Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > GridView > How to unit test viewmodel for correct loading of VirtualQueryableCollectionView

Not answered How to unit test viewmodel for correct loading of VirtualQueryableCollectionView

Feed from this thread
  • Remco avatar

    Posted on Feb 7, 2012 (permalink)

    Hello,

    I am trying to write a unit test for my viewmodel correctly loading data into a VirtualQueryableCollectionView. The viewmodel handles the ItemsLoading event of the VirtualQueryableCollectionView to load data into the VirtualQueryableCollectionView. In my unit test I basically need to to the same as a RadGridView would do to trigger the ItemsLoading event. But I don't know which properties to set or which methods to invoke on the VirtualQueryableCollectionView to make it trigger the ItemsLoading event. Note that I am not trying to unit test the VirtualQueryableCollectionView for correctly triggering the ItemsLoading event. Telerik will have done that. I am trying to unit test my viewmodel for correctly loading data into the VirtualQueryableCollectionView. For that I need to trigger the ItemsLoading event. But I cannot get it to trigger. Setting a breakpoint in my viewmodel when the VirtualQueryableCollectionView is databound to the RadGridView indicates it is the GetItemAt method that triggers the ItemsLoading event, but me calling that method from my unit test does not trigger the ItemsLoading event. How can I make this work?

    This is what my unit test looks like:
    [TestMethod]
    public void GivenLogbookWhenViewingEntriesThenShouldLoadEntries()
    {
        var expectedEntry = new EntryPresentationModel { Id = 1, Timestamp = DateTime.UtcNow };
        var expectedEntries = new List<EntryPresentationModel> { expectedEntry };
        var expectedEntriesResult = new ServiceLoadResult<EntryPresentationModel>(expectedEntries);
     
        var contextMock = new Mock<ILogbookViewerContext>();
        contextMock.Setup(c => c.LoadEntriesByLogbookNameAsync(It.IsAny<string>(), It.IsAny<QueryBuilder<EntryPresentationModel>>(), It.IsAny<object>())).Returns(TaskEx.FromResult(expectedEntriesResult));
     
        var appServiceMock = new Mock<IAppService>();
        appServiceMock.Setup(a => a.LogbookName).Returns("LogbookName");
        appServiceMock.Setup(a => a.LoadSize).Returns(30);
        appServiceMock.Setup(a => a.RefreshInterval).Returns(TimeSpan.Zero);
     
        var exceptionManagerMock = new Mock<ExceptionManager>();
     
        EntriesViewModel.ContinuationOptions = TaskContinuationOptions.ExecuteSynchronously;
     
        var target = new EntriesViewModel(contextMock.Object, appServiceMock.Object, exceptionManagerMock.Object);
        target.Entries.SortDescriptors.Add(new SortDescriptor { Member = "Timestamp", SortDirection = ListSortDirection.Descending });
     
        var actualEntity = target.Entries.GetItemAt(0);
     
        Assert.AreSame(expectedEntry, actualEntity);
    }
    The EntriesViewModel.Entries property is the VirtualQueryableCollectionView.
    I hope that gives enough information about what I am trying to achieve.

    cheers

    Remco

    Reply

  • Vlad Vlad admin's avatar

    Posted on Feb 7, 2012 (permalink)

    Hello,

     Can you post more info how you've set up VirtualQueryableCollectionView in your case?

    Greetings,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Remco avatar

    Posted on Feb 7, 2012 (permalink)

    I was hoping I could attach the code as a zip file, but zip attachment is not allowed. So here is the EntriesViewModel:

    <deleted source code>

    And here is the ILogbookViewerContext interface:

    <deleted source code>

    Reply

  • Vlad Vlad admin's avatar

    Posted on Feb 7, 2012 (permalink)

    Hi,

     Unfortunately we are not sure why the event is not called in your case. Please open support ticket and send us small project demonstrating the problem. We will check it locally and we will provide you more info. 

    All the best,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > GridView > How to unit test viewmodel for correct loading of VirtualQueryableCollectionView
Related resources for "How to unit test viewmodel for correct loading of VirtualQueryableCollectionView"

Silverlight Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]