コード例 #1
0
        public async Task Return_Successful_DetailsResponse_By_MerchantId()
        {
            // Arrange
            var httpContext = new DefaultHttpContext();

            var controller = new PaymentController(NullLogger <PaymentController> .Instance, _paymentServiceMock.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext
                }
            };

            var detailsResponse = _fixture.Build <DetailsResponse>()
                                  .With(x => x.Success, true)
                                  .Create();

            _paymentServiceMock.Setup(x => x.GetDetailsAsync("merchantId1", null))
            .ReturnsAsync(detailsResponse);

            // Act
            var result = await controller.GetDetailsAsync("merchantId1", null) as OkObjectResult;

            var response = result.Value as DetailsResponse;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.OK, result.StatusCode);
            Assert.IsTrue(response.Success);
            Assert.AreEqual(detailsResponse.MaskedCardNo, response.MaskedCardNo);
        }
コード例 #2
0
        public async Task Return_NotFound_When_Null()
        {
            // Arrange
            var httpContext = new DefaultHttpContext();

            var controller = new PaymentController(NullLogger <PaymentController> .Instance, _paymentServiceMock.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext
                }
            };

            // Act
            var result = await controller.GetDetailsAsync(null, "paymentId1") as NotFoundObjectResult;

            var response = result.Value as DetailsResponse;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.NotFound, result.StatusCode);
            Assert.IsFalse(response.Success);
        }