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(); }
private async Task <ApiSpeciesResponseModel> CreateRecord() { var model = new ApiSpeciesRequestModel(); model.SetProperties("B"); CreateResponse <ApiSpeciesResponseModel> result = await this.Client.SpeciesCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
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 MapModelToBO() { var mapper = new BOLSpeciesMapper(); ApiSpeciesRequestModel model = new ApiSpeciesRequestModel(); model.SetProperties("A"); BOSpecies response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); }
public virtual BOSpecies MapModelToBO( int id, ApiSpeciesRequestModel model ) { BOSpecies boSpecies = new BOSpecies(); boSpecies.SetProperties( id, model.Name); return(boSpecies); }
public virtual async Task <IActionResult> Create([FromBody] ApiSpeciesRequestModel model) { CreateResponse <ApiSpeciesResponseModel> result = await this.SpeciesService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Species/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiSpeciesModelMapper(); var model = new ApiSpeciesRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiSpeciesRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSpeciesRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
private async Task <ApiSpeciesRequestModel> PatchModel(int id, JsonPatchDocument <ApiSpeciesRequestModel> patch) { var record = await this.SpeciesService.Get(id); if (record == null) { return(null); } else { ApiSpeciesRequestModel request = this.SpeciesModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiSpeciesResponseModel> > Create( ApiSpeciesRequestModel model) { CreateResponse <ApiSpeciesResponseModel> response = new CreateResponse <ApiSpeciesResponseModel>(await this.speciesModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolSpeciesMapper.MapModelToBO(default(int), model); var record = await this.speciesRepository.Create(this.dalSpeciesMapper.MapBOToEF(bo)); response.SetRecord(this.bolSpeciesMapper.MapBOToModel(this.dalSpeciesMapper.MapEFToBO(record))); } return(response); }
public virtual async Task <UpdateResponse <ApiSpeciesResponseModel> > Update( int id, ApiSpeciesRequestModel model) { var validationResult = await this.speciesModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolSpeciesMapper.MapModelToBO(id, model); await this.speciesRepository.Update(this.dalSpeciesMapper.MapBOToEF(bo)); var record = await this.speciesRepository.Get(id); return(new UpdateResponse <ApiSpeciesResponseModel>(this.bolSpeciesMapper.MapBOToModel(this.dalSpeciesMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiSpeciesResponseModel>(validationResult)); } }
public async void Create() { var mock = new ServiceMockFacade <ISpeciesRepository>(); var model = new ApiSpeciesRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Species>())).Returns(Task.FromResult(new Species())); 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); CreateResponse <ApiSpeciesResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpeciesRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Species>())); }
public async void Delete() { var mock = new ServiceMockFacade <ISpeciesRepository>(); var model = new ApiSpeciesRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); 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); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSpeciesRequestModel model) { ApiSpeciesRequestModel request = await this.PatchModel(id, this.SpeciesModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiSpeciesResponseModel> result = await this.SpeciesService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
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 Task <ValidationResult> ValidateUpdateAsync(int id, ApiSpeciesRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <UpdateResponse <ApiSpeciesResponseModel> > SpeciesUpdateAsync(int id, ApiSpeciesRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Species/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiSpeciesResponseModel> >(httpResponse.Content.ContentToString())); }