Exemple #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTagsRequestModel model)
 {
     this.CountRules();
     this.ExcerptPostIdRules();
     this.TagNameRules();
     this.WikiPostIdRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiTagsResponseModel> CreateRecord()
        {
            var model = new ApiTagsRequestModel();

            model.SetProperties(2, 2, "B", 2);
            CreateResponse <ApiTagsResponseModel> result = await this.Client.TagsCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapModelToBO()
        {
            var mapper = new BOLTagsMapper();
            ApiTagsRequestModel model = new ApiTagsRequestModel();

            model.SetProperties(1, 1, "A", 1);
            BOTags 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 void MapResponseToRequest()
        {
            var mapper = new ApiTagsModelMapper();
            var model  = new ApiTagsResponseModel();

            model.SetProperties(1, 1, 1, "A", 1);
            ApiTagsRequestModel response = mapper.MapResponseToRequest(model);

            response.Count.Should().Be(1);
            response.ExcerptPostId.Should().Be(1);
            response.TagName.Should().Be("A");
            response.WikiPostId.Should().Be(1);
        }
Exemple #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiTagsRequestModel model)
        {
            CreateResponse <ApiTagsResponseModel> result = await this.TagsService.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 virtual BOTags MapModelToBO(
            int id,
            ApiTagsRequestModel model
            )
        {
            BOTags boTags = new BOTags();

            boTags.SetProperties(
                id,
                model.Count,
                model.ExcerptPostId,
                model.TagName,
                model.WikiPostId);
            return(boTags);
        }
        public virtual async Task <CreateResponse <ApiTagsResponseModel> > Create(
            ApiTagsRequestModel model)
        {
            CreateResponse <ApiTagsResponseModel> response = new CreateResponse <ApiTagsResponseModel>(await this.tagsModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolTagsMapper.MapModelToBO(default(int), model);
                var record = await this.tagsRepository.Create(this.dalTagsMapper.MapBOToEF(bo));

                response.SetRecord(this.bolTagsMapper.MapBOToModel(this.dalTagsMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemple #8
0
        private async Task <ApiTagsRequestModel> PatchModel(int id, JsonPatchDocument <ApiTagsRequestModel> patch)
        {
            var record = await this.TagsService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTagsRequestModel request = this.TagsModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiTagsModelMapper();
            var model  = new ApiTagsRequestModel();

            model.SetProperties(1, 1, "A", 1);

            JsonPatchDocument <ApiTagsRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiTagsRequestModel();

            patch.ApplyTo(response);
            response.Count.Should().Be(1);
            response.ExcerptPostId.Should().Be(1);
            response.TagName.Should().Be("A");
            response.WikiPostId.Should().Be(1);
        }
Exemple #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITagsRepository>();
            var model = new ApiTagsRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Tags>())).Returns(Task.FromResult(new Tags()));
            var service = new TagsService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.TagsModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLTagsMapperMock,
                                          mock.DALMapperMockFactory.DALTagsMapperMock);

            CreateResponse <ApiTagsResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TagsModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTagsRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Tags>()));
        }
Exemple #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITagsRepository>();
            var model = new ApiTagsRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new TagsService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.TagsModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLTagsMapperMock,
                                          mock.DALMapperMockFactory.DALTagsMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TagsModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <UpdateResponse <ApiTagsResponseModel> > Update(
            int id,
            ApiTagsRequestModel model)
        {
            var validationResult = await this.tagsModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolTagsMapper.MapModelToBO(id, model);
                await this.tagsRepository.Update(this.dalTagsMapper.MapBOToEF(bo));

                var record = await this.tagsRepository.Get(id);

                return(new UpdateResponse <ApiTagsResponseModel>(this.bolTagsMapper.MapBOToModel(this.dalTagsMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTagsResponseModel>(validationResult));
            }
        }
Exemple #13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTagsRequestModel model)
        {
            ApiTagsRequestModel request = await this.PatchModel(id, this.TagsModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiTagsResponseModel> result = await this.TagsService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemple #14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTagsRequestModel> patch)
        {
            ApiTagsResponseModel record = await this.TagsService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiTagsRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiTagsResponseModel> result = await this.TagsService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <UpdateResponse <ApiTagsResponseModel> > TagsUpdateAsync(int id, ApiTagsRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Tags/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiTagsResponseModel> >(httpResponse.Content.ContentToString()));
        }