public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiProjectGroupRequestModel model)
 {
     this.DataVersionRules();
     this.JSONRules();
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiProjectGroupResponseModel> CreateRecord()
        {
            var model = new ApiProjectGroupRequestModel();

            model.SetProperties(BitConverter.GetBytes(2), "B", "B");
            CreateResponse <ApiProjectGroupResponseModel> result = await this.Client.ProjectGroupCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Exemple #3
0
        public void MapModelToBO()
        {
            var mapper = new BOLProjectGroupMapper();
            ApiProjectGroupRequestModel model = new ApiProjectGroupRequestModel();

            model.SetProperties(BitConverter.GetBytes(1), "A", "A");
            BOProjectGroup response = mapper.MapModelToBO("A", model);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiProjectGroupModelMapper();
            var model  = new ApiProjectGroupResponseModel();

            model.SetProperties("A", BitConverter.GetBytes(1), "A", "A");
            ApiProjectGroupRequestModel response = mapper.MapResponseToRequest(model);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiProjectGroupRequestModel model)
        {
            CreateResponse <ApiProjectGroupResponseModel> result = await this.ProjectGroupService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ProjectGroups/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOProjectGroup MapModelToBO(
            string id,
            ApiProjectGroupRequestModel model
            )
        {
            BOProjectGroup boProjectGroup = new BOProjectGroup();

            boProjectGroup.SetProperties(
                id,
                model.DataVersion,
                model.JSON,
                model.Name);
            return(boProjectGroup);
        }
        private async Task <ApiProjectGroupRequestModel> PatchModel(string id, JsonPatchDocument <ApiProjectGroupRequestModel> patch)
        {
            var record = await this.ProjectGroupService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProjectGroupRequestModel request = this.ProjectGroupModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiProjectGroupResponseModel> > Create(
            ApiProjectGroupRequestModel model)
        {
            CreateResponse <ApiProjectGroupResponseModel> response = new CreateResponse <ApiProjectGroupResponseModel>(await this.projectGroupModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolProjectGroupMapper.MapModelToBO(default(string), model);
                var record = await this.projectGroupRepository.Create(this.dalProjectGroupMapper.MapBOToEF(bo));

                response.SetRecord(this.bolProjectGroupMapper.MapBOToModel(this.dalProjectGroupMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public void CreatePatch()
        {
            var mapper = new ApiProjectGroupModelMapper();
            var model  = new ApiProjectGroupRequestModel();

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

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

            patch.ApplyTo(response);
            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IProjectGroupRepository>();
            var model = new ApiProjectGroupRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProjectGroup>())).Returns(Task.FromResult(new ProjectGroup()));
            var service = new ProjectGroupService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.ProjectGroupModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLProjectGroupMapperMock,
                                                  mock.DALMapperMockFactory.DALProjectGroupMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProjectGroupModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProjectGroupRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProjectGroup>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IProjectGroupRepository>();
            var model = new ApiProjectGroupRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ProjectGroupService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.ProjectGroupModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLProjectGroupMapperMock,
                                                  mock.DALMapperMockFactory.DALProjectGroupMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ProjectGroupModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
        public virtual async Task <UpdateResponse <ApiProjectGroupResponseModel> > Update(
            string id,
            ApiProjectGroupRequestModel model)
        {
            var validationResult = await this.projectGroupModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolProjectGroupMapper.MapModelToBO(id, model);
                await this.projectGroupRepository.Update(this.dalProjectGroupMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiProjectGroupResponseModel>(this.bolProjectGroupMapper.MapBOToModel(this.dalProjectGroupMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProjectGroupResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiProjectGroupRequestModel model)
        {
            ApiProjectGroupRequestModel request = await this.PatchModel(id, this.ProjectGroupModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiProjectGroupRequestModel> patch)
        {
            ApiProjectGroupResponseModel record = await this.ProjectGroupService.Get(id);

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

                UpdateResponse <ApiProjectGroupResponseModel> result = await this.ProjectGroupService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }