public void AcceptPaymentShouldThrowInvalidOperationException()
        {
            var payment = new Payment("mock", "mock", 1, 1);

            payment.AcceptPayment();

            Assert.Throws <InvalidOperationException>(() => payment.AcceptPayment());
        }
        public void AcceptPaymentShouldWork()
        {
            var payment = new Payment("mock", "mock", 1, 1);

            payment.AcceptPayment();

            var expected = true;
            var actual   = payment.IsPayed;

            Assert.Equal(expected, actual);
        }
        public async Task Handle(IThrowsException gatewayExceptionSimulator, Guid gatewayPaymentId)
        {
            Payment knownPayment  = null;
            var     bankPaymentId = _bankResponse.BankPaymentId;

            try
            {
                try
                {
                    knownPayment = await _paymentsRepository.GetById(gatewayPaymentId);

                    gatewayExceptionSimulator?.Throws();
                }
                catch (AggregateNotFoundException)
                {
                    return;
                }

                switch (_bankResponse.PaymentStatus)
                {
                case BankPaymentStatus.Accepted:
                    knownPayment.AcceptPayment(bankPaymentId);
                    break;

                case BankPaymentStatus.Rejected:
                    knownPayment.BankRejectPayment(bankPaymentId);
                    break;
                }

                await _paymentsRepository.Save(knownPayment, knownPayment.Version);
            }

            catch (Exception)
            {
                //TODO: log
                knownPayment.FailOnGateway(bankPaymentId);
                await _paymentsRepository.Save(knownPayment, knownPayment.Version);
            }
        }
        public void CheckIfAcceptingPaymentWorks()
        {
            Payment payment = new Payment();

            Assert.AreEqual(5000, payment.AcceptPayment(4000, 1000));
        }
        public void UpdatePaymentsTest(decimal amount1, bool isPayed1,
                                       decimal amount2, bool isPayed2,
                                       decimal amount3, bool isPayed3,
                                       decimal amount4, bool isPayed4,
                                       decimal received, decimal toReceive, decimal payed, decimal toPay)
        {
            //Arrange
            var user     = new User("mock", "mock");
            var payment1 = new Payment("mock", "mock", 1, amount1);

            if (isPayed1)
            {
                payment1.AcceptPayment();
            }
            var payment2 = new Payment("mock", "mock", 1, amount2);

            if (isPayed2)
            {
                payment2.AcceptPayment();
            }
            var payment3 = new Payment("mock", "mock", 1, amount3);

            if (isPayed3)
            {
                payment3.AcceptPayment();
            }
            var payment4 = new Payment("mock", "mock", 1, amount4);

            if (isPayed4)
            {
                payment4.AcceptPayment();
            }

            var receivedPayments = new List <Payment>()
            {
                payment1,
                payment2
            };
            var payedPayments = new List <Payment>()
            {
                payment3,
                payment4
            };

            user.ReceivedPayments.AddRange(receivedPayments);
            user.PayedPayments.AddRange(payedPayments);


            //Act
            user.UpdatePayments();
            var expectedPayed = payed;
            var actualPayed   = user.Payed;

            var expectedToPay = toPay;
            var actualToPay   = user.ToPay;

            var expectedReceived = received;
            var actualReceived   = user.Received;

            var expectedToReceive = toReceive;
            var actualToReceive   = user.ToReceive;

            //Assert
            Assert.Equal(expectedPayed, actualPayed);
            Assert.Equal(expectedToPay, actualToPay);
            Assert.Equal(expectedReceived, actualReceived);
            Assert.Equal(expectedToReceive, actualToReceive);
        }