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 ApiCountryRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiCountryResponseModel> createResult = await client.CountryCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiCountryResponseModel getResponse = await client.CountryGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.CountryDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCountryResponseModel verifyResponse = await client.CountryGetAsync(2); verifyResponse.Should().BeNull(); }
public void MapResponseToRequest() { var mapper = new ApiCountryModelMapper(); var model = new ApiCountryResponseModel(); model.SetProperties(1, "A"); ApiCountryRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
private async Task <ApiCountryResponseModel> CreateRecord(ApiClient client) { var model = new ApiCountryRequestModel(); model.SetProperties("B"); CreateResponse <ApiCountryResponseModel> result = await client.CountryCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLCountryMapper(); ApiCountryRequestModel model = new ApiCountryRequestModel(); model.SetProperties("A"); BOCountry response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); }
public virtual BOCountry MapModelToBO( int id, ApiCountryRequestModel model ) { BOCountry boCountry = new BOCountry(); boCountry.SetProperties( id, model.Name); return(boCountry); }
public void CreatePatch() { var mapper = new ApiCountryModelMapper(); var model = new ApiCountryRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiCountryRequestModel> patch = mapper.CreatePatch(model); var response = new ApiCountryRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiCountryRequestModel model) { CreateResponse <ApiCountryResponseModel> result = await this.CountryService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Countries/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual async Task <CreateResponse <ApiCountryResponseModel> > Create( ApiCountryRequestModel model) { CreateResponse <ApiCountryResponseModel> response = new CreateResponse <ApiCountryResponseModel>(await this.countryModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolCountryMapper.MapModelToBO(default(int), model); var record = await this.countryRepository.Create(this.dalCountryMapper.MapBOToEF(bo)); response.SetRecord(this.bolCountryMapper.MapBOToModel(this.dalCountryMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiCountryRequestModel> PatchModel(int id, JsonPatchDocument <ApiCountryRequestModel> patch) { var record = await this.CountryService.Get(id); if (record == null) { return(null); } else { ApiCountryRequestModel request = this.CountryModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Delete() { var mock = new ServiceMockFacade <ICountryRepository>(); var model = new ApiCountryRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new CountryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCountryMapperMock, mock.DALMapperMockFactory.DALCountryMapperMock, mock.BOLMapperMockFactory.BOLProvinceMapperMock, mock.DALMapperMockFactory.DALProvinceMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.CountryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Create() { var mock = new ServiceMockFacade <ICountryRepository>(); var model = new ApiCountryRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Country>())).Returns(Task.FromResult(new Country())); var service = new CountryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCountryMapperMock, mock.DALMapperMockFactory.DALCountryMapperMock, mock.BOLMapperMockFactory.BOLProvinceMapperMock, mock.DALMapperMockFactory.DALProvinceMapperMock); CreateResponse <ApiCountryResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.CountryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCountryRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Country>())); }
public virtual async Task <UpdateResponse <ApiCountryResponseModel> > Update( int id, ApiCountryRequestModel model) { var validationResult = await this.countryModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolCountryMapper.MapModelToBO(id, model); await this.countryRepository.Update(this.dalCountryMapper.MapBOToEF(bo)); var record = await this.countryRepository.Get(id); return(new UpdateResponse <ApiCountryResponseModel>(this.bolCountryMapper.MapBOToModel(this.dalCountryMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiCountryResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiCountryRequestModel model) { ApiCountryRequestModel request = await this.PatchModel(id, this.CountryModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiCountryResponseModel> result = await this.CountryService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void Update() { var mock = new ServiceMockFacade <ICountryRepository>(); var model = new ApiCountryRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Country>())).Returns(Task.FromResult(new Country())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Country())); var service = new CountryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCountryMapperMock, mock.DALMapperMockFactory.DALCountryMapperMock, mock.BOLMapperMockFactory.BOLCountryRequirementMapperMock, mock.DALMapperMockFactory.DALCountryRequirementMapperMock, mock.BOLMapperMockFactory.BOLDestinationMapperMock, mock.DALMapperMockFactory.DALDestinationMapperMock); UpdateResponse <ApiCountryResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.CountryModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiCountryRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Country>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCountryRequestModel> patch) { ApiCountryResponseModel record = await this.CountryService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCountryRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCountryResponseModel> result = await this.CountryService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiCountryResponseModel> > CountryUpdateAsync(int id, ApiCountryRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Countries/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiCountryResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiCountryRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model, id)); }