Initializer Collections

Even with a fluent interface, it can become laborious to retype the same few initializers every time you create a unit test. For that reason, initializers can be grouped into collections so that a baseline for every test can be composed of more discrete parts:

public class CalculatorIsReadyToRun : InitializerCollection
{
	protected override void Register()
	{
		GivenThat<CalculatorIsDefaultConstructed>()
			.And<SomeOtherInitialization>()
			.And<MoreInitialization>()
			.And<EvenMoreIntialization>()
			.And<ThankGodForInitializerCollections>();
        }
}
...
[TestClass]
public class AddingNumbersThatCauseOverflowShouldThrowOverflowException : UnitTest<Calculator, int>
{
        [TestMethod]
        public override void Run()
        {
                GivenThat<CalculatorIsReadyToRun>()
                        .And<TestSpecificInitializer>();

                When<AddingTwoNumbers>(int.MaxValue, 1);

                ThenThrow<OverflowException>();
        }
}

Last edited Aug 15, 2011 at 1:52 PM by garymcleanhall, version 1

Comments

No comments yet.