So, I have this little piece of code
public class DataElephant
{
public static DataElephant Instance
{
get
{
DataElephant elephant = (DataElephant) HttpContext.Current.Application["Elephant"];
if (elephant != null)
{
return elephant;
}
else
{
elephant = new DataElephant();
HttpContext.Current.Application["Elephant"] = elephant;
return elephant;
}
}
}
}
The test code goes something like this:
[Test]
[VerifyMocks]
public void DataElephantInstanceNewTest()
{
MockObject<HttpContext> mockedContext = MockManager.MockObject<HttpContext>(Constructor.Mocked);
Mock httpContextMock = MockManager.Mock<HttpContext>(Constructor.Mocked);
httpContextMock.ExpectGetAlways("Current", mockedContext.MockedInstance);
MockObject<HttpApplicationState> mockedApplication = MockManager.MockObject<HttpApplicationState>(Constructor.Mocked);
mockedContext.ExpectGet("Application", mockedApplication.MockedInstance);
mockedApplication.ExpectGetIndex(null).Args("Elephant");
Mock elephantMock = MockManager.Mock<DataElephant>();
mockedApplication.ExpectSetIndexAlways().Args("Elephant", elephantMock.MockedInstance );
DataElephant elephant = DataElephant.Instance;
}
Expect that won't work, of course, since elephantMock.MockedInstance is null until the code is actually ran. If I could somehow mock the DataElephant constructor and return a mock object...