Click here to Skip to main content
15,885,869 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 95.9K   85   118  
With this article, I am evolving a domain problem towards the best possible solution.
using NMock2;

using NUnit.Framework;

namespace BusinessRules.Evolution_Four.Tests
{
    [TestFixture]
    public class IncomeTaxEngineCreationFixture
    {
        private Mockery mocks = null;
        private ICurrentCultureInfo currentCulture = null;

        /// <summary>
        /// The Setup method is called before each test method is called. 
        /// </summary>
        [SetUp]
        public void Setup()
        {
            mocks = new Mockery();
            currentCulture = mocks.NewMock<ICurrentCultureInfo>();
        }

        [Test]
        public void ShouldReturnNewZealandIncomeTaxEngine()
        {
            // Setup expectations for our mock.
            Expect.Once.On(currentCulture).GetProperty("CurrentCultureName").Will(Return.Value("en-NZ"));

            // Execute the behavior
            IIncomeTaxEngine taxEngine = IncomeTaxEngine.CreateInstance(currentCulture);

            // Validate the results is as expected
            Assert.IsNotNull(taxEngine);
            Assert.IsInstanceOfType(typeof (NewZealandIncomeTaxEngine), taxEngine);
        }

        [Test]
        public void ShouldReturnAustralianIncomeTaxEngine()
        {
            // Setup expectations for our mock.
            Expect.Once.On(currentCulture).GetProperty("CurrentCultureName").Will(Return.Value("en-AU"));

            // Execute the behavior
            IIncomeTaxEngine taxEngine = IncomeTaxEngine.CreateInstance(currentCulture);

            // Validate the results is as expected
            Assert.IsNotNull(taxEngine);
            Assert.IsInstanceOfType(typeof (AustralianIncomeTaxEngine), taxEngine);
        }

        [Test]
        public void ShouldReturnUsaTaxIncomeTaxEngine()
        {
            // Setup expectations for our mock.
            Expect.Once.On(currentCulture).GetProperty("CurrentCultureName").Will(Return.Value("en-US"));

            // Execute the behavior
            IIncomeTaxEngine taxEngine = IncomeTaxEngine.CreateInstance(currentCulture);

            // Validate the results is as expected
            Assert.IsNotNull(taxEngine);
            Assert.IsInstanceOfType(typeof (UsaIncomeTaxEngine), taxEngine);
        }

        [Test]
        public void ShouldReturnNullIncomeTaxEngine()
        {
            // Setup expectations for our mock.
            Expect.Once.On(currentCulture).GetProperty("CurrentCultureName").Will(Return.Value("en-ZA"));

            // Execute the behavior
            IIncomeTaxEngine taxEngine = IncomeTaxEngine.CreateInstance(currentCulture);

            // Validate the results is as expected
            Assert.IsNotNull(taxEngine);
            Assert.IsInstanceOfType(typeof (NullIncomeTaxEngine), taxEngine);
        }

        /// <summary>
        /// The Teardown method is called after each test method is called. 
        /// So we validate all the expectations have been met.
        /// </summary>
        [TearDown]
        public void Teardown()
        {
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
    }
}

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