I have a test that I wrote to test that a class factory creates the correct object. I am attempting to use VerifyMocks to ensure the correct behavior.
Using
TDD, I was validating that the test fails, but it doesn't, it passes. Should it not fail because I have not instantiated a AssemblyInfoWrapperManaged?
Production Code
private AssemblyInfoWrapperBase GetAssemblyInfoWrapper(ITaskItem item)
{
switch (Path.GetExtension(item.ItemSpec).ToLower())
{
case AssemblyInfo.CSharpExtension:
case AssemblyInfo.VBExtension:
case AssemblyInfo.JSharpExtension:
break;
case AssemblyInfo.CPPExtension:
break;
default:
break;
}
return default(AssemblyInfoWrapperBase);
}
Test Code
[TestMethod]
[VerifyMocks]
[Description("Proves GetAssemblyInfoWrapper creates the correct type of AssemblyInfoWrapperBase." )]
public void GetAssemblyInfoWrapper()
{
AssemblyInfo target = new AssemblyInfo();
AssemblyInfo_Accessor a = AssemblyInfo_Accessor.AttachShadow(target);
ITaskItem[] items = new ITaskItem[] {
RecorderManager.CreateMockedObject<ITaskItem>()
, RecorderManager.CreateMockedObject<ITaskItem>()
, RecorderManager.CreateMockedObject<ITaskItem>()
, RecorderManager.CreateMockedObject<ITaskItem>() };
using(RecordExpectations r = new RecordExpectations())
{
r.ExpectAndReturn(items[0].ItemSpec, "something.cs").RepeatAlways();
r.ExpectAndReturn(items[1].ItemSpec, "something.vb").RepeatAlways();
r.ExpectAndReturn(items[2].ItemSpec, "something.jsl").RepeatAlways();
r.ExpectAndReturn(items[3].ItemSpec, "something.rc").RepeatAlways();
/// this should not pass the VerifyMocks?????
AssemblyInfoWrapperBase cs = new AssemblyInfoWrapperManaged(items[0].ItemSpec);
r.CheckArguments(items[0]);
//AssemblyInfoWrapperBase vb = new AssemblyInfoWrapperManaged(items[1].ItemSpec);
//r.CheckArguments(items[1]);
//AssemblyInfoWrapperBase jsl = new AssemblyInfoWrapperManaged(items[2].ItemSpec);
//r.CheckArguments(items[2]);
//AssemblyInfoWrapperBase cpp = new AssemblyInfoWrapperManaged(items[3].ItemSpec);
//r.CheckArguments(items[3]);
}
a.GetAssemblyInfoWrapper(items[0]);
a.GetAssemblyInfoWrapper(items[1]);
a.GetAssemblyInfoWrapper(items[2]);
a.GetAssemblyInfoWrapper(items[3]);
}