How to arrange IEventAggregator

2 posts, 0 answers
  1. Rayne
    Rayne avatar
    261 posts
    Member since:
    Sep 2010

    Posted 28 Nov 2012 Link to this post

    Here is a snippet of my test code:

    private PendingListViewModel _vm;
            public void Setup()
                var view = Mock.Create<IPendingListView>();
                var repository = Mock.Create<ISubmissionRepository>();
                repository.Arrange(x => x.GetPendingSubmissions()).Returns(GetSubmissionSet());
                var subscribedEvent = Mock.Create<RefreshPendingSubmissions>();
                subscribedEvent.Arrange(x => x.Subscribe(Arg.IsAny<Action<string>>())).DoNothing();
                var events = Mock.Create<IEventAggregator>();
                events.Arrange(x => x.GetEvent<RefreshPendingSubmissions>()).Returns(subscribedEvent);
                _vm = new PendingListViewModel(view, repository, events);
            public void ExecuteSortByCountyCommand_CollectionShouldContainOneSortDescriptor()
                Assert.IsTrue(_vm.SubmissionsCollection.SortDescriptions.Count == 1);

    When I do this I get an exception:

    System.IO.FileLoadException: System.IO.FileLoadException: Could not load file or assembly 'Telerik.JustMock_fe91bf8a4e2f4132a3849f92ab689d67, Version=2012.3.1025.4, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044).
        at Microsoft.Practices.Prism.Events.CompositePresentationEvent`1.Subscribe(Action`1 action)
       at Complaints.Modules.Web.ViewModels.PendingListViewModel..ctor(IPendingListView view, ISubmissionRepository subRepository, IEventAggregator events) in PendingListViewModel.cs: line 73

    If I remove the code that creates and arranges subscribedEvent and leave the mocked event aggregator alone (just create, no arranging), then the same line of code returns a NullReferenceException.

    The problem line of code is :
    _events.GetEvent<RefreshPendingSubmissions>().Subscribe(a => OnRefresh());

    in the constructor of my Class under test.

    I had the same issues when I used a Mocking Container, so I switched to creating all the mocks individually, but it's still not working.

    What am I doing wrong?
  2. Ricky
    Ricky avatar
    467 posts

    Posted 30 Nov 2012 Link to this post

    Hi Rayne,

    Thanks again for contacting us.

    We recently fixed this issue and therefore would ask you to open a support ticket alongside a sample project where we will go through issue and send you an internal build if needed.

    Kind Regards
    the Telerik team

    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Back to Top