示例#1
0
        public void PutCashflowCategories_Return_InternalServerError()
        {
            //Setup
            Mock <IServiceProvider> serviceProviderMock = GetServiceProvider();
            var service = new Mock <IBudgetCashflowService>();

            CashflowTypeFormDto formDto = new CashflowTypeFormDto();

            service
            .Setup(s => s.UpdateBudgetCashflowCategory(It.IsAny <int>(), It.IsAny <CashflowCategoryFormDto>()))
            .Throws(new Exception());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService)))
            .Returns(service.Object);

            //Act

            IActionResult response = GetController(serviceProviderMock).PutCashflowCategories(1, new CashflowCategoryFormDto());

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode);
        }
示例#2
0
        public IActionResult PostCashflowType([FromBody] CashflowTypeFormDto form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);

                var id = _service.CreateBudgetCashflowType(form);

                var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok();

                return(Created(string.Concat(Request.Path, "/", id), result));
            }
            catch (ServiceValidationException e)
            {
                var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }
示例#3
0
        public void PostCashflowCategory_Throws_ValidationException()
        {
            //Setup
            Mock <IServiceProvider> serviceProviderMock = GetServiceProvider();
            var service = new Mock <IBudgetCashflowService>();

            CashflowTypeFormDto formDto = new CashflowTypeFormDto();

            service
            .Setup(s => s.CreateBudgetCashflowCategory(It.IsAny <CashflowCategoryFormDto>()))
            .Throws(GetServiceValidationException(formDto));

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService)))
            .Returns(service.Object);

            //Act

            IActionResult response = GetController(serviceProviderMock).PostCashflowCategory(new CashflowCategoryFormDto());

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.BadRequest, statusCode);
        }
示例#4
0
        public void GetCashflowCategoryById_Return_OK()
        {
            //Setup
            Mock <IServiceProvider> serviceProviderMock = GetServiceProvider();
            var service = new Mock <IBudgetCashflowService>();

            service
            .Setup(s => s.GetBudgetCashflowCategoryById(It.IsAny <int>()))
            .Returns(new BudgetCashflowCategoryModel());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService)))
            .Returns(service.Object);

            //Act
            CashflowTypeFormDto formDto  = new CashflowTypeFormDto();
            IActionResult       response = GetController(serviceProviderMock).GetCashflowCategoryById(1);

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.OK, statusCode);
        }
示例#5
0
        public void DeleteCashflowCategory_Return_NoContent()
        {
            //Setup
            Mock <IServiceProvider> serviceProviderMock = GetServiceProvider();
            var service = new Mock <IBudgetCashflowService>();

            service
            .Setup(s => s.DeleteBudgetCashflowCategories(It.IsAny <int>()))
            .Returns(1);

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService)))
            .Returns(service.Object);

            //Act
            CashflowTypeFormDto formDto  = new CashflowTypeFormDto();
            IActionResult       response = GetController(serviceProviderMock).DeleteCashflowCategory(1);

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.NoContent, statusCode);
        }
示例#6
0
        public void GetCashflowCategories_Return_OK()
        {
            //Setup
            Mock <IServiceProvider> serviceProviderMock = GetServiceProvider();
            var service = new Mock <IBudgetCashflowService>();

            service
            .Setup(s => s.GetBudgetCashflowCategories(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(new ReadResponse <BudgetCashflowCategoryModel>(new List <BudgetCashflowCategoryModel>(), 1, new Dictionary <string, string>(), new List <string>()));

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService)))
            .Returns(service.Object);

            //Act
            CashflowTypeFormDto formDto  = new CashflowTypeFormDto();
            IActionResult       response = GetController(serviceProviderMock).GetCashflowCategories(1, "", 1, 10);

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.OK, statusCode);
        }
示例#7
0
        public void PutCashflowType_Succes_OK()
        {
            //Setup
            Mock <IServiceProvider> serviceProviderMock = GetServiceProvider();
            var service = new Mock <IBudgetCashflowService>();

            service
            .Setup(s => s.UpdateBudgetCashflowType(It.IsAny <int>(), It.IsAny <CashflowTypeFormDto>()))
            .Returns(1);

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService)))
            .Returns(service.Object);

            //Act
            CashflowTypeFormDto formDto  = new CashflowTypeFormDto();
            IActionResult       response = GetController(serviceProviderMock).PutCashflowType(1, formDto);

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.NoContent, statusCode);
        }
示例#8
0
        public IActionResult PutCashflowType([FromRoute] int id, [FromBody] CashflowTypeFormDto form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);

                _service.UpdateBudgetCashflowType(id, form);

                return(NoContent());
            }
            catch (ServiceValidationException e)
            {
                var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }