public async Task SelectedType_Transfer_LoadsItems() { var mocker = new AutoMocker().WithDefaults(); using var factory = mocker.WithDbScope(); using var _ = mocker.WithAutoDIResolver(); using var context = factory.Create(); var category1 = new ExpenseCategory { Name = "Foo" }; var category2 = new ExpenseCategory { Name = "Bar" }; var category3 = new ExpenseCategory { Name = "Cat" }; context.AddRange(category1, category2, category3); await context.SaveChangesAsync(); var vm = mocker.CreateInstance <AddItemViewModel>(); vm.SelectedType = AddType.Transfer; Assert.AreEqual(2, vm.LineItems.Count); Assert.IsNull(vm.LineItems[0].SelectedCategory); Assert.IsNull(vm.LineItems[1].SelectedCategory); Assert.AreEqual(DateTime.Today, vm.Date); }
public void Date_MonthsWithinRange_DoesNotShowWarning(int monthOffset) { var mocker = new AutoMocker().WithDefaults(); using var __ = mocker.WithAutoDIResolver(); using var _ = mocker.WithDbScope(); var vm = mocker.CreateInstance <AddItemViewModel>(); vm.Date = DateTime.Now.AddMonths(monthOffset); var errors = vm.GetErrors(nameof(vm.Date)).OfType <string>().ToList(); Assert.AreEqual(0, errors.Count); }
public void AddCommands_SetsAddItem(AddType?parameter, AddType expected) { var mocker = new AutoMocker() .WithDefaults(); using var scope = mocker.WithDbScope(); using var _ = mocker.WithAutoDIResolver(); var vm = mocker.CreateInstance <MainWindowViewModel>(); Assert.IsTrue(vm.ShowAddCommand.CanExecute(parameter)); vm.ShowAddCommand.Execute(parameter); Assert.IsNotNull(vm.AddItem); Assert.AreEqual(expected, vm.AddItem?.SelectedType); }
public void Date_MonthsOutOfRange_ShowsWarning(int monthOffset) { var now = DateTime.Now; var mocker = new AutoMocker().WithDefaults(); using var __ = mocker.WithAutoDIResolver(); using var _ = mocker.WithDbScope(); var vm = mocker.CreateInstance <AddItemViewModel>(); vm.Date = DateTime.Now.AddMonths(monthOffset); var errors = vm.GetErrors(nameof(vm.Date)).OfType <string>().ToList(); Assert.AreEqual(1, errors.Count); Assert.AreEqual($"Date should be between {now.AddMonths(-2).StartOfMonth():d} and {now.AddMonths(1).EndOfMonth():d}", errors[0]); }
public void TotalAmount_Transaction_UpdatesRemainingAmount() { var mocker = new AutoMocker().WithDefaults(); using var _ = mocker.WithDbScope(); using var __ = mocker.WithAutoDIResolver(); using var ___ = mocker.WithSynchonousTaskRunner(); var vm = mocker.CreateInstance <AddItemViewModel>(); vm.SelectedType = AddType.Transaction; vm.AddItemCommand.Execute(null); vm.TotalAmount = 100_00; vm.LineItems[0].Amount = 25_00; Assert.AreEqual(2, vm.LineItems.Count); Assert.AreEqual(25_00, vm.LineItems[0].Amount); Assert.AreEqual(0, vm.LineItems[1].Amount); Assert.AreEqual(75_00, vm.RemainingAmount); }
public void Date_ChangingCurrentMonth_ClearsWarning() { var mocker = new AutoMocker().WithDefaults(); using var _ = mocker.WithDbScope(); using var __ = mocker.WithAutoDIResolver(); using var ___ = mocker.WithSynchonousTaskRunner(); ICurrentMonth current = mocker.Get <ICurrentMonth>(); var vm = mocker.CreateInstance <AddItemViewModel>(); current.CurrenMonth = DateTime.Now.AddMonths(-10); vm.Date = DateTime.Now; var errorsBefore = vm.GetErrors(nameof(vm.Date)).OfType <string>().ToList(); current.CurrenMonth = DateTime.Now; var errorsAfter = vm.GetErrors(nameof(vm.Date)).OfType <string>().ToList(); Assert.AreEqual(1, errorsBefore.Count); Assert.AreEqual(0, errorsAfter.Count); }
public async Task SubmitCommand_TransactionIgnoreBudget_CreatesTransaction() { var mocker = new AutoMocker().WithDefaults(); using var factory = mocker.WithDbScope(); using var _ = mocker.WithAutoDIResolver(); using var __ = mocker.WithSynchonousTaskRunner(); using var context = factory.Create(); var category = new ExpenseCategory(); context.ExpenseCategories.Add(category); await context.SaveChangesAsync(); var vm = mocker.CreateInstance <AddItemViewModel>(); var today = DateTime.Today; vm.SelectedType = AddType.Transaction; vm.Description = "Test description"; vm.Date = today; vm.LineItems[0].Amount = 25_00; vm.LineItems[0].SelectedCategory = category; await vm.SubmitCommand.ExecuteAsync(true); using var verificationContext = factory.Create(); ExpenseCategoryItem transaction = await verificationContext.ExpenseCategoryItems .Include(x => x.Details) .SingleAsync(); Assert.AreEqual("Test description", transaction.Description); Assert.AreEqual(today, transaction.Date); Assert.IsTrue(transaction.IgnoreBudget); Assert.AreEqual(1, transaction.Details?.Count); Assert.AreEqual(-25_00, transaction.Details ![0].Amount);