public async Task TestCreatePaymentInactiveMerchant()
        {
            Merchant.Active = false;
            await PaymentDb.SaveChangesAsync();

            var paymentRequest = GetPaymentRequest();
            var response       = await Subject.PostPayment(paymentRequest);

            Assert.IsInstanceOfType(response.Result, typeof(BadRequestObjectResult));
            Assert.IsNull(response.Value);
        }
        public async Task TestGetPaymentNotCurrentMerchant()
        {
            var payment = GetPayment(UnknownMerchantId);

            PaymentDb.Payments.Add(payment);
            await PaymentDb.SaveChangesAsync();

            var response = await Subject.GetPayment(payment.Id);

            Assert.IsInstanceOfType(response.Result, typeof(NotFoundResult));
            Assert.IsNull(response.Value);
        }
        public async Task TestGetPaymentsEmpty()
        {
            var payments = new[]
            {
                GetPayment(UnknownMerchantId),
            };

            PaymentDb.Payments.AddRange(payments);
            await PaymentDb.SaveChangesAsync();

            var response = await Subject.GetPayments();

            var paymentsResponse = response.Value.ToArray();

            Assert.AreEqual(0, paymentsResponse.Length);
        }
        public async Task TestGetPaymentSuccess()
        {
            var payment = GetPayment(Merchant.Id);

            PaymentDb.Payments.Add(payment);
            await PaymentDb.SaveChangesAsync();

            var response = await Subject.GetPayment(payment.Id);

            var paymentResponse = response.Value;

            Assert.AreEqual(payment.Id, paymentResponse.Id);
            Assert.AreEqual(payment.Status, paymentResponse.Status);
            Assert.AreEqual(payment.Amount, paymentResponse.Amount);
            Assert.AreEqual(payment.Currency, paymentResponse.Currency);
            Assert.AreEqual(payment.ExpiryMonth, paymentResponse.ExpiryMonth);
            Assert.AreEqual(payment.ExpiryYear, paymentResponse.ExpiryYear);
            Assert.AreEqual("XXXXXX" + payment.CardLastDigits, paymentResponse.MaskedCardNumber);
        }
        public override async Task Setup()
        {
            await base.Setup();

            BankRegistry = new Mock <IBankRegistry>();
            Merchant     = new Merchant
            {
                AcquirerType   = AcquirerType.MasterCard,
                Active         = true,
                HashedPassword = "******",
                Id             = 1,
                Login          = "******",
                Salt           = EncryptionService.GenerateSalt(),
                Name           = "Some Merchant"
            };
            PaymentDb.Merchants.Add(Merchant);
            await PaymentDb.SaveChangesAsync();

            Acquirer = new Mock <IAcquirer>();
            BankRegistry.Setup(t => t.GetAcquirer(Merchant))
            .Returns(Acquirer.Object);
            Subject = new PaymentsController(PaymentDb, BankRegistry.Object, EncryptionService);
            SetMerchantId(Subject, Merchant.Id);
        }