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 ApiSpeciesRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiSpeciesResponseModel> createResult = await client.SpeciesCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiSpeciesResponseModel getResponse = await client.SpeciesGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.SpeciesDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiSpeciesResponseModel verifyResponse = await client.SpeciesGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiSpeciesResponseModel MapBOToModel( BOSpecies boSpecies) { var model = new ApiSpeciesResponseModel(); model.SetProperties(boSpecies.Id, boSpecies.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiSpeciesModelMapper(); var model = new ApiSpeciesResponseModel(); model.SetProperties(1, "A"); ApiSpeciesRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLSpeciesMapper(); BOSpecies bo = new BOSpecies(); bo.SetProperties(1, "A"); ApiSpeciesResponseModel 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()); ApiSpeciesResponseModel response = await client.SpeciesGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiSpeciesResponseModel response = await this.SpeciesService.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 <ISpeciesRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Species>(null)); var service = new SpeciesService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSpeciesMapperMock, mock.DALMapperMockFactory.DALSpeciesMapperMock, mock.BOLMapperMockFactory.BOLBreedMapperMock, mock.DALMapperMockFactory.DALBreedMapperMock); ApiSpeciesResponseModel 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()); ApiSpeciesResponseModel model = await client.SpeciesGetAsync(1); ApiSpeciesModelMapper mapper = new ApiSpeciesModelMapper(); UpdateResponse <ApiSpeciesResponseModel> updateResponse = await client.SpeciesUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { SpeciesControllerMockFacade mock = new SpeciesControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiSpeciesResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiSpeciesResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSpeciesRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSpeciesResponseModel> >(mockResponse.Object)); SpeciesController controller = new SpeciesController(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 ApiSpeciesRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSpeciesRequestModel>())); }
public async void All_Exists() { SpeciesControllerMockFacade mock = new SpeciesControllerMockFacade(); var record = new ApiSpeciesResponseModel(); var records = new List <ApiSpeciesResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); SpeciesController controller = new SpeciesController(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 <ApiSpeciesResponseModel>; 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 <ApiSpeciesRequestModel> patch) { ApiSpeciesResponseModel record = await this.SpeciesService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSpeciesRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSpeciesResponseModel> result = await this.SpeciesService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiSpeciesResponseModel response = await this.Client.SpeciesGetAsync(1); response.Should().NotBeNull(); }