Click here to Skip to main content
15,897,273 members
Articles / Programming Languages / C#

Who cares about Domain Rules?

Rate me:
Please Sign up or sign in to vote.
4.96/5 (88 votes)
20 Nov 2006MIT12 min read 96.6K   85   118  
With this article, I am evolving a domain problem towards the best possible solution.
using NUnit.Framework;

namespace BusinessRules.Evolution_Five.Tests
{
    [TestFixture]
    public class TaxBandFixture
    {
        private TaxBand m_band;

        /// <summary>
        /// The Setup method is called before each test method is called. 
        /// So we recreate a new TaxBand object before each test.
        /// </summary>
        [SetUp]
        public void Setup()
        {
            m_band = new TaxBand(0.0, 20000.00, 0.1);
        }

        /// <summary>
        /// Validates the tax rate is correct after creating a new tax band.
        /// </summary>
        [Test]
        public void ValidateTaxRateCorrectAfterCreatingNewTaxBand()
        {
            double expectedTaxRate = 0.1;

            Assert.AreEqual(expectedTaxRate, m_band.TaxRate);
        }

        /// <summary>
        /// Validates the calculate tax portion method behaves as expected.
        /// </summary>
        [Test]
        public void ValidateCalculateTaxPortion()
        {
            Assert.AreEqual(0.0, m_band.CalculateTaxPortion(0.0));
            Assert.AreEqual(1000.0, m_band.CalculateTaxPortion(10000.0));
            Assert.AreEqual(500.0, m_band.CalculateTaxPortion(5000.0));
            Assert.AreEqual(2000.0, m_band.CalculateTaxPortion(20000.0));
            Assert.AreEqual(2000.0, m_band.CalculateTaxPortion(20001.0));
            Assert.AreEqual(1254.6, m_band.CalculateTaxPortion(12546.0), 2.0);
            Assert.AreEqual(2000.0, m_band.CalculateTaxPortion(12021541.0));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Web Developer
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions