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 IResult Handle(AddPaymentCommand command)
        {
            int clientId = SessionRepository.GetClientIdOfSession(command.sessionToken);

            if (clientId == -1)
            {
                throw new Exception();
            }

            var order = DatabaseQueryProcessor.GetTheMostRecentOrder(clientId);

            if (order == null)
            {
                throw new Exception();
            }

            var totalPrice = DatabaseQueryProcessor.GetTotal(order.orderId);

            DatabaseQueryProcessor.CreateNewPayment(
                command.paymentId,
                order.orderId,
                totalPrice,
                DateTime.Now.ToString("yyyy-MM-dd")
                );

            ThreadPool.QueueUserWorkItem(
                o => new OrderPlacementEmail().Send(clientId));



            var isSuccessPayment = PaymentMethod.Check(command.paymentId, totalPrice);

            if (isSuccessPayment)
            {
                DatabaseQueryProcessor.UpdateOrder(order.orderId, 1);
                ThreadPool.QueueUserWorkItem(o =>
                                             new SuccessfullPaymentEmail().Send(clientId));
            }
            else
            {
                ThreadPool.QueueUserWorkItem(o =>
                                             new UnsuccessfullPaymentEmail().Send(clientId));
            }

            return(new SuccessInfoDto
            {
                isSuccess = true
            });
        }
        public void AddPayment_CheckTransaction_Success(string _paymentId, int _total)
        {
            var isSuccessfulPayment = PaymentMethod.Check(_paymentId, _total);

            Assert.IsTrue(isSuccessfulPayment);
        }