public async Task When_AddPaymentCommand_Get_Subscription_Corresponding_To_CreditCard() { var subId = CreditCardSubscriptionId.NewId(); var creditCard = new CreditCard(CreditCardId.NewId(), subId, DateTimeOffset.Now); var repo = A.Fake <IAggregateRepository <CreditCard> >(); A.CallTo(() => repo.GetByIdAsync(creditCard.Id)) .Returns(creditCard); var subRepository = A.Fake <IAggregateRepository <CreditCardSubscription> >(); var sub = new CreditCardSubscription(subId, DateTimeOffset.Now, new CreditCardSubscriptionName("gold")); sub.UseNoPaymentFee(DateTimeOffset.Now); A.CallTo(subRepository) .WithReturnType <Task <CreditCardSubscription> >() .Returns(sub); var sut = new AddPaymentCommandHandler(repo, subRepository); await sut.Handle(new AddPaymentCommand { AggregateId = creditCard.Id, Payment = new Payment(PaymentId.NewId(), Money.CreateAUD(200), DateTimeOffset.Now) }, CancellationToken.None); A.CallTo(() => subRepository.GetByIdAsync(subId)) .MustHaveHappenedOnceExactly(); A.CallTo(() => repo.SaveAsync(A <CreditCard> ._, A <long> ._)) .MustHaveHappenedOnceExactly(); }
private static CreditCardSubscription CreateSut() { var id = CreditCardSubscriptionId.NewId(); var name = new CreditCardSubscriptionName("Silver"); return(new CreditCardSubscription(id, DateTimeOffset.Now, name)); }
public static CreditCard CreateCard(CreditCardId?id = null, CreditCardSubscriptionId?subscriptionId = null) { return(new CreditCard( id ?? CreditCardId.NewId(), subscriptionId ?? CreditCardSubscriptionId.NewId(), DateTimeOffset.Now )); }
public void When_CreditCard_Created_Applies_CreditCardCreated() { var id = CreditCardId.NewId(); var subId = CreditCardSubscriptionId.NewId(); var sut = new CreditCard(id, subId, DateTimeOffset.Now); var actual = sut.GetUncommittedChanges(); Assert.True(actual.OfType <CreditCardCreated>() .Any(x => x.CreditCardSubscription == subId && x.AggregateId == id)); Assert.That(sut.SubscriptionId, Is.EqualTo(subId)); }
public void When_CreateCardCommand_Subscription_Does_Not_exist_Throw_InvalidOperationException() { var repo = A.Fake <IAggregateRepository <CreditCard> >(); var subRepository = A.Fake <IAggregateRepository <CreditCardSubscription> >(); A.CallTo(() => subRepository.ExistsAsync(A <CreditCardSubscriptionId> ._)) .Returns(false); var clock = A.Fake <ISystemClock>(); var sut = new CreateCreditCardHandler(repo, subRepository, clock); Assert.ThrowsAsync <InvalidOperationException>( () => sut.Handle( new CreateCreditCard(CreditCardId.NewId(), CreditCardSubscriptionId.NewId(), DateTimeOffset.Now), CancellationToken.None) ); }
public async Task When_CreateCardCommand_Valid_Arguments_Saves_Card() { var repo = A.Fake <IAggregateRepository <CreditCard> >(); var subRepository = A.Fake <IAggregateRepository <CreditCardSubscription> >(); A.CallTo(() => subRepository.ExistsAsync(A <CreditCardSubscriptionId> ._)) .Returns(true); var clock = A.Fake <ISystemClock>(); var sut = new CreateCreditCardHandler(repo, subRepository, clock); await sut.Handle( new CreateCreditCard(CreditCardId.NewId(), CreditCardSubscriptionId.NewId(), DateTimeOffset.Now), CancellationToken.None); A.CallTo(() => repo.SaveAsync(A <CreditCard> ._, A <long> ._)) .MustHaveHappenedOnceExactly(); }
public void When_CreditCard_AddTransaction_Applies_CreditCardTransactionAdded() { var id = CreditCardId.NewId(); var subId = CreditCardSubscriptionId.NewId(); var transaction = Transaction.CreatePayment(new Payment(PaymentId.NewId(), Money.CreateAUD(200), DateTimeOffset.Now)); var sut = new CreditCard(id, subId, DateTimeOffset.Now); var actual = sut.GetUncommittedChanges(); sut.AddTransaction(transaction, DateTimeOffset.Now); Assert.True(actual.OfType <CreditCardTransactionAdded>().Any(x => x.Transaction.Id == transaction.Id && x.Transaction.Value == transaction.Value && x.AggregateId == id)); }