public async Task CheckCard_PassesCorrectDetailsToBank_NoProcess() { var log = new Mock <ILogger <PaymentController> >(); var bank = new Mock <IBankProvider>(); var store = new Mock <IPaymentRequestStore>(); bank.Setup(x => x.ValidateCardDetailsAsync(It.IsAny <CardDetails>())) .Returns(Task.FromResult(false)); var controller = new PaymentController(log.Object, bank.Object, store.Object); var details = new CardDetails { CardholderName = "Robin Wood", CardNumber = "1234567890123456", Expires = DateTime.Now.AddMonths(5), ValidFrom = DateTime.Now.AddMonths(-1), CSC = "222" }; var response = await controller.CheckCard(details); // TODO: This is lazy, should check actual values of the object to ensure they've not changed bank.Verify(b => b.ValidateCardDetailsAsync(details), Times.Once); bank.VerifyNoOtherCalls(); store.VerifyNoOtherCalls(); }
public async Task CheckCard_InvalidCard_Ok_NotValid() { var log = new Mock <ILogger <PaymentController> >(); var bank = new Mock <IBankProvider>(); var store = new Mock <IPaymentRequestStore>(); bank.Setup(x => x.ValidateCardDetailsAsync(It.IsAny <CardDetails>())) .Returns(Task.FromResult(false)); var controller = new PaymentController(log.Object, bank.Object, store.Object); var response = await controller.CheckCard(new CardDetails()); Assert.IsInstanceOf <OkObjectResult>(response); var content = ((OkObjectResult)response).Value as CheckCardResult; Assert.False(content.Valid); }
public async Task CheckCard_InvalidModel_BadRequest() { var log = new Mock <ILogger <PaymentController> >(); var bank = new Mock <IBankProvider>(); var store = new Mock <IPaymentRequestStore>(); var controller = new PaymentController(log.Object, bank.Object, store.Object); controller.ModelState.AddModelError("an error", "error"); var response = await controller.CheckCard(new CardDetails { CardholderName = "Robin Wood", CardNumber = "1234567890123456", Expires = DateTime.Now.AddMonths(5), ValidFrom = DateTime.Now.AddMonths(-1), CSC = "000" }); Assert.IsInstanceOf <BadRequestObjectResult>(response); bank.VerifyNoOtherCalls(); store.VerifyNoOtherCalls(); }