Exemplo n.º 1
0
        public void ShouldThrowBadRequestIfLogicThrowsException()
        {
            //Arrange
            var mockResult = GetMockResult();

            _calculateNPVResultsLogic.Setup(x => x.GetByRequestId(It.IsAny <int>()))
            .Throws(new System.Exception());

            var controller = new CalculateNPVResultsController(_calculateNPVResultsLogic.Object);

            //Act
            var calculateNPVRequests = controller.GetByRequestId(1);
            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);
        }
Exemplo n.º 2
0
        public void ShouldReturnCalculateNPVResultsSuccessfully()
        {
            //Arrange
            var mockResult = GetMockResult();

            _calculateNPVResultsLogic.Setup(x => x.GetByRequestId(It.IsAny <int>()))
            .Returns(Task.FromResult(mockResult));

            var controller = new CalculateNPVResultsController(_calculateNPVResultsLogic.Object);

            //Act
            var calculateNPVResults = controller.GetByRequestId(1);
            var contentResult       = calculateNPVResults.Result as OkNegotiatedContentResult <IList <CalculateNPVResult> >;


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