IList<string> attrNames = new List<string>();
attrNames.Add("foo");
using (RecordExpectations recorder = new RecordExpectations())
{
obj.RemoveAttributes(attrNames);
recorder.CheckArguments(attrNames);
}
a little later in the unit test we call a method that then calls obj.RemoveAttributes (the method under test). When that happens obj.RemoveAttributes gets called with a string[] (which implements IList<string> via the framework).
obj.RemoveAttributes(new string[] { "foo" });
The failure is:
TypeMock Verification: Call to MyObject.RemoveAttributes() Parameter: 1 array index [0]
expected: [System.Collections.Generic.List`1[System.String]]
but was: <"foo">
I don't believe that this should happen. At a minimum this is unexpected. Here's my reasoning. The actual call to obj.RemoveAttributes(IList<string> attrNames) is well inside of a stack frame and the fact that the caller currently builds the argument as a string[] is an implementation detail that the test/tester shouldn't need to care about. Working with List<T> in the unit test is convenient and correct for the test/tester. IOW, they shouldn't need to know the implementation detail and have to pass in a string[].
string[] attrNames = new string[] { "foo" };
using (RecordExpectations recorder = new RecordExpectations())
{
obj.RemoveAttributes(attrNames);
recorder.CheckArguments(attrNames);
}
This code works just fine but it isn't obvious or convenient.
Thanks,
Darin