public IActionResult PostCustoms([FromBody] CustomsFormDto form) { try { VerifyUser(); var id = _service.CreateFromCustoms(form); var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(Created(string.Concat(Request.Path, "/", id), 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 PostCustoms_Succes_Created() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IGarmentDebtBalanceService>(); service .Setup(s => s.CreateFromCustoms(It.IsAny <CustomsFormDto>())) .Returns(1); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IGarmentDebtBalanceService))) .Returns(service.Object); //Act CustomsFormDto form = new CustomsFormDto(); IActionResult response = GetController(serviceProviderMock).PostCustoms(form); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.Created, statusCode); }