예제 #1
0
        public async Task MakePaymentRequestCallsThroughToMediator()
        {
            MakePaymentCommand command = new MakePaymentCommand();
            var mediator = new Mock <IMediator>();
            var sut      = new PaymentsController(mediator.Object);

            await sut.MakePayment(command);

            mediator.Verify(x => x.Send(It.Is <MakePaymentCommand>(y => y == command), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task MakePayment_Returns201CreatedWithResponse_WhenPaymentMadeSuccessfully()
        {
            // Arrange
            var(makePaymentCommandDto, makePaymentCommand) = CreateFakeMakePaymentCommandAndDto();

            var fakeSuccessPaymentResponse = CreateFakeSuccessPaymentResponse();


            A.CallTo(() => _mapper.Map <MakePaymentCommand>(makePaymentCommandDto)).Returns(makePaymentCommand);

            A.CallTo(() => _mediator.Send(A <IRequest <PaymentResponse> > ._, A <CancellationToken> ._))
            .Returns(Task.FromResult(fakeSuccessPaymentResponse));

            // Act
            var action            = _sut.MakePayment(makePaymentCommandDto);
            var actionResult      = (CreatedResult)action.Result;
            var paymentResponseId = actionResult.Value
                                    .GetType().GetProperty("Id").GetValue(actionResult.Value).ToString();

            // Assert
            Assert.AreEqual(actionResult.StatusCode, 201);
            Assert.AreEqual(paymentResponseId, fakeSuccessPaymentResponse.Id.ToString());
        }