public async Task GetCorrectSumForWithDeactivatedAccount() { // 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 account3 = 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); account3.Deactivate(); await context.AddAsync(account1); await context.AddAsync(account2); await context.AddAsync(account3); 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 ReturnCorrectAmount() { // Arrange ISystemDateHelper 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, 10), 50, PaymentType.Income, account); var payment2 = new Payment(new DateTime(2020, 09, 18), 20, PaymentType.Income, account); var payment3 = new Payment(new DateTime(2020, 09, 4), 30, PaymentType.Expense, account); await context.AddAsync(payment1); await context.AddAsync(payment2); await context.AddAsync(payment3); await context.SaveChangesAsync(); // Act decimal sum = await new GetMonthlyIncomeQuery.Handler(contextAdapter, systemDateHelper).Handle(new GetMonthlyIncomeQuery(), default); // Assert sum.Should().Be(70); }
public async Task DontIncludeDeactivatedAccountsInBalance() { // Arrange ISystemDateHelper systemDateHelper = Substitute.For <ISystemDateHelper>(); systemDateHelper.Today.Returns(new DateTime(2020, 09, 05)); var accountIncluded = new Account("test", 100); var accountDeactivated = new Account("test", 100); accountDeactivated.Deactivate(); var payment = new Payment(new DateTime(2020, 09, 25), 50, PaymentType.Expense, accountIncluded); await context.AddAsync(accountIncluded); await context.AddAsync(accountDeactivated); 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 Handler(IContextAdapter contextAdapter, ISystemDateHelper systemDateHelper) { this.contextAdapter = contextAdapter; this.systemDateHelper = systemDateHelper; }
/// <summary> /// Returns the last day of the month /// </summary> /// <returns>Last day of the month</returns> public static DateTime GetEndOfMonth(ISystemDateHelper systemDateHelper) { DateTime today = systemDateHelper.Today; return(new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month))); }
/// <summary> /// Returns the first day of the current month. /// </summary> /// <returns></returns> public static DateTime GetFirstDayMonth(ISystemDateHelper systemDateHelper) => new DateTime(systemDateHelper.Today.Year, systemDateHelper.Today.Month, 1);