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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I am doing some testing of a DAL and so am testing classes which effectively take in a load of data and then passing it out again.

At present I am doing this in roughly the style shown below.

       [TestMethod]
        public void Copying_Test()
        {                   
           VWE_STB_BOOKMARK entity = new VWE_STB_BOOKMARK();
           entity.STB_ID = int.MaxValue;
           Nullable<int> temp_STB_ID = entity.STB_ID;

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                VWE_STB_BOOKMARK newBookmark = new VWE_STB_BOOKMARK();
                recorder.ExpectAndReturn(newBookmark.STB_ID, temp_STB_ID);
            }
            try
            {
                VWE_STB_BOOKMARK target = new VWE_STB_BOOKMARK();
                Nullable<int> result = target.STB_ID;                
                Assert.AreEqual(temp_STB_ID,result);
                MockManager.Verify();
            }
            finally
            {                    
                MockManager.ClearAll();
            }
        }


I was wandering if there is a may to use the properties of an entity as the results from calls in natural typemocks. This would be something like the code shown below.

        [TestMethod]
        public void Copying_Test2()
        {                   
           VWE_STB_BOOKMARK entity = new VWE_STB_BOOKMARK();
           entity.STB_ID = int.MaxValue;
           Nullable<int> temp_STB_ID = entity.STB_ID;

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                VWE_STB_BOOKMARK newBookmark = new VWE_STB_BOOKMARK();
                recorder.ExpectAndReturn(newBookmark.STB_ID, [u]entity.STB_ID[/u]);
            }
            try
            {
                VWE_STB_BOOKMARK target = new VWE_STB_BOOKMARK();
                Nullable<int> result = target.STB_ID;                
                Assert.AreEqual(temp_STB_ID,result);
                MockManager.Verify();
            }
            finally
            {                    
                MockManager.ClearAll();
            }
        }


This wont work at present. Presumably as TypeMock is mocking the call to entity.STB_ID within the recording section.

Thanks,
asked by Cnash (2.3k points)

2 Answers

0 votes
This is a good feature request. We have actually already implemented it and it will be part of our next release. The beta will be out soon.

I have seen that you are wrapping your test with a try/catch. a nicer way would be to put the MockManager.ClearAll() in the [TearDown] method.
It will keep your tests tidy and make sure that your mocks don't overflow into other test
answered by scott (32k points)
0 votes
Hi
This feature is available in 4.0.0 release
answered by ohad (35.5k points)
...