I have a unit test invoking a constructor, passing in a "null" on purpose to test the handling of the null.
I expect the method invoked to throw an ArgumentNullException, but when I step through the code, I see the parameter has actually been initialised.
This has me stumped, although my gut says it has something to do with the DI container (Castle Windsor).
Can anyone shed any light on this?
My unit test, a null is passed together with an instantiated delegate:
[Test]
public void ConstructorThrowsAnExceptionWhenImplementationCollectionIsNull()
{
//assert
Assert.Throws<ArgumentException>(() => new CacheImplementationSelector(null, _stubCacheImplementationSelectorDelegate));
}
The invoked method:
public CacheImplementationSelector(ICollection<ICacheImplementation> implementations, CacheImplementationSelectorDelegate selectorDelegate)
{
implementations.IsNotNullArgCheck("implementations");
...
Hovering my mouse over the implementations parameter with the code stopped on a breakpoint in the CacheImplementationSelectorMethod, visual studio tells me the parameter "implementations" has a Count of 1 and [0] is null.
I am using ReSharper to run the NUnit test.
For completeness the TestFixtureSetup and SetUp are as follows:
[TestFixtureSetUp]
public void FixtureSetUp()
{
_mocks = new MockRepository();
}
[SetUp]
public void Setup()
{
_listOfImplementations = new List<ICacheImplementation>() { _stubICacheImplementation };
_stubCacheImplementationSelectorDelegate = MockRepository.GenerateStub<CacheImplementationSelectorDelegate>();
_stubICacheImplementation = MockRepository.GenerateStub<ICacheImplementation>();
_stubKeyCreator = MockRepository.GenerateStub<ICacheKeyCreator>();
_stubStrategy = MockRepository.GenerateStub<ICachingStrategy>();
_stubEncoder = MockRepository.GenerateStub<ICacheItemEncoder>();
_c = new CacheImplementationSelector(_listOfImplementations, _stubCacheImplementationSelectorDelegate);
_testObject = new object();
_yesterday = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
_tomorrow = DateTime.Now.Add(new TimeSpan(1, 0, 0, 0));
_testString = "test";
_tooLongKey = "a".Repeat(Cache.MaxKeyLength+1);
_tooLongFriendlyName = "a".Repeat(Cache.MaxFriendlyNameLength + 1);
}