This is a migrated thread and some comments may be shown as answers.

Mocking WinRT Types

1 Answer 22 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 26 May 2014, 08:22 AM
I'm currently evaluating JustMock for a Windows Store App that I'm developing.

I've tried this code:

            var mock = Mock.Create<ConnectionProfile>(Constructor.NotMocked);

            Assert.AreEqual(NetworkConnectivityLevel.ConstrainedInternetAccess, mock.GetNetworkConnectivityLevel());

And it fails with the following exception:

Result Message: Test method JustMockWinRtTypes.UnitTest1.MockTest threw exception: 
Telerik.JustMock.MockException: Failed to create instance of type 'Windows.Networking.Connectivity.ConnectionProfile'
Result StackTrace:
at Telerik.JustMock.Core.MocksRepository.CreateExternalMockMixin(Type mockObjectType, Object mockObject, IEnumerable`1 mixins, IEnumerable`1 supplementaryBehaviors, IEnumerable`1 fallbackBehaviors)
   at Telerik.JustMock.Core.MocksRepository.Create(Type type, MockCreationSettings settings)
   at Telerik.JustMock.MockBuilder.Create(MocksRepository repository, Type type, Object[] constructorArgs, Nullable`1 behavior, Type[] additionalMockedInterfaces, Nullable`1 mockConstructorCall, IEnumerable`1 additionalProxyTypeAttributes, List`1 supplementaryBehaviors, List`1 fallbackBehaviors, List`1 mixins, Expression`1 interceptorFilter)
   at Telerik.JustMock.Mock.<>c__DisplayClass81`1.<Create>b__80()
   at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
   at Telerik.JustMock.Mock.Create[T](Constructor constructor)
   at JustMockWinRtTypes.UnitTest1.MockTest() in c:\Source Code\Spikes\JustMockWinRtTypes\JustMockWinRtTypes\UnitTest1.cs:line 22

Can you tell me what I need to do to make this work?

Thanks

Simon



1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 29 May 2014, 09:41 AM
Hi Simon,

Thank you for reporting this.

I managed to reproduce it on my side and further investigations lead to the fact that ConnectionProfile is actually a COM class. If you inspect it, you should notice that it comes from a .winmd file. Unfortunately, even as JustMock is fully integrated inside Win RT it still cannot mock COM types. So, this scenario is not supported by us, at this stage.

Nevertheless, I will be happy to assist you with the evaluation further. I might be able to do so, if you share why do you need to mock exactly this class. Perhaps, me and my colleagues could think of a better approach that will work for your scenario.

I hope this helps.

Regards,
Kaloyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Simon
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or