public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiVotesRequestModel model) { this.BountyAmountRules(); this.CreationDateRules(); this.PostIdRules(); this.UserIdRules(); this.VoteTypeIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiVotesResponseModel> CreateRecord() { var model = new ApiVotesRequestModel(); model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2); CreateResponse <ApiVotesResponseModel> result = await this.Client.VotesCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiVotesRequestModel model) { CreateResponse <ApiVotesResponseModel> result = await this.VotesService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Votes/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapResponseToRequest() { var mapper = new ApiVotesModelMapper(); var model = new ApiVotesResponseModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiVotesRequestModel response = mapper.MapResponseToRequest(model); response.BountyAmount.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.UserId.Should().Be(1); response.VoteTypeId.Should().Be(1); }
public virtual async Task <CreateResponse <ApiVotesResponseModel> > Create( ApiVotesRequestModel model) { CreateResponse <ApiVotesResponseModel> response = new CreateResponse <ApiVotesResponseModel>(await this.votesModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolVotesMapper.MapModelToBO(default(int), model); var record = await this.votesRepository.Create(this.dalVotesMapper.MapBOToEF(bo)); response.SetRecord(this.bolVotesMapper.MapBOToModel(this.dalVotesMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiVotesRequestModel> PatchModel(int id, JsonPatchDocument <ApiVotesRequestModel> patch) { var record = await this.VotesService.Get(id); if (record == null) { return(null); } else { ApiVotesRequestModel request = this.VotesModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOVotes MapModelToBO( int id, ApiVotesRequestModel model ) { BOVotes boVotes = new BOVotes(); boVotes.SetProperties( id, model.BountyAmount, model.CreationDate, model.PostId, model.UserId, model.VoteTypeId); return(boVotes); }
public void CreatePatch() { var mapper = new ApiVotesModelMapper(); var model = new ApiVotesRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); JsonPatchDocument <ApiVotesRequestModel> patch = mapper.CreatePatch(model); var response = new ApiVotesRequestModel(); patch.ApplyTo(response); response.BountyAmount.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.UserId.Should().Be(1); response.VoteTypeId.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <IVotesRepository>(); var model = new ApiVotesRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Votes>())).Returns(Task.FromResult(new Votes())); var service = new VotesService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VotesModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVotesMapperMock, mock.DALMapperMockFactory.DALVotesMapperMock); CreateResponse <ApiVotesResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.VotesModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVotesRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Votes>())); }
public async void Delete() { var mock = new ServiceMockFacade <IVotesRepository>(); var model = new ApiVotesRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new VotesService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VotesModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVotesMapperMock, mock.DALMapperMockFactory.DALVotesMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.VotesModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiVotesResponseModel> > Update( int id, ApiVotesRequestModel model) { var validationResult = await this.votesModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolVotesMapper.MapModelToBO(id, model); await this.votesRepository.Update(this.dalVotesMapper.MapBOToEF(bo)); var record = await this.votesRepository.Get(id); return(new UpdateResponse <ApiVotesResponseModel>(this.bolVotesMapper.MapBOToModel(this.dalVotesMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiVotesResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiVotesRequestModel model) { ApiVotesRequestModel request = await this.PatchModel(id, this.VotesModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiVotesResponseModel> result = await this.VotesService.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 <ApiVotesRequestModel> patch) { ApiVotesResponseModel record = await this.VotesService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiVotesRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiVotesResponseModel> result = await this.VotesService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiVotesResponseModel> > VotesUpdateAsync(int id, ApiVotesRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Votes/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiVotesResponseModel> >(httpResponse.Content.ContentToString())); }