I've got the following test:
[TestMethod] public void PayrollViewModel_CallConstructor_DisplayNameSet() { // Arrange var context = Mock.Create<PersonnelDomainContext>(); var session = Mock.Create<ISession>(); var eventAgg = Mock.Create<IEventAggregator>(); var viewModel = new PayrollViewModel(context, session, eventAgg); // Act viewModel.GetPersonnel(); // Assert Assert.AreEqual("Personnel List", viewModel.DisplayName, "Display name is incorrect"); }
Basically, I'm trying to Mock the DomainContext that is generated by RIA Services. I'd like all the service calls to the services on the server side to be mocked so they are not run/called.
I'm getting the following error:
TestMethod: PayrollViewModel_CallConstructor_DisplayNameSet
TestClass: PayrollViewModelTests
Result: Failed
Exception:
Could not create a mock from the specified target.
at Telerik.JustMock.MockManager.CreateInstance(Type target, Container container, Boolean profilerEnabled)
at Telerik.JustMock.MockManager.SetupMock(Type target, Behavior behavior, Boolean static)
at Telerik.JustMock.MockManager.CreateInstance()
at Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
at Telerik.JustMock.Mock.Create(Type target, Object[] args)
at Telerik.JustMock.Mock.Create[T]()
at PayrollPrototype.Client.Personnel.Tests.PayrollViewModelTests.PayrollViewModel_CallConstructor_DisplayNameSet()
Failed
I suspect it is because the DomainContext is sealed. So how do I mock it, I'm supposed to be able to mock just about anything with justmock. (pardon the pun). I've been reading about mocking for some time but am still weak in the implementation. Need more practice. I keep seeming to hit errors when I try to mock anything.
thanks,
Stephen