This question is locked. New answers and comments are not allowed.
Hi All,
I was just wondering if someone could post some example code of how to Mock a QueryableCollectionView?
I have a unit test that creates a class (injects a couple of Mocked services into constructor) and in the constructor of the viewmodel (that i'm testing) it sets up a collection view. The QueryableCollectionView takes property on the mocked dataservice as input and throws an exception. Not sure what I'm doing wrong.
is how I do the mock, and then inside the constructor of the viewmodel is this;
Which throws null exception error when i run the unit test.
PayrunComments is not null so not sure whats up with that.
help appreciated,
thanks,
Stephen
I was just wondering if someone could post some example code of how to Mock a QueryableCollectionView?
I have a unit test that creates a class (injects a couple of Mocked services into constructor) and in the constructor of the viewmodel (that i'm testing) it sets up a collection view. The QueryableCollectionView takes property on the mocked dataservice as input and throws an exception. Not sure what I'm doing wrong.
var dataService = Mock.Create<IHoursEntryDataService>();
Mock.Arrange(() => dataService.PayrunComments).Returns(new EntitySet<PayrunCommentDto>());
is how I do the mock, and then inside the constructor of the viewmodel is this;
_commentsCollectionView = new QueryableCollectionView(_hoursEntryDataService.PayrunComments);
Which throws null exception error when i run the unit test.
PayrunComments is not null so not sure whats up with that.
help appreciated,
thanks,
Stephen
7 Answers, 1 is accepted
0
Hello Stephen,
Vlad
the Telerik team
Can you post the stack trace?
Regards,Vlad
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 2
answered on 09 Jun 2011, 09:24 AM
at System.ServiceModel.DomainServices.Client.EntitySet.GetEnumerator()
at System.ServiceModel.DomainServices.Client.EntitySet.System.Collections.IEnumerable.GetEnumerator()
at Telerik.Windows.Data.EnumerableExtensions.TryGetFirstElement(IEnumerable source, Object& firstElement)
at Telerik.Windows.Data.EnumerableExtensions.TryGetFirstElementType(IEnumerable source, Type& firstElementType)
at Telerik.Windows.Data.EnumerableExtensions.CastToFirstElementType(IEnumerable source)
at Telerik.Windows.Data.QueryableFactory.CreateQueryable(IEnumerable source)
at Telerik.Windows.Data.QueryableCollectionView.InitializeQueryableSourceCollection()
at Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection)
at PayrollSiteDataEntry.Client.ViewModels.HoursEntryViewModel.SetupCommentsCollectionView()
at PayrollSiteDataEntry.Client.ViewModels.HoursEntryViewModel..ctor(ISession session, IHoursEntryDataService hoursEntryDataService, INavigationService navigationService, IPopupActivator popupActivator)
at Client.UnitTests.HoursEntryViewModelTests.HoursEntryViewModel_Construction_IsNotNull()
Its a silverlight unit test. It gives me the above stack trace.
cheers,
Stephen
0
Hi,
Vlad
the Telerik team
According to the stack trace the exception is raised from WCF RIA services class - you may need to mock your service as well.
Best wishes,Vlad
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 2
answered on 09 Jun 2011, 09:37 AM
// Arrange
var dataService = Mock.Create<IHoursEntryDataService>();
var session = Mock.Create<ISession>();
var popupActivator = Mock.Create<IPopupActivator>();
var navigationService = Mock.Create<INavigationService>();
Mock.Arrange(() => dataService.PayrunComments).Returns(
new
EntitySet<PayrunCommentDto>());
// Act
var viewModel =
new
HoursEntryViewModel(session, dataService, navigationService, popupActivator);
Assert.IsNotNull(viewModel);
Thats my unit test. As you can see I've got a Dataservice (IHoursEntryDataService) which I'm mocking.
Is there perhaps something else on the dataservice that I need to Arrange?
I'm new at mocking and finding examples of mocking RIA Services has been difficult to find.
cheers,
Stephen
0
Hi Stephen,
Vlad
the Telerik team
You need to mock GetEnumerator() method as well.
Best wishes,Vlad
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 2
answered on 09 Jun 2011, 10:46 AM
Ah, I'm struggling with how to mock the GetEnumerator() method.
Would you be able to post a small example?
many thanks!
Would you be able to post a small example?
many thanks!
0
Hi Stephen,
In case you are mocking a collection or IQueryable implementation, you can use the ReturnsCollection from Telerik.JustMock.Helpers. Please take a look into the following example:
http://www.telerik.com/help/justmock/advanced-usage-mocking-linq-queries.html
Hope that solves your issue.
Kind Regards,
Ricky
the Telerik team
In case you are mocking a collection or IQueryable implementation, you can use the ReturnsCollection from Telerik.JustMock.Helpers. Please take a look into the following example:
http://www.telerik.com/help/justmock/advanced-usage-mocking-linq-queries.html
Hope that solves your issue.
Kind Regards,
Ricky
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items