public virtual ApiSalesTaxRateResponseModel MapBOToModel( BOSalesTaxRate boSalesTaxRate) { var model = new ApiSalesTaxRateResponseModel(); model.SetProperties(boSalesTaxRate.SalesTaxRateID, boSalesTaxRate.ModifiedDate, boSalesTaxRate.Name, boSalesTaxRate.Rowguid, boSalesTaxRate.StateProvinceID, boSalesTaxRate.TaxRate, boSalesTaxRate.TaxType); return(model); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiSalesTaxRateResponseModel response = await client.SalesTaxRateGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiSalesTaxRateResponseModel response = await this.SalesTaxRateService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByStateProvinceIDTaxType(int stateProvinceID, int taxType) { ApiSalesTaxRateResponseModel response = await this.SalesTaxRateService.ByStateProvinceIDTaxType(stateProvinceID, taxType); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiSalesTaxRateModelMapper(); var model = new ApiSalesTaxRateResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1m, 1); ApiSalesTaxRateRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.StateProvinceID.Should().Be(1); response.TaxRate.Should().Be(1m); response.TaxType.Should().Be(1); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ISalesTaxRateRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <SalesTaxRate>(null)); var service = new SalesTaxRateService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SalesTaxRateModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSalesTaxRateMapperMock, mock.DALMapperMockFactory.DALSalesTaxRateMapperMock); ApiSalesTaxRateResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public void MapBOToModel() { var mapper = new BOLSalesTaxRateMapper(); BOSalesTaxRate bo = new BOSalesTaxRate(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1m, 1); ApiSalesTaxRateResponseModel response = mapper.MapBOToModel(bo); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.SalesTaxRateID.Should().Be(1); response.StateProvinceID.Should().Be(1); response.TaxRate.Should().Be(1m); response.TaxType.Should().Be(1); }
public async void ByStateProvinceIDTaxType_Exists() { var mock = new ServiceMockFacade <ISalesTaxRateRepository>(); var record = new SalesTaxRate(); mock.RepositoryMock.Setup(x => x.ByStateProvinceIDTaxType(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new SalesTaxRateService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SalesTaxRateModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSalesTaxRateMapperMock, mock.DALMapperMockFactory.DALSalesTaxRateMapperMock); ApiSalesTaxRateResponseModel response = await service.ByStateProvinceIDTaxType(default(int), default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.ByStateProvinceIDTaxType(It.IsAny <int>(), It.IsAny <int>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiSalesTaxRateResponseModel model = await client.SalesTaxRateGetAsync(1); ApiSalesTaxRateModelMapper mapper = new ApiSalesTaxRateModelMapper(); UpdateResponse <ApiSalesTaxRateResponseModel> updateResponse = await client.SalesTaxRateUpdateAsync(model.SalesTaxRateID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { SalesTaxRateControllerMockFacade mock = new SalesTaxRateControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiSalesTaxRateResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiSalesTaxRateResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSalesTaxRateRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSalesTaxRateResponseModel> >(mockResponse.Object)); SalesTaxRateController controller = new SalesTaxRateController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiSalesTaxRateRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSalesTaxRateRequestModel>())); }
public async void All_Exists() { SalesTaxRateControllerMockFacade mock = new SalesTaxRateControllerMockFacade(); var record = new ApiSalesTaxRateResponseModel(); var records = new List <ApiSalesTaxRateResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); SalesTaxRateController controller = new SalesTaxRateController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiSalesTaxRateResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSalesTaxRateRequestModel> patch) { ApiSalesTaxRateResponseModel record = await this.SalesTaxRateService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSalesTaxRateRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSalesTaxRateResponseModel> result = await this.SalesTaxRateService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiSalesTaxRateResponseModel response = await this.Client.SalesTaxRateGetAsync(1); response.Should().NotBeNull(); }