Example #1
0
        public void ShouldThrowBadRequestIfLogicThrowsException()
        {
            //Arrange
            _calculateNPVRequestsLogic.Setup(x => x.GetAllAsync(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>()))
            .Throws(new System.Exception());

            var controller = new CalculateNPVRequestsController(_calculateNPVRequestsLogic.Object);

            //Act
            var calculateNPVRequests = controller.Get();
            var badRequestResult     = calculateNPVRequests.Result as BadRequestWithErrorsResult;
            var responseMessage      = badRequestResult.Execute();

            //Assert
            Assert.IsNotNull(badRequestResult);
            Assert.IsInstanceOfType(badRequestResult, typeof(BadRequestWithErrorsResult));
            Assert.AreEqual(responseMessage.StatusCode, System.Net.HttpStatusCode.BadRequest);
        }
Example #2
0
        public void ShouldReturnCalculateNPVRequestsSuccessfully()
        {
            //Arrange
            var mockResult = GetMockResult();

            _calculateNPVRequestsLogic.Setup(x => x.GetAllAsync(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>()))
            .Returns(Task.FromResult(mockResult));

            var controller = new CalculateNPVRequestsController(_calculateNPVRequestsLogic.Object);

            //Act
            var calculateNPVRequests = controller.Get();
            var contentResult        = calculateNPVRequests.Result as OkNegotiatedContentResult <IList <CalculateNPVRequest> >;


            //Assert
            Assert.IsNotNull(calculateNPVRequests);
            Assert.IsNotNull(contentResult.Content);
            Assert.IsInstanceOfType(contentResult.Content, typeof(List <CalculateNPVRequest>));
        }