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:
                        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]);
        }
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)
...