public virtual ApiBillOfMaterialResponseModel MapBOToModel( BOBillOfMaterial boBillOfMaterial) { var model = new ApiBillOfMaterialResponseModel(); model.SetProperties(boBillOfMaterial.BillOfMaterialsID, boBillOfMaterial.BOMLevel, boBillOfMaterial.ComponentID, boBillOfMaterial.EndDate, boBillOfMaterial.ModifiedDate, boBillOfMaterial.PerAssemblyQty, boBillOfMaterial.ProductAssemblyID, boBillOfMaterial.StartDate, boBillOfMaterial.UnitMeasureCode); 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()); ApiBillOfMaterialResponseModel response = await client.BillOfMaterialGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiBillOfMaterialResponseModel response = await this.BillOfMaterialService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByProductAssemblyIDComponentIDStartDate(int?productAssemblyID, int componentID, DateTime startDate) { ApiBillOfMaterialResponseModel response = await this.BillOfMaterialService.ByProductAssemblyIDComponentIDStartDate(productAssemblyID, componentID, startDate); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IBillOfMaterialRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <BillOfMaterial>(null)); var service = new BillOfMaterialService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BillOfMaterialModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBillOfMaterialMapperMock, mock.DALMapperMockFactory.DALBillOfMaterialMapperMock); ApiBillOfMaterialResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ByProductAssemblyIDComponentIDStartDate_Not_Exists() { var mock = new ServiceMockFacade <IBillOfMaterialRepository>(); mock.RepositoryMock.Setup(x => x.ByProductAssemblyIDComponentIDStartDate(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <DateTime>())).Returns(Task.FromResult <BillOfMaterial>(null)); var service = new BillOfMaterialService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BillOfMaterialModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBillOfMaterialMapperMock, mock.DALMapperMockFactory.DALBillOfMaterialMapperMock); ApiBillOfMaterialResponseModel response = await service.ByProductAssemblyIDComponentIDStartDate(default(int?), default(int), default(DateTime)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.ByProductAssemblyIDComponentIDStartDate(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <DateTime>())); }
public void MapResponseToRequest() { var mapper = new ApiBillOfMaterialModelMapper(); var model = new ApiBillOfMaterialResponseModel(); model.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiBillOfMaterialRequestModel response = mapper.MapResponseToRequest(model); response.BOMLevel.Should().Be(1); response.ComponentID.Should().Be(1); response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PerAssemblyQty.Should().Be(1); response.ProductAssemblyID.Should().Be(1); response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.UnitMeasureCode.Should().Be("A"); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiBillOfMaterialResponseModel model = await client.BillOfMaterialGetAsync(1); ApiBillOfMaterialModelMapper mapper = new ApiBillOfMaterialModelMapper(); UpdateResponse <ApiBillOfMaterialResponseModel> updateResponse = await client.BillOfMaterialUpdateAsync(model.BillOfMaterialsID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public void MapBOToModel() { var mapper = new BOLBillOfMaterialMapper(); BOBillOfMaterial bo = new BOBillOfMaterial(); bo.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiBillOfMaterialResponseModel response = mapper.MapBOToModel(bo); response.BillOfMaterialsID.Should().Be(1); response.BOMLevel.Should().Be(1); response.ComponentID.Should().Be(1); response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PerAssemblyQty.Should().Be(1); response.ProductAssemblyID.Should().Be(1); response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.UnitMeasureCode.Should().Be("A"); }
public async void Create_Errors() { BillOfMaterialControllerMockFacade mock = new BillOfMaterialControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiBillOfMaterialResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiBillOfMaterialResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBillOfMaterialRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBillOfMaterialResponseModel> >(mockResponse.Object)); BillOfMaterialController controller = new BillOfMaterialController(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 ApiBillOfMaterialRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBillOfMaterialRequestModel>())); }
public async void All_Exists() { BillOfMaterialControllerMockFacade mock = new BillOfMaterialControllerMockFacade(); var record = new ApiBillOfMaterialResponseModel(); var records = new List <ApiBillOfMaterialResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); BillOfMaterialController controller = new BillOfMaterialController(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 <ApiBillOfMaterialResponseModel>; 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 <ApiBillOfMaterialRequestModel> patch) { ApiBillOfMaterialResponseModel record = await this.BillOfMaterialService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBillOfMaterialRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBillOfMaterialResponseModel> result = await this.BillOfMaterialService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiBillOfMaterialResponseModel response = await this.Client.BillOfMaterialGetAsync(1); response.Should().NotBeNull(); }