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 ApiVoteRequestModel(); createModel.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2); CreateResponse <ApiVoteResponseModel> createResult = await client.VoteCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiVoteResponseModel getResponse = await client.VoteGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.VoteDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiVoteResponseModel verifyResponse = await client.VoteGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiVoteRequestModel model) { this.BountyAmountRules(); this.CreationDateRules(); this.PostIdRules(); this.UserIdRules(); this.VoteTypeIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiVoteResponseModel> CreateRecord(ApiClient client) { var model = new ApiVoteRequestModel(); model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2); CreateResponse <ApiVoteResponseModel> result = await client.VoteCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiVoteRequestModel model) { CreateResponse <ApiVoteResponseModel> result = await this.VoteService.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 ApiVoteModelMapper(); var model = new ApiVoteResponseModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiVoteRequestModel 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 <ApiVoteResponseModel> > Create( ApiVoteRequestModel model) { CreateResponse <ApiVoteResponseModel> response = new CreateResponse <ApiVoteResponseModel>(await this.VoteModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolVoteMapper.MapModelToBO(default(int), model); var record = await this.VoteRepository.Create(this.DalVoteMapper.MapBOToEF(bo)); response.SetRecord(this.BolVoteMapper.MapBOToModel(this.DalVoteMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiVoteRequestModel> PatchModel(int id, JsonPatchDocument <ApiVoteRequestModel> patch) { var record = await this.VoteService.Get(id); if (record == null) { return(null); } else { ApiVoteRequestModel request = this.VoteModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOVote MapModelToBO( int id, ApiVoteRequestModel model ) { BOVote boVote = new BOVote(); boVote.SetProperties( id, model.BountyAmount, model.CreationDate, model.PostId, model.UserId, model.VoteTypeId); return(boVote); }
public void CreatePatch() { var mapper = new ApiVoteModelMapper(); var model = new ApiVoteRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); JsonPatchDocument <ApiVoteRequestModel> patch = mapper.CreatePatch(model); var response = new ApiVoteRequestModel(); 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 <IVoteRepository>(); var model = new ApiVoteRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Vote>())).Returns(Task.FromResult(new Vote())); var service = new VoteService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VoteModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVoteMapperMock, mock.DALMapperMockFactory.DALVoteMapperMock); CreateResponse <ApiVoteResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.VoteModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVoteRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Vote>())); }
public async void Delete() { var mock = new ServiceMockFacade <IVoteRepository>(); var model = new ApiVoteRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new VoteService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VoteModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVoteMapperMock, mock.DALMapperMockFactory.DALVoteMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.VoteModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiVoteResponseModel> > Update( int id, ApiVoteRequestModel model) { var validationResult = await this.VoteModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolVoteMapper.MapModelToBO(id, model); await this.VoteRepository.Update(this.DalVoteMapper.MapBOToEF(bo)); var record = await this.VoteRepository.Get(id); return(new UpdateResponse <ApiVoteResponseModel>(this.BolVoteMapper.MapBOToModel(this.DalVoteMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiVoteResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiVoteRequestModel model) { ApiVoteRequestModel request = await this.PatchModel(id, this.VoteModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiVoteResponseModel> result = await this.VoteService.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 <ApiVoteRequestModel> patch) { ApiVoteResponseModel record = await this.VoteService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiVoteRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiVoteResponseModel> result = await this.VoteService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiVoteResponseModel> > VoteUpdateAsync(int id, ApiVoteRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Votes/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiVoteResponseModel> >(httpResponse.Content.ContentToString())); }