Ejemplo n.º 1
0
        private async Task <ApiProjectResponseModel> CreateRecord()
        {
            var model = new ApiProjectRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Ejemplo n.º 2
0
        public virtual async Task <IActionResult> Create([FromBody] ApiProjectRequestModel model)
        {
            CreateResponse <ApiProjectResponseModel> result = await this.ProjectService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Projects/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Ejemplo n.º 3
0
        public virtual async Task <CreateResponse <ApiProjectResponseModel> > Create(
            ApiProjectRequestModel model)
        {
            CreateResponse <ApiProjectResponseModel> response = new CreateResponse <ApiProjectResponseModel>(await this.projectModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolProjectMapper.MapModelToBO(default(string), model);
                var record = await this.projectRepository.Create(this.dalProjectMapper.MapBOToEF(bo));

                response.SetRecord(this.bolProjectMapper.MapBOToModel(this.dalProjectMapper.MapEFToBO(record)));
            }

            return(response);
        }
Ejemplo n.º 4
0
        private async Task <ApiProjectRequestModel> PatchModel(string id, JsonPatchDocument <ApiProjectRequestModel> patch)
        {
            var record = await this.ProjectService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProjectRequestModel request = this.ProjectModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiProjectRequestModel model)
 {
     this.AutoCreateReleaseRules();
     this.DataVersionRules();
     this.DeploymentProcessIdRules();
     this.DiscreteChannelReleaseRules();
     this.IncludedLibraryVariableSetIdsRules();
     this.IsDisabledRules();
     this.JSONRules();
     this.LifecycleIdRules();
     this.NameRules();
     this.ProjectGroupIdRules();
     this.SlugRules();
     this.VariableSetIdRules();
     return(await this.ValidateAsync(model, id));
 }
Ejemplo n.º 6
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IProjectRepository>();
            var model = new ApiProjectRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Project>())).Returns(Task.FromResult(new Project()));
            var service = new ProjectService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ProjectModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLProjectMapperMock,
                                             mock.DALMapperMockFactory.DALProjectMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProjectModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProjectRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Project>()));
        }
Ejemplo n.º 7
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IProjectRepository>();
            var model = new ApiProjectRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ProjectService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ProjectModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLProjectMapperMock,
                                             mock.DALMapperMockFactory.DALProjectMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ProjectModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
Ejemplo n.º 8
0
        public virtual async Task <UpdateResponse <ApiProjectResponseModel> > Update(
            string id,
            ApiProjectRequestModel model)
        {
            var validationResult = await this.projectModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolProjectMapper.MapModelToBO(id, model);
                await this.projectRepository.Update(this.dalProjectMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiProjectResponseModel>(this.bolProjectMapper.MapBOToModel(this.dalProjectMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProjectResponseModel>(validationResult));
            }
        }
Ejemplo n.º 9
0
        public void MapModelToBO()
        {
            var mapper = new BOLProjectMapper();
            ApiProjectRequestModel model = new ApiProjectRequestModel();

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

            response.AutoCreateRelease.Should().Be(true);
            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.DeploymentProcessId.Should().Be("A");
            response.DiscreteChannelRelease.Should().Be(true);
            response.IncludedLibraryVariableSetIds.Should().Be("A");
            response.IsDisabled.Should().Be(true);
            response.JSON.Should().Be("A");
            response.LifecycleId.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupId.Should().Be("A");
            response.Slug.Should().Be("A");
            response.VariableSetId.Should().Be("A");
        }
Ejemplo n.º 10
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiProjectRequestModel model)
        {
            ApiProjectRequestModel request = await this.PatchModel(id, this.ProjectModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Ejemplo n.º 11
0
        public virtual BOProject MapModelToBO(
            string id,
            ApiProjectRequestModel model
            )
        {
            BOProject boProject = new BOProject();

            boProject.SetProperties(
                id,
                model.AutoCreateRelease,
                model.DataVersion,
                model.DeploymentProcessId,
                model.DiscreteChannelRelease,
                model.IncludedLibraryVariableSetIds,
                model.IsDisabled,
                model.JSON,
                model.LifecycleId,
                model.Name,
                model.ProjectGroupId,
                model.Slug,
                model.VariableSetId);
            return(boProject);
        }
Ejemplo n.º 12
0
        public void CreatePatch()
        {
            var mapper = new ApiProjectModelMapper();
            var model  = new ApiProjectRequestModel();

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

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

            patch.ApplyTo(response);
            response.AutoCreateRelease.Should().Be(true);
            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.DeploymentProcessId.Should().Be("A");
            response.DiscreteChannelRelease.Should().Be(true);
            response.IncludedLibraryVariableSetIds.Should().Be("A");
            response.IsDisabled.Should().Be(true);
            response.JSON.Should().Be("A");
            response.LifecycleId.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupId.Should().Be("A");
            response.Slug.Should().Be("A");
            response.VariableSetId.Should().Be("A");
        }
Ejemplo n.º 13
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiProjectRequestModel> patch)
        {
            ApiProjectResponseModel record = await this.ProjectService.Get(id);

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

                UpdateResponse <ApiProjectResponseModel> result = await this.ProjectService.Update(id, model);

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