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've created a couple of unit tests that require interface mocking. When running those in VS2008 with Typemock 6.0 they run perfectly. In VS2010 (after the automatic conversion of the solution) I get the following error
when executing this line:

RecorderManager.CreateMockedObject<IEquityRepository>();


System.ArgumentException: Cannot set parent to an interface.

StackTrace:
at System.Reflection.Emit.TypeBuilder.SetParent(Type parent)
at System.Reflection.Emit.GenericTypeParameterBuilder.SetBaseTypeConstraint(Type baseTypeConstraint)
at ec.a(GenericTypeParameterBuilder A_0, Type A_1, MethodInfo A_2)
at ec.a(MethodInfo A_0, Type A_1, GenericTypeParameterBuilder A_2)
at ec.a(MethodInfo A_0, Type[] A_1, String[] A_2, MethodBuilder A_3)
at ec.a(TypeBuilder A_0, MethodInfo A_1, MethodAttributes A_2)
at ec.b(TypeBuilder A_0, MethodInfo A_1, MethodAttributes A_2)
at ec.a(TypeBuilder A_0, MethodInfo A_1)
at ec.a(Type A_0, Object[] A_1)
at TypeMock.MockManager.a(Type A_0, Constructor A_1, Object[] A_2, Boolean A_3)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.RecorderManager.CreateMockedObject(Type typeToMock, Constructor mockConstructor)
at TypeMock.RecorderManager.CreateMockedObject(Type typeToMock)
at TypeMock.RecorderManager.CreateMockedObject[TMockedType]()
at Tests.QuoteWatcher.Shared.utQWRepository.QWRepository_Verify() in C:UsersndreasDevelopedQuote-WatcherTestingTests.QuoteWatcher.SharedutQWRepository.cs:line 115


Again, the only thing changed was the conversion to VS2010 which moves all MS Tests to .NET framework 4.0.

Any ideas?

Thanks,
Andreas
asked by andreasn (720 points)

6 Answers

0 votes
Hi Andreas,

Can you please post here the test code?
Also please let me know against what .net version your tests are running?
answered by ohad (35.4k points)
0 votes
Alright.

The App is build for .NET 3.5. However, when you convert the solution to VS2010 all test projects get converted so they target .NET 4.0 (otherwise MS Test doesn't work. So the tests effectively run under .NET 4.0

The test fails on the following line:
_eqdb = RecorderManager.CreateMockedObject<IEquityRepository>();

BTW - I'm obviously using the MS Unity framework, but there is a small tweak in it, so it's not 100% the original, but it's also signed with a different key (so it has a different strong name).

The full test code:

[TestMethod]
public void QWRepository_Verify()
{
MockManager.Init();

IEquityRepository _eqdb = null;
IExchangeRepository _exdb = null;
IQuoteStorageRepository _qsdb = null;
ICurrencyRepository _fxdb = null;
IUnityContainer _pm = null;

try
{
_eqdb = QWRepository.sEquityDB;
Assert.Fail();
}
catch (InvalidOperationException)
{
}

try
{
_exdb = QWRepository.sExchangeDB;
Assert.Fail();
}
catch (InvalidOperationException)
{
}

try
{
_qsdb = QWRepository.sQuotesRepository;
Assert.Fail();
}
catch (InvalidOperationException)
{
}

try
{
_pm = QWRepository.sPluginManager;
Assert.Fail();
}
catch (InvalidOperationException)
{
}

_eqdb = RecorderManager.CreateMockedObject<IEquityRepository>();
_exdb = RecorderManager.CreateMockedObject<IExchangeRepository>();
_qsdb = RecorderManager.CreateMockedObject<IQuoteStorageRepository>();
_fxdb = RecorderManager.CreateMockedObject<ICurrencyRepository>();

_pm = new UnityContainer();
QWRepository.Initialize(_pm);
Assert.IsNotNull(QWRepository.sPluginManager);

_pm.RegisterInstance<IEquityRepository>(_eqdb);
_pm.RegisterInstance<IExchangeRepository>(_exdb);
_pm.RegisterInstance<IQuoteStorageRepository>(_qsdb);
_pm.RegisterInstance<ICurrencyRepository>(_fxdb);

_eqdb = QWRepository.sEquityDB;
_exdb = QWRepository.sExchangeDB;
_qsdb = QWRepository.sQuotesRepository;
_fxdb = QWRepository.sCurrencyRepository;

Assert.IsNotNull(_eqdb);
Assert.IsNotNull(_exdb);
Assert.IsNotNull(_qsdb);
Assert.IsNotNull(_fxdb);

QWRepository _qwrep = new QWRepository();

_eqdb = _qwrep.EquityDB;
_exdb = _qwrep.ExchangeDB;
_qsdb = _qwrep.QuotesRepository;
_fxdb = _qwrep.CurrencyRepository;

Assert.IsNotNull(_eqdb);
Assert.IsNotNull(_exdb);
Assert.IsNotNull(_qsdb);
Assert.IsNotNull(_fxdb);
Assert.IsNotNull(_qwrep.PluginManager);

MockManager.Verify();
}
answered by andreasn (720 points)
0 votes
Hi Andreas,

Thanks for the info, we'll check it out.
BTW any reason why you're not using the newer AAA API for this?
answered by ohad (35.4k points)
0 votes
No - not really - when I started converting to VS2010. I started the most basic solution which is kind of the basis module for the rest for the app(s). Because of that it's still using the old syntax.

I also tried the Isolate.Fake method, but same error.

Regards,
Andreas
answered by andreasn (720 points)
0 votes
Hi there,

were you able to reproduce the error or do you need more guidance?

Thanks,
Andreas
answered by andreasn (720 points)
0 votes
Hi Adreas,

I'd like to further investigate this issue - let's take it offline.
answered by dhelper (11.9k points)
...