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 ApiTagRequestModel(); createModel.SetProperties(2, 2, "B", 2); CreateResponse <ApiTagResponseModel> createResult = await client.TagCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTagResponseModel getResponse = await client.TagGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TagDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTagResponseModel verifyResponse = await client.TagGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTagRequestModel model) { this.CountRules(); this.ExcerptPostIdRules(); this.TagNameRules(); this.WikiPostIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiTagResponseModel> CreateRecord(ApiClient client) { var model = new ApiTagRequestModel(); model.SetProperties(2, 2, "B", 2); CreateResponse <ApiTagResponseModel> result = await client.TagCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiTagModelMapper(); var model = new ApiTagResponseModel(); model.SetProperties(1, 1, 1, "A", 1); ApiTagRequestModel response = mapper.MapResponseToRequest(model); response.Count.Should().Be(1); response.ExcerptPostId.Should().Be(1); response.TagName.Should().Be("A"); response.WikiPostId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiTagRequestModel model) { CreateResponse <ApiTagResponseModel> result = await this.TagService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Tags/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLTagMapper(); ApiTagRequestModel model = new ApiTagRequestModel(); model.SetProperties(1, 1, "A", 1); BOTag response = mapper.MapModelToBO(1, model); response.Count.Should().Be(1); response.ExcerptPostId.Should().Be(1); response.TagName.Should().Be("A"); response.WikiPostId.Should().Be(1); }
public virtual BOTag MapModelToBO( int id, ApiTagRequestModel model ) { BOTag boTag = new BOTag(); boTag.SetProperties( id, model.Count, model.ExcerptPostId, model.TagName, model.WikiPostId); return(boTag); }
public virtual async Task <CreateResponse <ApiTagResponseModel> > Create( ApiTagRequestModel model) { CreateResponse <ApiTagResponseModel> response = new CreateResponse <ApiTagResponseModel>(await this.TagModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolTagMapper.MapModelToBO(default(int), model); var record = await this.TagRepository.Create(this.DalTagMapper.MapBOToEF(bo)); response.SetRecord(this.BolTagMapper.MapBOToModel(this.DalTagMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiTagRequestModel> PatchModel(int id, JsonPatchDocument <ApiTagRequestModel> patch) { var record = await this.TagService.Get(id); if (record == null) { return(null); } else { ApiTagRequestModel request = this.TagModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiTagModelMapper(); var model = new ApiTagRequestModel(); model.SetProperties(1, 1, "A", 1); JsonPatchDocument <ApiTagRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTagRequestModel(); patch.ApplyTo(response); response.Count.Should().Be(1); response.ExcerptPostId.Should().Be(1); response.TagName.Should().Be("A"); response.WikiPostId.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <ITagRepository>(); var model = new ApiTagRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Tag>())).Returns(Task.FromResult(new Tag())); var service = new TagService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TagModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTagMapperMock, mock.DALMapperMockFactory.DALTagMapperMock); CreateResponse <ApiTagResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TagModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTagRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Tag>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITagRepository>(); var model = new ApiTagRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TagService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TagModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTagMapperMock, mock.DALMapperMockFactory.DALTagMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TagModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiTagResponseModel> > Update( int id, ApiTagRequestModel model) { var validationResult = await this.TagModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolTagMapper.MapModelToBO(id, model); await this.TagRepository.Update(this.DalTagMapper.MapBOToEF(bo)); var record = await this.TagRepository.Get(id); return(new UpdateResponse <ApiTagResponseModel>(this.BolTagMapper.MapBOToModel(this.DalTagMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTagResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTagRequestModel model) { ApiTagRequestModel request = await this.PatchModel(id, this.TagModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTagResponseModel> result = await this.TagService.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 <ApiTagRequestModel> patch) { ApiTagResponseModel record = await this.TagService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTagRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTagResponseModel> result = await this.TagService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiTagResponseModel> > TagUpdateAsync(int id, ApiTagRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Tags/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiTagResponseModel> >(httpResponse.Content.ContentToString())); }