コード例 #1
0
        public async Task ProcessPayment_When_Payload_Is_Invalid_Then_Return_BadRequestResult()
        {
            _mockPaymentsService.Setup(x => x.ProcessPayment(It.IsAny <PaymentRequest>()))
            .ReturnsAsync(false);

            var controller = new PaymentsController(_logger, _mockPaymentsService.Object, _mockBankService.Object);

            var paymentRequest = new PaymentRequest
            {
                ExpiryMonth = DateTime.Now.Month,
                ExpiryYear  = DateTime.Now.Year
            };

            var validator        = new PaymentRequestValidator();
            var validationResult = await validator.ValidateAsync(paymentRequest);

            validationResult.AddToModelState(controller.ModelState, null);

            var expected = new BadRequestResult();
            var actual   = await controller.ProcessPayment(paymentRequest);

            actual.Should().BeEquivalentTo(expected);
        }