Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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());
        }
Пример #6
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());
        }