예제 #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();
        }
예제 #2
0
        private static CreditCardSubscription CreateSut()
        {
            var id   = CreditCardSubscriptionId.NewId();
            var name = new CreditCardSubscriptionName("Silver");

            return(new CreditCardSubscription(id, DateTimeOffset.Now, name));
        }
예제 #3
0
 public static CreditCard CreateCard(CreditCardId?id = null, CreditCardSubscriptionId?subscriptionId = null)
 {
     return(new CreditCard(
                id ?? CreditCardId.NewId(),
                subscriptionId ?? CreditCardSubscriptionId.NewId(),
                DateTimeOffset.Now
                ));
 }
예제 #4
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));
        }
예제 #5
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)
                );
        }
예제 #6
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();
        }
예제 #7
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));
        }