public virtual ApiProductSubcategoryResponseModel MapBOToModel( BOProductSubcategory boProductSubcategory) { var model = new ApiProductSubcategoryResponseModel(); model.SetProperties(boProductSubcategory.ProductSubcategoryID, boProductSubcategory.ModifiedDate, boProductSubcategory.Name, boProductSubcategory.ProductCategoryID, boProductSubcategory.Rowguid); 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()); ApiProductSubcategoryResponseModel response = await client.ProductSubcategoryGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiProductSubcategoryResponseModel response = await this.ProductSubcategoryService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiProductSubcategoryModelMapper(); var model = new ApiProductSubcategoryResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiProductSubcategoryRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.ProductCategoryID.Should().Be(1); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public void MapBOToModel() { var mapper = new BOLProductSubcategoryMapper(); BOProductSubcategory bo = new BOProductSubcategory(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiProductSubcategoryResponseModel response = mapper.MapBOToModel(bo); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.ProductCategoryID.Should().Be(1); response.ProductSubcategoryID.Should().Be(1); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IProductSubcategoryRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ProductSubcategory>(null)); var service = new ProductSubcategoryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductSubcategoryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock, mock.DALMapperMockFactory.DALProductSubcategoryMapperMock, mock.BOLMapperMockFactory.BOLProductMapperMock, mock.DALMapperMockFactory.DALProductMapperMock); ApiProductSubcategoryResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(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()); ApiProductSubcategoryResponseModel model = await client.ProductSubcategoryGetAsync(1); ApiProductSubcategoryModelMapper mapper = new ApiProductSubcategoryModelMapper(); UpdateResponse <ApiProductSubcategoryResponseModel> updateResponse = await client.ProductSubcategoryUpdateAsync(model.ProductSubcategoryID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void ByName_Exists() { var mock = new ServiceMockFacade <IProductSubcategoryRepository>(); var record = new ProductSubcategory(); mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record)); var service = new ProductSubcategoryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductSubcategoryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock, mock.DALMapperMockFactory.DALProductSubcategoryMapperMock, mock.BOLMapperMockFactory.BOLProductMapperMock, mock.DALMapperMockFactory.DALProductMapperMock); ApiProductSubcategoryResponseModel response = await service.ByName(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>())); }
public async void Create_Errors() { ProductSubcategoryControllerMockFacade mock = new ProductSubcategoryControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiProductSubcategoryResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiProductSubcategoryResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiProductSubcategoryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiProductSubcategoryResponseModel> >(mockResponse.Object)); ProductSubcategoryController controller = new ProductSubcategoryController(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 ApiProductSubcategoryRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiProductSubcategoryRequestModel>())); }
public async void All_Exists() { ProductSubcategoryControllerMockFacade mock = new ProductSubcategoryControllerMockFacade(); var record = new ApiProductSubcategoryResponseModel(); var records = new List <ApiProductSubcategoryResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ProductSubcategoryController controller = new ProductSubcategoryController(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 <ApiProductSubcategoryResponseModel>; 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 <ApiProductSubcategoryRequestModel> patch) { ApiProductSubcategoryResponseModel record = await this.ProductSubcategoryService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiProductSubcategoryRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiProductSubcategoryResponseModel> result = await this.ProductSubcategoryService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiProductSubcategoryResponseModel response = await this.Client.ProductSubcategoryGetAsync(1); response.Should().NotBeNull(); }