public async Task GetCorrectSumForSingleAccount() { // Arrange var account1 = new Account("test", 100); var account2 = new Account("test", 200); var payment1 = new Payment(DateTime.Now.AddDays(2), 50, PaymentType.Income, account1); var payment2 = new Payment(DateTime.Now.AddDays(2), 50, PaymentType.Expense, account2); await context.AddAsync(account1); await context.AddAsync(account2); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.SaveChangesAsync(); // Act decimal result = await new GetAccountEndOfMonthBalanceQuery.Handler(contextAdapterMock).Handle( new GetAccountEndOfMonthBalanceQuery(account1.Id), default); // Assert result.Should().Be(150); }
public async Task GetCorrectSumForSingleAccount() { // Arrange ISystemDateHelper systemDateHelper = Substitute.For <ISystemDateHelper>(); systemDateHelper.Today.Returns(new DateTime(2020, 09, 05)); var account1 = new Account("test", 100); var account2 = new Account("test", 200); var payment1 = new Payment(new DateTime(2020, 09, 15), 50, PaymentType.Income, account1); var payment2 = new Payment(new DateTime(2020, 09, 25), 50, PaymentType.Expense, account2); await context.AddAsync(account1); await context.AddAsync(account2); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.SaveChangesAsync(); // Act decimal result = await new GetAccountEndOfMonthBalanceQuery.Handler(contextAdapterMock, systemDateHelper).Handle( new GetAccountEndOfMonthBalanceQuery(account1.Id), default); // Assert result.Should().Be(150); }
public async Task GetPaymentsForAccountId_CorrectAccountId_PaymentFound() { // Arrange var account = new Account("test", 80); var payment1 = new Payment(DateTime.Now, 20, PaymentType.Expense, account); var payment2 = new Payment(DateTime.Now, 20, PaymentType.Expense, new Account("test", 80)); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.SaveChangesAsync(); // Act List<Payment> result = await new GetPaymentsForAccountIdQuery.Handler(contextAdapterMock.Object).Handle(new GetPaymentsForAccountIdQuery(account.Id, DateTime .Now .AddDays(-1), DateTime .Now .AddDays(1)), default); // Assert result.First().Id.ShouldEqual(payment1.Id); }
public async Task ReturnCorrectAmount() { // Arrange var systemDateHelper = Substitute.For <ISystemDateHelper>(); systemDateHelper.Today.Returns(new DateTime(2020, 09, 05)); var account = new Account("test", 80); var payment1 = new Payment(new DateTime(2020, 09, 03), 50, PaymentType.Expense, account); var payment2 = new Payment(new DateTime(2020, 09, 04), 20, PaymentType.Expense, account); var payment3 = new Payment(new DateTime(2020, 09, 04), 30, PaymentType.Income, account); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.AddAsync(payment3); await context.SaveChangesAsync(); // Act var sum = await new GetMonthlyExpenseQuery.Handler(contextAdapter, systemDateHelper).Handle(new GetMonthlyExpenseQuery(), default); // Assert sum.Should().Be(70); }
public async Task GetAccountQuery_CorrectNumberLoaded() { // Arrange var account = new Account("test", 80); await context.AddAsync(account); await context.SaveChangesAsync(); // Act List <Account> result = await new GetAccountsQuery.Handler(contextAdapterMock.Object).Handle(new GetAccountsQuery(), default); // Assert Assert.Single(result); }
public async Task GetExcludedAccountQuery_WithoutFilter_CorrectNumberLoaded() { // Arrange var category1 = new Category("test"); await context.AddAsync(category1); await context.SaveChangesAsync(); // Act await new DeleteCategoryByIdCommand.Handler(contextAdapterMock.Object, backupServiceMock.Object, settingsFacadeMock.Object) .Handle(new DeleteCategoryByIdCommand(category1.Id), default); // Assert (await context.Categories.FirstOrDefaultAsync(x => x.Id == category1.Id)).ShouldBeNull(); }
public async Task DeletePayment_PaymentDeleted() { // Arrange var payment1 = new Payment(DateTime.Now, 20, PaymentType.Expense, new Account("test", 80)); await context.AddAsync(payment1); await context.SaveChangesAsync(); // Act await new DeletePaymentByIdCommand.Handler(contextAdapterMock.Object, backupServiceMock.Object, settingsFacadeMock.Object) .Handle(new DeletePaymentByIdCommand(payment1.Id), default); // Assert Assert.Empty(context.Payments); }
public async Task DeactivatedAccountNotDeleted() { // Arrange var account = new Account("test"); await context.AddAsync(account); await context.SaveChangesAsync(); // Act await new DeactivateAccountByIdCommand.Handler(contextAdapterMock.Object, backupServiceMock.Object, settingsFacadeMock.Object) .Handle(new DeactivateAccountByIdCommand(account.Id), default); // Assert (await context.Accounts.FirstOrDefaultAsync(x => x.Id == account.Id)).Should().NotBeNull(); }
public async Task GetExcludedAccountQuery_WithoutFilter_CorrectNumberLoaded() { // Arrange var category1 = new Category("test"); var category2 = new Category("test2"); await context.AddAsync(category1); await context.AddAsync(category2); await context.SaveChangesAsync(); // Act List <Category> result = await new GetCategoryBySearchTermQuery.Handler(context).Handle(new GetCategoryBySearchTermQuery(), default); // Assert result.Count.ShouldEqual(2); }
public async Task GetExcludedAccountQuery_CorrectNumberLoaded() { // Arrange var accountExcluded = new Account("test", 80, isExcluded: true); var accountIncluded = new Account("test", 80); await context.AddAsync(accountExcluded); await context.AddAsync(accountIncluded); await context.SaveChangesAsync(); // Act List <Account> result = await new GetExcludedAccountQuery.Handler(context).Handle(new GetExcludedAccountQuery(), default); // Assert Assert.Single(result); }
public async Task GetAccountByIdQuery_CorrectNumberLoaded() { // Arrange var account1 = new Account("test2", 80); var account2 = new Account("test3", 80); await context.AddAsync(account1); await context.AddAsync(account2); await context.SaveChangesAsync(); // Act Account result = await new GetAccountByIdQuery.Handler(context).Handle(new GetAccountByIdQuery(account1.Id), default); // Assert result.Name.ShouldEqual(account1.Name); }
public async Task GetExcludedAccountQuery_CorrectNumberLoaded() { // Arrange var accountExcluded = new Account("test", 80, isExcluded: true); var accountIncluded = new Account("test", 80); await context.AddAsync(accountExcluded); await context.AddAsync(accountIncluded); await context.SaveChangesAsync(); // Act int result = await new GetAccountCountQuery.Handler(contextAdapter).Handle(new GetAccountCountQuery(), default); // Assert result.ShouldEqual(2); }
public async Task GetSummary() { // Arrange var accountExcluded = new Account("test", 80, isExcluded: true); var accountIncluded = new Account("test", 80); await context.AddAsync(accountExcluded); await context.AddAsync(accountIncluded); await context.SaveChangesAsync(); // Act var result = await new GetIncludedAccountBalanceSummaryQuery.Handler(contextAdapterMock.Object).Handle(new GetIncludedAccountBalanceSummaryQuery(), default); // Assert result.ShouldEqual(80); }
public async Task UpdateCategoryCommand_CorrectNumberLoaded() { // Arrange var category = new Category("test"); await context.AddAsync(category); await context.SaveChangesAsync(); // Act category.UpdateData("foo"); await new UpdateCategoryCommand.Handler(contextAdapterMock.Object, backupServiceMock.Object, settingsFacadeMock.Object) .Handle(new UpdateCategoryCommand(category), default); Category loadedCategory = await context.Categories.FindAsync(category.Id); // Assert loadedCategory.Name.ShouldEqual("foo"); }
public async Task GetExcludedAccountQuery_CorrectNumberLoaded(string name, bool expectedResult) { // Arrange var accountExcluded = new Account("Foo", 80, isExcluded: true); var accountIncluded = new Account("test", 80); await context.AddAsync(accountExcluded); await context.AddAsync(accountIncluded); await context.SaveChangesAsync(); // Act bool result = await new GetIfAccountWithNameExistsQuery.Handler(contextAdapterMock.Object) .Handle(new GetIfAccountWithNameExistsQuery(name), default); // Assert result.ShouldEqual(expectedResult); }
public async Task GetIncludedAccountBalanceSummary_CorrectSum() { // Arrange var accountIncluded = new Account("test", 100); var payment = new Payment(DateTime.Now.AddDays(2), 50, PaymentType.Expense, accountIncluded); await context.AddAsync(accountIncluded); await context.AddAsync(payment); await context.SaveChangesAsync(); // Act decimal result = await new GetTotalEndOfMonthBalanceQuery.Handler(contextAdapterMock).Handle( new GetTotalEndOfMonthBalanceQuery(), default); // Assert result.Should().Be(50); }
public async Task GetExcludedAccountQuery_CorrectNumberLoaded() { // Arrange var accountExcluded = new Account("test", 80, isExcluded: true); var accountIncluded = new Account("test", 80); await context.AddAsync(accountExcluded); await context.AddAsync(accountIncluded); await context.SaveChangesAsync(); // Act List <Account> resultList = await new GetExcludedAccountQuery.Handler(contextAdapterMock.Object) .Handle(new GetExcludedAccountQuery(), default); // Assert resultList.Should().ContainSingle(); resultList[0].CurrentBalance.Should().Be(80); }
public async Task UpdateCategoryCommand_CorrectNumberLoaded() { // Arrange var account = new Account("test", 80); await context.AddAsync(account); await context.SaveChangesAsync(); // Act account.UpdateAccount("foo"); await new UpdateAccountCommand.Handler(contextAdapterMock.Object, backupServiceMock.Object, settingsFacadeMock.Object) .Handle(new UpdateAccountCommand(account), default); Account loadedAccount = await context.Accounts.FindAsync(account.Id); // Assert loadedAccount.Name.Should().Be("foo"); }
public async Task GetIncludedAccountBalanceSummary_CorrectSum() { // Arrange var accountExcluded = new Account("test", 80, isExcluded: true); var accountIncluded1 = new Account("test", 100); var accountIncluded2 = new Account("test", 120); await context.AddAsync(accountExcluded); await context.AddAsync(accountIncluded1); await context.AddAsync(accountIncluded2); await context.SaveChangesAsync(); // Act decimal result = await new GetIncludedAccountBalanceSummaryQuery.Handler(context).Handle(new GetIncludedAccountBalanceSummaryQuery(), default); // Assert result.ShouldEqual(220); }
public async Task GetPaymentsQuery_CorrectNumberLoaded() { // Arrange var account = new Account("test", 80); var payment1 = new Payment(DateTime.Now.AddDays(1), 20, PaymentType.Expense, account); var payment2 = new Payment(DateTime.Now, 20, PaymentType.Expense, account); var payment3 = new Payment(DateTime.Now.AddMonths(1), 20, PaymentType.Expense, account); payment2.ClearPayment(); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.AddAsync(payment3); await context.SaveChangesAsync(); // Act List <Payment> result = await new GetUnclearedPaymentsOfThisMonthQuery.Handler(context).Handle(new GetUnclearedPaymentsOfThisMonthQuery(), default); // Assert Assert.Single(result); }
public async Task UpdatePayment_PaymentFound() { // Arrange var payment1 = new Payment(DateTime.Now, 20, PaymentType.Expense, new Account("test", 80)); await context.AddAsync(payment1); await context.SaveChangesAsync(); payment1.UpdatePayment(payment1.Date, 100, payment1.Type, payment1.ChargedAccount); // Act await new UpdatePaymentCommand.Handler(contextAdapterMock.Object, backupServiceMock.Object, settingsFacadeMock.Object) .Handle(new UpdatePaymentCommand(payment1.Id, payment1.Date, payment1.Amount, payment1.IsCleared, payment1.Type, payment1.Note, payment1.IsRecurring, payment1.Category != null ? payment1.Category.Id : 0, payment1.ChargedAccount != null ? payment1.ChargedAccount.Id : 0, payment1.TargetAccount != null ? payment1.TargetAccount.Id : 0, false, null, null, null), default); // Assert (await context.Payments.FindAsync(payment1.Id)).Amount.ShouldEqual(payment1.Amount); }
/// <inheritdoc /> public async Task SavePayment(PaymentViewModel paymentViewModel) { var payment = await CreatePaymentFromViewModel(paymentViewModel); await context.AddAsync(payment); foreach (var e in context.ChangeTracker.Entries()) { logger.Info("entity: {e}", e); } var count = await context.SaveChangesAsync(); logger.Info("{count} entities saved.", count); }
public async Task ReturnCorrectAmount() { // Arrange var account = new Account("test", 80); var payment1 = new Payment(DateTime.Now.AddDays(-2), 50, PaymentType.Expense, account); var payment2 = new Payment(DateTime.Now, 20, PaymentType.Expense, account); var payment3 = new Payment(DateTime.Now, 30, PaymentType.Income, account); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.AddAsync(payment3); await context.SaveChangesAsync(); // Act var sum = await new GetMonthlyExpenseQuery.Handler(contextAdapterMock).Handle(new GetMonthlyExpenseQuery(), default); // Assert sum.Should().Be(70); }
public async Task GetIncludedAccountBalanceSummary_CorrectSum() { // Arrange ISystemDateHelper systemDateHelper = Substitute.For <ISystemDateHelper>(); systemDateHelper.Today.Returns(new DateTime(2020, 09, 05)); var accountIncluded = new Account("test", 100); var payment = new Payment(new DateTime(2020, 09, 25), 50, PaymentType.Expense, accountIncluded); await context.AddAsync(accountIncluded); await context.AddAsync(payment); await context.SaveChangesAsync(); // Act decimal result = await new GetTotalEndOfMonthBalanceQuery.Handler(contextAdapterMock, systemDateHelper).Handle( new GetTotalEndOfMonthBalanceQuery(), default); // Assert result.Should().Be(50); }
public async Task GetExcludedAccountQuery_WithoutFilter_CorrectNumberLoaded() { // Arrange var account = new Account("test"); await context.AddAsync(account); await context.SaveChangesAsync(); // Act await new DeleteAccountByIdCommand.Handler(context).Handle(new DeleteAccountByIdCommand(account.Id), default); // Assert (await context.Accounts.FirstOrDefaultAsync(x => x.Id == account.Id)).ShouldBeNull(); }
public async Task DeletePayment_PaymentFound() { // Arrange var payment1 = new Payment(DateTime.Now, 20, PaymentType.Expense, new Account("test", 80)); await context.AddAsync(payment1); await context.SaveChangesAsync(); // Act await new DeletePaymentByIdCommand.Handler(context).Handle(new DeletePaymentByIdCommand(payment1.Id), default); // Assert Assert.Empty(context.Payments); }
public async Task GetCategory_CategoryFound() { // Arrange var payment1 = new Payment(DateTime.Now, 20, PaymentType.Expense, new Account("test", 80)); await context.AddAsync(payment1); await context.SaveChangesAsync(); // Act Payment result = await new GetPaymentByIdQuery.Handler(context).Handle(new GetPaymentByIdQuery(payment1.Id), default); // Assert result.ShouldNotBeNull(); result.Id.ShouldEqual(payment1.Id); }
public async Task GetAccountByIdQuery_CorrectNumberLoaded() { // Arrange var account1 = new Account("test2", 80); await context.AddAsync(account1); await context.SaveChangesAsync(); // Act string result = await new GetAccountNameByIdQuery.Handler(contextAdapterMock.Object).Handle(new GetAccountNameByIdQuery(account1.Id), default); // Assert result.Should().Be(account1.Name); }
public async Task UpdatePayment_PaymentFound() { // Arrange var payment1 = new Payment(DateTime.Now, 20, PaymentType.Expense, new Account("test", 80)); await context.AddAsync(payment1); await context.SaveChangesAsync(); payment1.UpdatePayment(payment1.Date, 100, payment1.Type, payment1.ChargedAccount); // Act await new UpdatePaymentCommand.Handler(context).Handle(new UpdatePaymentCommand(payment1), default); // Assert (await context.Payments.FindAsync(payment1.Id)).Amount.ShouldEqual(payment1.Amount); }
public async Task UpdateCategoryCommand_CorrectNumberLoaded() { // Arrange var category = new Category("test"); await context.AddAsync(category); await context.SaveChangesAsync(); // Act category.UpdateData("foo"); await new UpdateCategoryCommand.Handler(context).Handle(new UpdateCategoryCommand { Category = category }, default); Category loadedCategory = await context.Categories.FindAsync(category.Id); // Assert loadedCategory.Name.ShouldEqual("foo"); }