Beispiel #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();
        }
        public void AddPayment_CorrectAttributes_Success(int _clientId, string _paymentId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            var addPaymentCommand = new AddPaymentCommand
            {
                sessionToken = testSessionToken,
                paymentId    = _paymentId
            };

            var lastOrder = DatabaseQueryProcessor.GetTheMostRecentOrder(_clientId);
            var total     = DatabaseQueryProcessor.GetTotal(lastOrder.orderId);

            var isSuccessfulPayment = PaymentMethod.Check(_paymentId, total);
            var handler             = new AddPaymentCommandHandler();
            var result = (SuccessInfoDto)handler.Handle(addPaymentCommand);

            DatabaseQueryProcessor.Erase();

            SessionRepository.RemoveSession(testSessionToken);
            Assert.IsTrue(result.isSuccess);
            Assert.IsTrue(isSuccessfulPayment);
        }
        public void AddPayment_IncorrectClientId_Exception(int _clientId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            var addPaymentCommand = new AddPaymentCommand
            {
                sessionToken = testSessionToken,
                paymentId    = "PAY-2RR93057JR3600055LQ5FWMA"
            };

            var          handler = new AddPaymentCommandHandler();
            TestDelegate result  = () => handler.Handle(addPaymentCommand);

            SessionRepository.RemoveSession(testSessionToken);

            Assert.Throws <Exception>(result);
        }
        public void AddPayment_ClientHasNoOrders_Success(int _clientId, string _paymentId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            var addPaymentCommand = new AddPaymentCommand
            {
                sessionToken = testSessionToken,
                paymentId    = _paymentId
            };

            var          handler = new AddPaymentCommandHandler();
            TestDelegate result  = () => handler.Handle(addPaymentCommand);

            SessionRepository.RemoveSession(testSessionToken);

            Assert.Throws <Exception>(result);
        }