public void GetCashflowSubCategoryById_Success_Return_OK() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IBudgetCashflowService>(); var model = new BudgetCashflowSubCategoryModel("", 1, 1, new List <int>() { 1 }, true, new ReportType(), false); service .Setup(s => s.GetBudgetCashflowSubCategoryById(It.IsAny <int>())) .Returns(new BudgetCashflowSubCategoryTypeDto(model)); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService))) .Returns(service.Object); //Act CashflowSubCategoryFormDto form = new CashflowSubCategoryFormDto(); IActionResult response = GetController(serviceProviderMock).GetCashflowSubCategoryById(1); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.OK, statusCode); }
public IActionResult PostCashflowSubCategory([FromBody] CashflowSubCategoryFormDto form) { try { VerifyUser(); _validateService.Validate(form); var id = _service.CreateBudgetCashflowSubCategory(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)); } }
public void Get_Success_Return_OK() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IBudgetCashflowService>(); service .Setup(s => s.GetBudgetCashflowMasterLayout(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(new ReadResponse <BudgetCashflowMasterDto>(new List <BudgetCashflowMasterDto>(), 1, new Dictionary <string, string>(), new List <string>())); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService))) .Returns(service.Object); //Act CashflowSubCategoryFormDto form = new CashflowSubCategoryFormDto(); IActionResult response = GetController(serviceProviderMock).Get("", 1, 10); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.OK, statusCode); }
public void GetCashflowSubCategoryById_Success_Return_InternalServerError() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IBudgetCashflowService>(); service .Setup(s => s.GetBudgetCashflowSubCategoryById(It.IsAny <int>())) .Throws(new Exception()); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService))) .Returns(service.Object); //Act CashflowSubCategoryFormDto form = new CashflowSubCategoryFormDto(); IActionResult response = GetController(serviceProviderMock).GetCashflowSubCategoryById(1); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode); }
public void DeleteCashflowSubCategory_Success_Return_NoContent() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IBudgetCashflowService>(); service .Setup(s => s.DeleteBudgetCashflowSubCategories(It.IsAny <int>())) .Returns(1); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService))) .Returns(service.Object); //Act CashflowSubCategoryFormDto form = new CashflowSubCategoryFormDto(); IActionResult response = GetController(serviceProviderMock).DeleteCashflowSubCategory(1); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.NoContent, statusCode); }
public void PostCashflowSubCategory_Return_Create() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IBudgetCashflowService>(); service .Setup(s => s.CreateBudgetCashflowSubCategory(It.IsAny <CashflowSubCategoryFormDto>())) .Returns(1); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService))) .Returns(service.Object); //Act CashflowSubCategoryFormDto formDto = new CashflowSubCategoryFormDto(); IActionResult response = GetController(serviceProviderMock).PostCashflowSubCategory(formDto); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.Created, statusCode); }
public IActionResult PutCashflowSubCategories([FromRoute] int id, [FromBody] CashflowSubCategoryFormDto form) { try { VerifyUser(); _validateService.Validate(form); _service.UpdateBudgetCashflowSubCategory(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)); } }
public void PutCashflowSubCategories_Throws_ValidationException() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IBudgetCashflowService>(); CashflowSubCategoryFormDto form = new CashflowSubCategoryFormDto(); service .Setup(s => s.UpdateBudgetCashflowSubCategory(It.IsAny <int>(), It.IsAny <CashflowSubCategoryFormDto>())) .Throws(GetServiceValidationException(form)); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IBudgetCashflowService))) .Returns(service.Object); //Act IActionResult response = GetController(serviceProviderMock).PutCashflowSubCategories(1, form); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.BadRequest, statusCode); }