コード例 #1
0
        public async Task Given_ValidPayment_When_PostIsInvoked_Then_SuccessIsReturned()
        {
            // arrange
            var paymentDto = new PaymentDto(
                785D,
                "EUR",
                new CreditCardDto(
                    "785",
                    "John Doe",
                    "78548569852364521",
                    this.futureMonth,
                    this.futureYear));

            var paymentResponseSuccess = new PaymentResponseSuccessDto();

            this.paymentService
            .Setup(p => p.PayAsync(It.IsAny <PaymentDto>()))
            .ReturnsAsync(paymentResponseSuccess);

            this.paymentResponseLinkBuilder
            .Setup(p => p.BuildLinks(It.IsAny <PaymentResponseSuccessDto>()))
            .Returns(paymentResponseSuccess);

            // act
            var actionResult = await paymentController.Post(paymentDto);

            // assert
            Assert.True(actionResult.Result is OkObjectResult);
            Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)HttpStatusCode.OK);
        }
コード例 #2
0
        public async Task Given_ValidId_When_GetIsInvoked_Then_SuccessIsReturned()
        {
            // arrange
            var id = Guid.NewGuid();

            var creditCard =
                new CreditCardDto(
                    "345",
                    "Rick Mark",
                    "7854896523654521",
                    this.futureMonth,
                    this.futureYear);

            var paymentDto =
                new PaymentDto(
                    4745D,
                    "RUB",
                    creditCard);

            var paymentResponseSuccess =
                new PaymentResponseSuccessDto(
                    id, paymentDto);

            this.paymentService
            .Setup(p => p.GetAsync(It.IsAny <Guid>()))
            .ReturnsAsync(paymentResponseSuccess);

            // act
            var actionResult = await paymentController.Get(id);

            // assert
            Assert.True(actionResult.Result is OkObjectResult);

            var okResult = actionResult.Result as OkObjectResult;

            var resultValue = okResult.Value as PaymentResponseSuccessDto;

            Assert.Equal(okResult.StatusCode, (int)HttpStatusCode.OK);
            Assert.Equal(paymentDto.Amount, resultValue.Payment.Amount);
            Assert.Equal(paymentDto.Currency, resultValue.Payment.Currency);
            Assert.Equal(paymentDto.PaymentMethod.CardNumber, resultValue.Payment.PaymentMethod.CardNumber);
            Assert.Equal(paymentDto.PaymentMethod.Name, resultValue.Payment.PaymentMethod.Name);
            Assert.Equal(paymentDto.PaymentMethod.CVV, resultValue.Payment.PaymentMethod.CVV);
        }