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 am currently evaluating TypeMock and performing a simple test to check if it suitible for my unit testing needs.

The thing that makes type mock appealing is that you do not have to compromise your design, being force to implement IoC patterns when you don't want/need to. Anyway that's another debate. :wink:

I have a legacy component that I reference in my .NET project. This creates a runtime callable wrapper around the COM component.

When I try to mock this object's RWC it don't seem to work.


        [Test]
        public void Test()
        {
            Mock deviceMock = MockManager.Mock(typeof(MyLegacyClass));
            deviceMock.ExpectCall("MyLegacyMethod");
            unit = new Unit();
            unit.Do();

            MockManager.Verify();
        }


public class Unit
    {
        private MyLegacyClass legacyObject;

        public Unit()
        {
            this.legacyObject = new MyLegacyClass ();
        }

        public void Do()
        {
            this.legacyObject.MyLegacyMethod();
           
        }
    }


This is the message I get

TypeMock.VerifyException :
TypeMock Verification: Expected a new instance of MyLegacyNamespace.MyLegacyClass (try using MockAll)

Any help on whether this is possible in TypeMock or if there is anything wrong with my code is much appreciated.
asked by Leroy1883 (1.1k points)

3 Answers

0 votes
This should work.

:idea: Try looking at the tracer tool. it should give more information on why this doesnt work.
answered by lior (13.2k points)
0 votes
I am now able to get my test to run, but not repeatability.

Sometimes, it passes, sometimes it fails. Not sure why.
answered by Leroy1883 (1.1k points)
0 votes
Hi
Lets take it offline
I'll send you my mail address with instructions how to get more info
about what's going on in the test.
answered by ohad (35.4k points)
...