public virtual ApiErrorLogResponseModel MapBOToModel( BOErrorLog boErrorLog) { var model = new ApiErrorLogResponseModel(); model.SetProperties(boErrorLog.ErrorLogID, boErrorLog.ErrorLine, boErrorLog.ErrorMessage, boErrorLog.ErrorNumber, boErrorLog.ErrorProcedure, boErrorLog.ErrorSeverity, boErrorLog.ErrorState, boErrorLog.ErrorTime, boErrorLog.UserName); 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()); ApiErrorLogResponseModel response = await client.ErrorLogGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiErrorLogResponseModel response = await this.ErrorLogService.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 <IErrorLogRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ErrorLog>(null)); var service = new ErrorLogService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ErrorLogModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLErrorLogMapperMock, mock.DALMapperMockFactory.DALErrorLogMapperMock); ApiErrorLogResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public void MapResponseToRequest() { var mapper = new ApiErrorLogModelMapper(); var model = new ApiErrorLogResponseModel(); model.SetProperties(1, 1, "A", 1, "A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiErrorLogRequestModel response = mapper.MapResponseToRequest(model); response.ErrorLine.Should().Be(1); response.ErrorMessage.Should().Be("A"); response.ErrorNumber.Should().Be(1); response.ErrorProcedure.Should().Be("A"); response.ErrorSeverity.Should().Be(1); response.ErrorState.Should().Be(1); response.ErrorTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.UserName.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLErrorLogMapper(); BOErrorLog bo = new BOErrorLog(); bo.SetProperties(1, 1, "A", 1, "A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiErrorLogResponseModel response = mapper.MapBOToModel(bo); response.ErrorLine.Should().Be(1); response.ErrorLogID.Should().Be(1); response.ErrorMessage.Should().Be("A"); response.ErrorNumber.Should().Be(1); response.ErrorProcedure.Should().Be("A"); response.ErrorSeverity.Should().Be(1); response.ErrorState.Should().Be(1); response.ErrorTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.UserName.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()); ApiErrorLogResponseModel model = await client.ErrorLogGetAsync(1); ApiErrorLogModelMapper mapper = new ApiErrorLogModelMapper(); UpdateResponse <ApiErrorLogResponseModel> updateResponse = await client.ErrorLogUpdateAsync(model.ErrorLogID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { ErrorLogControllerMockFacade mock = new ErrorLogControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiErrorLogResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiErrorLogResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiErrorLogRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiErrorLogResponseModel> >(mockResponse.Object)); ErrorLogController controller = new ErrorLogController(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 ApiErrorLogRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiErrorLogRequestModel>())); }
public async void All_Exists() { ErrorLogControllerMockFacade mock = new ErrorLogControllerMockFacade(); var record = new ApiErrorLogResponseModel(); var records = new List <ApiErrorLogResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ErrorLogController controller = new ErrorLogController(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 <ApiErrorLogResponseModel>; 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 <ApiErrorLogRequestModel> patch) { ApiErrorLogResponseModel record = await this.ErrorLogService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiErrorLogRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiErrorLogResponseModel> result = await this.ErrorLogService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiErrorLogResponseModel response = await this.Client.ErrorLogGetAsync(1); response.Should().NotBeNull(); }