Mocking WinRT Types

2 posts, 0 answers
  1. Simon
    Simon avatar
    1 posts
    Member since:
    Nov 2012

    Posted 26 May 2014 Link to this post

    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



  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 29 May 2014 Link to this post

    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.

     
  3. DevCraft R3 2016 release webinar banner
Back to Top