public async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); var createModel = new ApiFileTypeRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiFileTypeResponseModel> createResult = await client.FileTypeCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiFileTypeResponseModel getResponse = await client.FileTypeGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.FileTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiFileTypeResponseModel verifyResponse = await client.FileTypeGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiFileTypeResponseModel MapBOToModel( BOFileType boFileType) { var model = new ApiFileTypeResponseModel(); model.SetProperties(boFileType.Id, boFileType.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiFileTypeModelMapper(); var model = new ApiFileTypeResponseModel(); model.SetProperties(1, "A"); ApiFileTypeRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLFileTypeMapper(); BOFileType bo = new BOFileType(); bo.SetProperties(1, "A"); ApiFileTypeResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.Name.Should().Be("A"); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiFileTypeResponseModel response = await client.FileTypeGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiFileTypeResponseModel response = await this.FileTypeService.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 <IFileTypeRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <FileType>(null)); var service = new FileTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFileTypeMapperMock, mock.DALMapperMockFactory.DALFileTypeMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ApiFileTypeResponseModel 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()); ApiFileTypeResponseModel model = await client.FileTypeGetAsync(1); ApiFileTypeModelMapper mapper = new ApiFileTypeModelMapper(); UpdateResponse <ApiFileTypeResponseModel> updateResponse = await client.FileTypeUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { FileTypeControllerMockFacade mock = new FileTypeControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiFileTypeResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiFileTypeResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFileTypeRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFileTypeResponseModel> >(mockResponse.Object)); FileTypeController controller = new FileTypeController(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 ApiFileTypeRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiFileTypeRequestModel>())); }
public async void All_Exists() { FileTypeControllerMockFacade mock = new FileTypeControllerMockFacade(); var record = new ApiFileTypeResponseModel(); var records = new List <ApiFileTypeResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); FileTypeController controller = new FileTypeController(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 <ApiFileTypeResponseModel>; 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 <ApiFileTypeRequestModel> patch) { ApiFileTypeResponseModel record = await this.FileTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiFileTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiFileTypeResponseModel> result = await this.FileTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiFileTypeResponseModel response = await this.Client.FileTypeGetAsync(1); response.Should().NotBeNull(); }