Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
 public static CreditCard CreateCard(CreditCardId?id = null, CreditCardSubscriptionId?subscriptionId = null)
 {
     return(new CreditCard(
                id ?? CreditCardId.NewId(),
                subscriptionId ?? CreditCardSubscriptionId.NewId(),
                DateTimeOffset.Now
                ));
 }
Exemplo n.º 3
0
        public async Task <ActionResult <CreditCardCreatedResponse> > AddCard([FromBody] CreateCreditCardModel model)
        {
            var cardId = CreditCardId.NewId();
            await _mediator.Send(new CreateCreditCard(cardId, model.CreditCardSubscriptionId, _clock.Now));

            return(Ok(new CreditCardCreatedResponse {
                CreditCardId = cardId
            }));
        }
Exemplo n.º 4
0
        public async Task When_AddPayment_To_Non_Existing_card_return_NotFound()
        {
            var result = await _service.AddPayment(CreditCardId.NewId(), new AddPaymentModel
            {
                Date   = DateTimeOffset.Now,
                Amount = 200
            });

            Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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)
                );
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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));
        }