public void VmShouldSaveAndRestoreStateHasChangesFalse() { var productModels = new List <ProductModel> { new ProductModel { Id = Guid.NewGuid(), Name = "Test" }, new ProductModel { Id = Guid.NewGuid(), Name = "Test" }, }; InitializeProductRepository(productModels); var viewModel = GetViewModel <ProductWorkspaceViewModel>(); Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(productModels)); Assert.IsFalse(viewModel.HasChanges); RepositoryMock.Verify(repository => repository.GetProductsAsync(It.IsAny <CancellationToken>()), Times.Once); var state = new DataContext(); viewModel.SaveState(state); state = UpdateState(state); RepositoryMock.ResetCalls(); viewModel = GetViewModel <ProductWorkspaceViewModel>(); viewModel.LoadState(state); Assert.IsFalse(viewModel.HasChanges); RepositoryMock.Verify(repository => repository.GetProductsAsync(It.IsAny <CancellationToken>()), Times.Once); Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(productModels)); }
public void VmShouldSaveAndRestoreStateHasChangesFalse() { var models = new List <OrderModel> { new OrderModel() }; InitializeRepository(models); var viewModel = GetViewModel <OrderWorkspaceViewModel>(); Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(models)); Assert.IsFalse(viewModel.HasChanges); RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once); var state = new DataContext(); viewModel.SaveState(state); state = UpdateState(state); RepositoryMock.ResetCalls(); viewModel = GetViewModel <OrderWorkspaceViewModel>(); viewModel.LoadState(state); Assert.IsFalse(viewModel.HasChanges); RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once); Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(models)); }
public void VmShouldSaveAndRestoreStateHasChangesTrue() { var models = new List <OrderModel> { new OrderModel() }; InitializeRepository(models); var viewModel = GetViewModel <OrderWorkspaceViewModel>(); Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(models)); RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once); RepositoryMock .Setup(repository => repository.GetProductsByOrderAsync(models[0].Id, It.IsAny <CancellationToken>())) .Returns(Task.FromResult <IList <OrderProductModel> >(Empty.Array <OrderProductModel>())); MessagePresenterMock .Setup( box => box.ShowAsync(It.IsAny <string>(), It.IsAny <string>(), MessageButton.YesNo, MessageImage.Question, It.IsAny <MessageResult>(), It.IsAny <IDataContext>())) .Returns(Task.FromResult(MessageResult.Yes)); viewModel.GridViewModel.SelectedItem = models[0]; viewModel.RemoveOrderCommand.Execute(null); Assert.IsTrue(viewModel.HasChanges); Assert.AreEqual(viewModel.GridViewModel.OriginalItemsSource.Count, 0); var state = new DataContext(); viewModel.SaveState(state); state = UpdateState(state); RepositoryMock.ResetCalls(); viewModel = GetViewModel <OrderWorkspaceViewModel>(); viewModel.LoadState(state); Assert.IsTrue(viewModel.HasChanges); RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once); Assert.AreEqual(viewModel.GridViewModel.OriginalItemsSource.Count, 0); }