Tim Van Wassenhove

Passionate geek, interested in Technology. Proud father of two

23 Sep 2008

Refactoring ApplicationEnvironment

Yesterday i blogged about an ApplicationEnvironment which had a dependency on the application configuration file. With my ConfigurationFileSession i was able to test the implementation despite that dependency. Today i modified the design a little so that i do not require the ConfigurationFileSession hack anymore.

First i added an internal constructor as following

internal protected ApplicationEnvironment(DateTime instanceEpoch, DateTime applicationEpoch)
{
	this.instanceEpoch = instanceEpoch;
	this.applicationEpoch = applicationEpoch;
}

Then i made the internals visible to the test project

[assembly: InternalsVisibleTo("Be.Timvw.Framework.Domain.Tests")]

And finally i added a base class that takes care of the initialization and clean up as following

[TestInitialize]
public void TestInitialize()
{
	this.original = ApplicationEnvironment.Instance;
	ApplicationEnvironment.Instance = new ApplicationEnvironment(DateTime.UtcNow, new DateTime(1998, 01, 01));
}

[TestCleanup]
public void TestCleanUp()
{
	ApplicationEnvironment.Instance = this.original;
}