Пример #1
0
        public async Task GetPayment_ReturnsNotFoundResult_WhenPaymentNotFound()
        {
            // Arrange

            Guid id = Guid.NewGuid();

            PaymentRespModel     paymentRespModel     = null;
            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

            mockPaymentManager.Setup(s => s.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>()))
            .Returns(Task.FromResult <(PaymentRespModel, ModelStateDictionary)>((paymentRespModel, modelStateDictionary)))
            .Verifiable();

            // Act

            ActionResult actionResult = await paymentController.Get(id) as ActionResult;

            // Assert

            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOf <NotFoundResult>(actionResult);

            NotFoundResult notFoundResult = actionResult as NotFoundResult;

            Assert.IsNotNull(notFoundResult);
            Assert.AreEqual(StatusCodes.Status404NotFound, notFoundResult.StatusCode);

            mockPaymentManager.Verify(v => v.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>()));
        }
Пример #2
0
        public async Task GetPayment_ReturnsOkObjectResult()
        {
            // Arrange

            Guid          id            = Guid.NewGuid();
            PaymentStatus paymentStatus = PaymentStatus.Paid;

            PaymentRespModel     paymentRespModel     = MockPaymentRespModel.Get(id, paymentStatus);
            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

            mockPaymentManager.Setup(s => s.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>()))
            .Returns(Task.FromResult <(PaymentRespModel, ModelStateDictionary)>((paymentRespModel, modelStateDictionary)))
            .Verifiable();

            // Act

            ActionResult actionResult = await paymentController.Get(id) as ActionResult;

            // Assert

            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOf <OkObjectResult>(actionResult);

            OkObjectResult okObjectResult = actionResult as OkObjectResult;

            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(StatusCodes.Status200OK, okObjectResult.StatusCode);

            Assert.IsNotNull(okObjectResult.Value);
            Assert.IsInstanceOf <PaymentRespVM>(okObjectResult.Value);

            PaymentRespVM paymentRespVM = okObjectResult.Value as PaymentRespVM;

            Assert.IsNotNull(paymentRespVM);
            Assert.AreEqual(id, paymentRespVM.Id);
            Assert.AreEqual(paymentStatus.ToString(), paymentRespVM.Status);
            Assert.AreEqual(CurrencyCode.GBP.ToString(), paymentRespVM.Currency);
            Assert.AreEqual(1, paymentRespVM.Amount);

            Assert.IsNotNull(paymentRespVM.CardDetails);
            Assert.AreEqual("J Doe", paymentRespVM.CardDetails.NameOnCard);
            Assert.AreEqual(CardType.Credit.ToString(), paymentRespVM.CardDetails.CardType);
            Assert.AreEqual(Issuer.Visa.ToString(), paymentRespVM.CardDetails.Issuer);
            Assert.AreEqual("6331", paymentRespVM.CardDetails.CardnumberLast4);
            Assert.AreEqual("***", paymentRespVM.CardDetails.Cvv);
            Assert.AreEqual(1, paymentRespVM.CardDetails.ExpiryMonth);
            Assert.AreEqual(2020, paymentRespVM.CardDetails.ExpiryYear);

            mockPaymentManager.Verify(v => v.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>()));
        }
Пример #3
0
        public async Task GetAsync_ReturnsPaymentRespModel()
        {
            // Arrange

            Guid          paymentId     = Guid.NewGuid();
            PaymentStatus paymentStatus = PaymentStatus.Paid;

            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

            PaymentRespModel paymentRespModel = MockPaymentRespModel.Get(paymentId, paymentStatus);

            mockHttpClientManager.Setup(s => s.GetAsync <PaymentRespModel>(It.IsAny <string>()))
            .Returns(Task.FromResult <(PaymentRespModel, string)>((paymentRespModel, null)))
            .Verifiable();

            // Act

            (PaymentRespModel paymentRespModelResp, ModelStateDictionary modelStateDictionaryResp) = await paymentManager.GetAsync(paymentId, modelStateDictionary);

            // Assert

            Assert.IsNotNull(paymentRespModelResp);

            Assert.AreEqual(paymentId, paymentRespModelResp.Id);
            Assert.AreEqual(paymentStatus.ToString(), paymentRespModelResp.Status);
            Assert.AreEqual(CurrencyCode.GBP.ToString(), paymentRespModelResp.Currency);
            Assert.AreEqual(1, paymentRespModelResp.Amount);

            Assert.IsNotNull(paymentRespModelResp.CardDetails);
            Assert.AreEqual("J Doe", paymentRespModelResp.CardDetails.NameOnCard);
            Assert.AreEqual(CardType.Credit.ToString(), paymentRespModelResp.CardDetails.CardType);
            Assert.AreEqual(Issuer.Visa.ToString(), paymentRespModelResp.CardDetails.Issuer);
            Assert.AreEqual("4485236273376331", paymentRespModelResp.CardDetails.Cardnumber);
            Assert.AreEqual("123", paymentRespModelResp.CardDetails.Cvv);
            Assert.AreEqual(1, paymentRespModelResp.CardDetails.ExpiryMonth);
            Assert.AreEqual(2020, paymentRespModelResp.CardDetails.ExpiryYear);

            Assert.IsNotNull(paymentRespModelResp.RecipientDetails);
            Assert.AreEqual("A Smith", paymentRespModelResp.RecipientDetails.Name);
            Assert.AreEqual("040004", paymentRespModelResp.RecipientDetails.SortCode);
            Assert.AreEqual("12345678", paymentRespModelResp.RecipientDetails.Accountnumber);
            Assert.AreEqual("Mocked", paymentRespModelResp.RecipientDetails.PaymentRefernce);

            Assert.IsNotNull(modelStateDictionaryResp);
            Assert.IsTrue(modelStateDictionaryResp.IsValid);

            mockHttpClientManager.Verify(v => v.GetAsync <PaymentRespModel>(It.IsAny <string>()));
        }
Пример #4
0
        public async Task GetPayment_ReturnsBadRequestObjectResult_WhenInvalidModelStateReturned()
        {
            // Arrange

            Guid id = Guid.NewGuid();

            PaymentRespModel paymentRespModel = null;

            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

            modelStateDictionary.AddModelError("UnitTest", "Error");

            mockPaymentManager.Setup(s => s.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>()))
            .Returns(Task.FromResult <(PaymentRespModel, ModelStateDictionary)>((paymentRespModel, modelStateDictionary)))
            .Verifiable();

            // Act

            ActionResult actionResult = await paymentController.Get(id) as ActionResult;

            // Assert

            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOf <BadRequestObjectResult>(actionResult);

            BadRequestObjectResult badRequestObjectResult = actionResult as BadRequestObjectResult;

            Assert.IsNotNull(badRequestObjectResult);
            Assert.AreEqual(StatusCodes.Status400BadRequest, badRequestObjectResult.StatusCode);

            Assert.IsNotNull(badRequestObjectResult.Value);
            Assert.IsInstanceOf <SerializableError>(badRequestObjectResult.Value);

            SerializableError serializableError = badRequestObjectResult.Value as SerializableError;

            Assert.IsNotNull(serializableError);

            Assert.AreEqual(1, serializableError.Keys.Count());
            Assert.IsTrue(serializableError.ContainsKey("UnitTest"));

            mockPaymentManager.Verify(v => v.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>()));
        }