public void SelectedCategoryIndexProperty() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.SelectedCategoryIndex); Assert.Equal(-1, actual.SelectedCategoryIndex.Value); // Model -> ViewModel var category1 = new Category { Id = "category1" }; var category2 = new Category { Id = "category2" }; var categories = new[] { category1, category2 }; editExpense.NotifyPropertyChanged(m => m.Categories, categories); editExpense.NotifyPropertyChanged(m => m.SelectedCategory, category2); Assert.Equal(1, actual.SelectedCategoryIndex.Value); // ViewMode -> Model actual.SelectedCategoryIndex.Value = 0; editExpense.VerifySet(m => m.SelectedCategory = category1, Times.Once); // Destroy actual.Destroy(); editExpense.NotifyPropertyChanged(m => m.SelectedCategory, category1); Assert.NotEqual(2, actual.SelectedCategoryIndex.Value); }
public void DateProperty() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); editExpense.Setup(m => m.Date).Returns(DateTime.MinValue); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.Date); Assert.Equal(DateTime.MinValue, actual.Date.Value); // ViewMode -> Model actual.Date.Value = DateTime.MaxValue; editExpense.VerifySet(x => x.Date = DateTime.MaxValue, Times.Once); // Model -> ViewModel editExpense.NotifyPropertyChanged(m => m.Date, DateTime.MinValue); Assert.Equal(DateTime.MinValue, actual.Date.Value); // Destroy actual.Destroy(); editExpense.NotifyPropertyChanged(m => m.Date, DateTime.MaxValue); Assert.NotEqual(DateTime.MaxValue, actual.Date.Value); }
public void OnNavigatedTo() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); actual.OnNavigatedTo(null); }
public void OnNavigatingTo() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); actual.OnNavigatingTo(null); editExpense.Verify(m => m.InitializeAsync(), Times.Once); }
public void OnNavigatingToForUpdate() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); var navigationParameters = new NavigationParameters(); navigationParameters[AddExpensePageViewModel.ExpenseIdKey] = "expenseId"; actual.OnNavigatingTo(navigationParameters); editExpense.Verify(m => m.InitializeAsync("expenseId"), Times.Once); }
public void NavigateReceiptPageCommand() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.NavigateReceiptPageCommand); Assert.True(actual.NavigateReceiptPageCommand.CanExecute()); actual.NavigateReceiptPageCommand.Execute(null); navigationService.Verify(m => m.NavigateAsync("ReceiptPage", null, null, true), Times.Once); }
public void CancenCommand() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.CancelCommand); Assert.True(actual.CancelCommand.CanExecute()); actual.CancelCommand.Execute(); editExpense.Verify(m => m.SaveAsync(), Times.Never); navigationService.Verify(m => m.GoBackAsync(null, true, true), Times.Once); }
public void HasReceiptProperty() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.HasReceipt); Assert.False(actual.HasReceipt.Value); // Model -> ViewModel var media = new Mock <IMediaFile>(); editExpense.NotifyPropertyChanged(m => m.Receipt, media.Object); Assert.True(actual.HasReceipt.Value); // Destroy // ... }
public void NoteProperty() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.Note); Assert.Null(actual.Note.Value); // ViewMode -> Model actual.Note.Value = "SetValue"; editExpense.VerifySet(x => x.Note = "SetValue", Times.Once); // Model -> ViewModel editExpense.NotifyPropertyChanged(m => m.Note, "UpdateValue"); Assert.Equal("UpdateValue", actual.Note.Value); // Destroy actual.Destroy(); editExpense.NotifyPropertyChanged(m => m.Note, "Destroy"); Assert.NotEqual("Destroy", actual.Note.Value); }
public void AmountProperty() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.Amount); Assert.Equal(0, actual.Amount.Value); // ViewMode -> Model actual.Amount.Value = 1; editExpense.VerifySet(x => x.Amount = 1, Times.Once); // Model -> ViewModel editExpense.NotifyPropertyChanged(m => m.Amount, 2); Assert.Equal(2, actual.Amount.Value); // Destroy actual.Destroy(); editExpense.NotifyPropertyChanged(m => m.Amount, 3); Assert.NotEqual(3, actual.Amount.Value); }
public void Categories() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.Categories); Assert.NotNull(actual.Categories.Value); Assert.Equal(0, actual.Categories.Value.Count()); var categories = new [] { new Category { Name = "category1", SortOrder = 1 }, new Category { Name = "category2", SortOrder = 0 } }; editExpense.NotifyPropertyChanged(m => m.Categories, categories); // Model -> ViewModel var actualCategory = actual.Categories.Value?.ToList(); Assert.NotNull(actualCategory); Assert.Equal(2, actualCategory.Count); Assert.Equal("category2", actualCategory[0]); Assert.Equal("category1", actualCategory[1]); // Destroy actual.Destroy(); editExpense.NotifyPropertyChanged(m => m.Categories, new Category[] { }); Assert.NotEqual(0, actual.Categories.Value.Count()); }
public void SaveAsyncCommand() { var navigationService = new Mock <INavigationService>(); var editExpense = new Mock <IEditExpense>(); editExpense.Setup(m => m.Location).Returns("Location"); var actual = new AddExpensePageViewModel(navigationService.Object, editExpense.Object); Assert.NotNull(actual.SaveAsyncCommand); Assert.True(actual.SaveAsyncCommand.CanExecute()); actual.SaveAsyncCommand.Execute(); editExpense.Verify(m => m.SaveAsync(), Times.Once); navigationService.Verify(m => m.GoBackAsync(null, null, true), Times.Once); editExpense.NotifyPropertyChanged(m => m.Location, null); Assert.False(actual.SaveAsyncCommand.CanExecute()); // Destroy actual.Destroy(); editExpense.NotifyPropertyChanged(m => m.Location, "Location"); Assert.False(actual.SaveAsyncCommand.CanExecute()); }