private Charge GetTestCharge(DateTime?date = null, AmountCurrency amountCurrency = null) { return(new Charge() { Amount = amountCurrency ?? new AmountCurrency(100, "ARS"), Event = new Event() { Id = 1, Date = date ?? DateTime.Now, Type = new EventType() { }, User = MockData.GetTestUser(), }, Payments = new List <PaymentCharge>() }); }
public async Task ShouldGetCorrectDebtByCurrency() { var chargeRepositoryMock = new Mock <IRepository <Charge> >(); chargeRepositoryMock.Setup(x => x.ListAsync( It.IsAny <Expression <Func <Charge, bool> > >(), It.IsAny <SortOptions>(), It.IsAny <int?>(), It.IsAny <int?>())) .Returns((Expression <Func <Charge, bool> > predicate, SortOptions sortOptions, int?pageSize, int?pageNum) => //Return charges after applying UserDebtService's predicate Task.FromResult(GetTestCharges().Where(predicate.Compile()).ToList())); UserDebtService userDebtService = new UserDebtService(chargeRepositoryMock.Object); AmountCurrency debt = await userDebtService.GetUserDebtByCurrency( MockData.GetTestUser().Id, Enumerations.Currency.ARS); Assert.Multiple(() => { Assert.AreEqual(63.75M, debt.Amount, "AR$ debt should be $63.75"); Assert.AreEqual(Enumerations.Currency.ARS, debt.Currency, "Debt currency should be AR$"); }); }
/// <summary> /// Validate payment is valid for the user's debt. /// e.g.: Payment cannot exceed user's debt /// </summary> /// <param name="payment"></param> /// <param name="userId"></param> /// <returns></returns> public async Task <bool> IsValidPayment(Payment payment) { AmountCurrency userDebtAmount = await GetUserDebtByCurrency(payment.User.Id, payment.Currency); return(payment.Amount <= userDebtAmount.Amount); }