Beispiel #1
0
        public async Task PostPayment_ReturnsBadRequestObjectResult_WhenInvalidModelStateReturned()
        {
            // Arrange

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

            PaymentReqVM paymentReqVM = MockPaymentReqVM.Get();

            PaymentReqRespModel  paymentReqRespModel  = MockPaymentReqRespModel.Get(id, paymentStatus);
            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

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


            mockPaymentManager.Setup(s => s.PostAsync(It.IsAny <PaymentReqModel>(), It.IsAny <ModelStateDictionary>()))
            .Returns(Task.FromResult <(PaymentReqRespModel, ModelStateDictionary)>((paymentReqRespModel, modelStateDictionary)))
            .Verifiable();

            // Act

            ActionResult actionResult = await paymentController.Post(paymentReqVM) 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.PostAsync(It.IsAny <PaymentReqModel>(), It.IsAny <ModelStateDictionary>()));
        }
Beispiel #2
0
        public async Task PostPayment_ReturnsCreatedResult()
        {
            // Arrange

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

            PaymentReqVM paymentReqVM = MockPaymentReqVM.Get();

            PaymentReqRespModel  paymentReqRespModel  = MockPaymentReqRespModel.Get(id, paymentStatus);
            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

            mockPaymentManager.Setup(s => s.PostAsync(It.IsAny <PaymentReqModel>(), It.IsAny <ModelStateDictionary>()))
            .Returns(Task.FromResult <(PaymentReqRespModel, ModelStateDictionary)>((paymentReqRespModel, modelStateDictionary)))
            .Verifiable();

            // Act

            ActionResult actionResult = await paymentController.Post(paymentReqVM) as ActionResult;

            // Assert

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

            CreatedResult createdResult = actionResult as CreatedResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(StatusCodes.Status201Created, createdResult.StatusCode);

            Assert.IsNotNull(createdResult.Value);
            Assert.IsInstanceOf <PaymentCreatedRespVM>(createdResult.Value);

            PaymentCreatedRespVM paymentCreatedRespVM = createdResult.Value as PaymentCreatedRespVM;

            Assert.IsNotNull(paymentCreatedRespVM);
            Assert.AreEqual(id, paymentCreatedRespVM.Id);
            Assert.AreEqual(paymentStatus.ToString(), paymentCreatedRespVM.Status);
            Assert.AreEqual($"/api/v1/Payment/{id}", paymentCreatedRespVM.Href);

            mockPaymentManager.Verify(v => v.PostAsync(It.IsAny <PaymentReqModel>(), It.IsAny <ModelStateDictionary>()));
        }