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
Try running the unit test below and you get this exception when the second mock object is created:

System.InvalidCastException: Unable to cast object of type 'TypeMock.MockObject`1[One.IOperations]' to type 'TypeMock.MockObject`1[Two.IOperations]'.


using NUnit.Framework;
using TypeMock;

namespace UnitTests
{
[TestFixture]
public class NUnitTests
{
[Test]
public void Test1()
{
MockObject<One.IOperations> mockObject1 = MockManager.MockObject<One.IOperations>();

MockObject<Two.IOperations> mockObject2 = MockManager.MockObject<Two.IOperations>();

}
}
}

namespace One
{
public interface IOperations
{
}
}

namespace Two
{
public interface IOperations
{
}
}
asked by jakecollins (640 points)

3 Answers

0 votes
Hi Jake,

It seems like you've indeed found a bug :(. We'll work on resolving it for an upcoming version and let you know when it's done.

Doron
Typemock Support Team
answered by doron (17.2k points)
0 votes
Thanks for quick reply. Can you think of any workaround we could do in the mean time? Is there any other way to mock the interfaces?
answered by jakecollins (640 points)
0 votes
Hi Jake,

As a workaround I suggest using the Natural Mocks syntax:

            One.IOperations mock1 = RecorderManager.CreateMockedObject<One.IOperations>();
            Two.IOperations mock2 = RecorderManager.CreateMockedObject<Two.IOperations>();

            using (RecordExpectations rec = new RecordExpectations())
            {

                mock1.MethodOne();
                mock2.MethodTwo();
            }
            mock1.MethodOne();
            mock2.MethodTwo();


Please let me know if this works for you.

Doron
Typemock Support Team
answered by doron (17.2k points)
...