示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        public void OnNavigatedTo()
        {
            var navigationService = new Mock <INavigationService>();
            var editExpense       = new Mock <IEditExpense>();
            var actual            = new AddExpensePageViewModel(navigationService.Object, editExpense.Object);

            actual.OnNavigatedTo(null);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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
            // ...
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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());
        }
示例#12
0
        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());
        }