public void MapResponseToRequest() { var mapper = new ApiPetModelMapper(); var model = new ApiPetResponseModel(); model.SetProperties(1, 1, 1, "A", 1); ApiPetRequestModel response = mapper.MapResponseToRequest(model); response.BreedId.Should().Be(1); response.ClientId.Should().Be(1); response.Name.Should().Be("A"); response.Weight.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiPetRequestModel model) { CreateResponse <ApiPetResponseModel> result = await this.PetService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Pets/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLPetMapper(); ApiPetRequestModel model = new ApiPetRequestModel(); model.SetProperties(1, 1, "A", 1); BOPet response = mapper.MapModelToBO(1, model); response.BreedId.Should().Be(1); response.ClientId.Should().Be(1); response.Name.Should().Be("A"); response.Weight.Should().Be(1); }
public virtual BOPet MapModelToBO( int id, ApiPetRequestModel model ) { BOPet boPet = new BOPet(); boPet.SetProperties( id, model.BreedId, model.ClientId, model.Name, model.Weight); return(boPet); }
public virtual async Task <CreateResponse <ApiPetResponseModel> > Create( ApiPetRequestModel model) { CreateResponse <ApiPetResponseModel> response = new CreateResponse <ApiPetResponseModel>(await this.petModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolPetMapper.MapModelToBO(default(int), model); var record = await this.petRepository.Create(this.dalPetMapper.MapBOToEF(bo)); response.SetRecord(this.bolPetMapper.MapBOToModel(this.dalPetMapper.MapEFToBO(record))); } return(response); }
public void MapResponseToRequest() { var mapper = new ApiPetModelMapper(); var model = new ApiPetResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A", 1, 1m, 1); ApiPetRequestModel response = mapper.MapResponseToRequest(model); response.AcquiredDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.BreedId.Should().Be(1); response.Description.Should().Be("A"); response.PenId.Should().Be(1); response.Price.Should().Be(1m); response.SpeciesId.Should().Be(1); }
private async Task <ApiPetRequestModel> PatchModel(int id, JsonPatchDocument <ApiPetRequestModel> patch) { var record = await this.PetService.Get(id); if (record == null) { return(null); } else { ApiPetRequestModel request = this.PetModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiPetModelMapper(); var model = new ApiPetRequestModel(); model.SetProperties(1, 1, "A", 1); JsonPatchDocument <ApiPetRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPetRequestModel(); patch.ApplyTo(response); response.BreedId.Should().Be(1); response.ClientId.Should().Be(1); response.Name.Should().Be("A"); response.Weight.Should().Be(1); }
public virtual BOPet MapModelToBO( int id, ApiPetRequestModel model ) { BOPet boPet = new BOPet(); boPet.SetProperties( id, model.AcquiredDate, model.BreedId, model.Description, model.PenId, model.Price, model.SpeciesId); return(boPet); }
public void CreatePatch() { var mapper = new ApiPetModelMapper(); var model = new ApiPetRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A", 1, 1m, 1); JsonPatchDocument <ApiPetRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPetRequestModel(); patch.ApplyTo(response); response.AcquiredDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.BreedId.Should().Be(1); response.Description.Should().Be("A"); response.PenId.Should().Be(1); response.Price.Should().Be(1m); response.SpeciesId.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <IPetRepository>(); var model = new ApiPetRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pet>())).Returns(Task.FromResult(new Pet())); var service = new PetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPetMapperMock, mock.DALMapperMockFactory.DALPetMapperMock, mock.BOLMapperMockFactory.BOLSaleMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); CreateResponse <ApiPetResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPetRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pet>())); }
public async void Delete() { var mock = new ServiceMockFacade <IPetRepository>(); var model = new ApiPetRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPetMapperMock, mock.DALMapperMockFactory.DALPetMapperMock, mock.BOLMapperMockFactory.BOLSaleMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiPetResponseModel> > Update( int id, ApiPetRequestModel model) { var validationResult = await this.petModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolPetMapper.MapModelToBO(id, model); await this.petRepository.Update(this.dalPetMapper.MapBOToEF(bo)); var record = await this.petRepository.Get(id); return(new UpdateResponse <ApiPetResponseModel>(this.bolPetMapper.MapBOToModel(this.dalPetMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiPetResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPetRequestModel model) { ApiPetRequestModel request = await this.PatchModel(id, this.PetModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPetResponseModel> result = await this.PetService.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 <ApiPetRequestModel> patch) { ApiPetResponseModel record = await this.PetService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPetRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPetResponseModel> result = await this.PetService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiPetResponseModel> > PetUpdateAsync(int id, ApiPetRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Pets/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiPetResponseModel> >(httpResponse.Content.ContentToString())); }