This question is locked. New answers and comments are not allowed.
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:
The EntriesViewModel.Entries property is the VirtualQueryableCollectionView.
I hope that gives enough information about what I am trying to achieve.
cheers
Remco
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);
}
I hope that gives enough information about what I am trying to achieve.
cheers
Remco