public virtual ApiConfigurationResponseModel MapBOToModel( BOConfiguration boConfiguration) { var model = new ApiConfigurationResponseModel(); model.SetProperties(boConfiguration.Id, boConfiguration.JSON); return(model); }
public void MapResponseToRequest() { var mapper = new ApiConfigurationModelMapper(); var model = new ApiConfigurationResponseModel(); model.SetProperties("A", "A"); ApiConfigurationRequestModel response = mapper.MapResponseToRequest(model); response.JSON.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLConfigurationMapper(); BOConfiguration bo = new BOConfiguration(); bo.SetProperties("A", "A"); ApiConfigurationResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be("A"); response.JSON.Should().Be("A"); }
public async virtual Task <IActionResult> Get(string id) { ApiConfigurationResponseModel response = await this.ConfigurationService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IConfigurationRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Configuration>(null)); var service = new ConfigurationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ConfigurationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLConfigurationMapperMock, mock.DALMapperMockFactory.DALConfigurationMapperMock); ApiConfigurationResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public async void Create_Errors() { ConfigurationControllerMockFacade mock = new ConfigurationControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiConfigurationResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiConfigurationResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiConfigurationRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiConfigurationResponseModel> >(mockResponse.Object)); ConfigurationController controller = new ConfigurationController(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 ApiConfigurationRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiConfigurationRequestModel>())); }
public async void All_Exists() { ConfigurationControllerMockFacade mock = new ConfigurationControllerMockFacade(); var record = new ApiConfigurationResponseModel(); var records = new List <ApiConfigurationResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ConfigurationController controller = new ConfigurationController(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 <ApiConfigurationResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiConfigurationRequestModel> patch) { ApiConfigurationResponseModel record = await this.ConfigurationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiConfigurationRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiConfigurationResponseModel> result = await this.ConfigurationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiConfigurationResponseModel response = await this.Client.ConfigurationGetAsync("A"); response.Should().NotBeNull(); }