Ejemplo n.º 1
0
        public void MapModelToBO()
        {
            var mapper = new BOLPostTypesMapper();
            ApiPostTypesRequestModel model = new ApiPostTypesRequestModel();

            model.SetProperties("A");
            BOPostTypes response = mapper.MapModelToBO(1, model);

            response.Type.Should().Be("A");
        }
Ejemplo n.º 2
0
        private async Task <ApiPostTypesResponseModel> CreateRecord()
        {
            var model = new ApiPostTypesRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiPostTypesResponseModel> result = await this.Client.PostTypesCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Ejemplo n.º 3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiPostTypesModelMapper();
            var model  = new ApiPostTypesResponseModel();

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

            response.Type.Should().Be("A");
        }
Ejemplo n.º 4
0
        public virtual BOPostTypes MapModelToBO(
            int id,
            ApiPostTypesRequestModel model
            )
        {
            BOPostTypes boPostTypes = new BOPostTypes();

            boPostTypes.SetProperties(
                id,
                model.Type);
            return(boPostTypes);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiPostTypesRequestModel model)
        {
            CreateResponse <ApiPostTypesResponseModel> result = await this.PostTypesService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PostTypes/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Ejemplo n.º 6
0
        public void CreatePatch()
        {
            var mapper = new ApiPostTypesModelMapper();
            var model  = new ApiPostTypesRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Type.Should().Be("A");
        }
Ejemplo n.º 7
0
        public virtual async Task <CreateResponse <ApiPostTypesResponseModel> > Create(
            ApiPostTypesRequestModel model)
        {
            CreateResponse <ApiPostTypesResponseModel> response = new CreateResponse <ApiPostTypesResponseModel>(await this.postTypesModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolPostTypesMapper.MapModelToBO(default(int), model);
                var record = await this.postTypesRepository.Create(this.dalPostTypesMapper.MapBOToEF(bo));

                response.SetRecord(this.bolPostTypesMapper.MapBOToModel(this.dalPostTypesMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiPostTypesRequestModel> PatchModel(int id, JsonPatchDocument <ApiPostTypesRequestModel> patch)
        {
            var record = await this.PostTypesService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiPostTypesRequestModel request = this.PostTypesModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Ejemplo n.º 9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPostTypesRepository>();
            var model = new ApiPostTypesRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostTypes>())).Returns(Task.FromResult(new PostTypes()));
            var service = new PostTypesService(mock.LoggerMock.Object,
                                               mock.RepositoryMock.Object,
                                               mock.ModelValidatorMockFactory.PostTypesModelValidatorMock.Object,
                                               mock.BOLMapperMockFactory.BOLPostTypesMapperMock,
                                               mock.DALMapperMockFactory.DALPostTypesMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PostTypesModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostTypesRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PostTypes>()));
        }
Ejemplo n.º 10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IPostTypesRepository>();
            var model = new ApiPostTypesRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PostTypesService(mock.LoggerMock.Object,
                                               mock.RepositoryMock.Object,
                                               mock.ModelValidatorMockFactory.PostTypesModelValidatorMock.Object,
                                               mock.BOLMapperMockFactory.BOLPostTypesMapperMock,
                                               mock.DALMapperMockFactory.DALPostTypesMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.PostTypesModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Ejemplo n.º 11
0
        public virtual async Task <UpdateResponse <ApiPostTypesResponseModel> > Update(
            int id,
            ApiPostTypesRequestModel model)
        {
            var validationResult = await this.postTypesModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolPostTypesMapper.MapModelToBO(id, model);
                await this.postTypesRepository.Update(this.dalPostTypesMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiPostTypesResponseModel>(this.bolPostTypesMapper.MapBOToModel(this.dalPostTypesMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiPostTypesResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPostTypesRequestModel model)
        {
            ApiPostTypesRequestModel request = await this.PatchModel(id, this.PostTypesModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiPostTypesResponseModel> result = await this.PostTypesService.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 <ApiPostTypesRequestModel> patch)
        {
            ApiPostTypesResponseModel record = await this.PostTypesService.Get(id);

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

                UpdateResponse <ApiPostTypesResponseModel> result = await this.PostTypesService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
		public async Task<ValidationResult> ValidateUpdateAsync(int id, ApiPostTypesRequestModel model)
		{
			this.TypeRules();
			return await this.ValidateAsync(model, id);
		}
		public async Task<ValidationResult> ValidateCreateAsync(ApiPostTypesRequestModel model)
		{
			this.TypeRules();
			return await this.ValidateAsync(model);
		}
Ejemplo n.º 16
0
        public virtual async Task <UpdateResponse <ApiPostTypesResponseModel> > PostTypesUpdateAsync(int id, ApiPostTypesRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/PostTypes/{id}", item).ConfigureAwait(false);

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