chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
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:
                case AssemblyInfo.CPPExtension:
            return default(AssemblyInfoWrapperBase);

Test Code
        [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>() };

            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);
                //AssemblyInfoWrapperBase vb = new AssemblyInfoWrapperManaged(items[1].ItemSpec);
                //AssemblyInfoWrapperBase jsl = new AssemblyInfoWrapperManaged(items[2].ItemSpec);
                //AssemblyInfoWrapperBase cpp = new AssemblyInfoWrapperManaged(items[3].ItemSpec);

asked by tbassett (1.8k points)

2 Answers

0 votes
Hi Tim,

You are right and this should fail.
and indeed I tried recreating this on our side and it fails as expected.

Is there a chance that ou can wrap this small example into a solution and sent it to us?
answered by lior (13.2k points)
0 votes
Let me wrap it up tomorrow nite for you.
answered by tbassett (1.8k points)