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

How to arrange IEventAggregator

1 Answer 14 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 28 Nov 2012, 05:23 PM
Here is a snippet of my test code:

private PendingListViewModel _vm;
 
        [TestInitialize]
        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);
        }
        [TestMethod]
        public void ExecuteSortByCountyCommand_CollectionShouldContainOneSortDescriptor()
        {
            _vm.SortCountyCommand.Execute("ASC");
            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?

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 30 Nov 2012, 09:04 PM
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
Ricky
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.
Tags
General Discussions
Asked by
Rayne
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or