private async Task <ApiDeploymentResponseModel> CreateRecord()
        {
            var model = new ApiDeploymentRequestModel();

            model.SetProperties("B", DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", "B", "B", "B", "B", "B", "B");
            CreateResponse <ApiDeploymentResponseModel> result = await this.Client.DeploymentCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Exemple #2
0
        public virtual async Task <IActionResult> Create([FromBody] ApiDeploymentRequestModel model)
        {
            CreateResponse <ApiDeploymentResponseModel> result = await this.DeploymentService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Deployments/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual async Task <CreateResponse <ApiDeploymentResponseModel> > Create(
            ApiDeploymentRequestModel model)
        {
            CreateResponse <ApiDeploymentResponseModel> response = new CreateResponse <ApiDeploymentResponseModel>(await this.deploymentModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolDeploymentMapper.MapModelToBO(default(string), model);
                var record = await this.deploymentRepository.Create(this.dalDeploymentMapper.MapBOToEF(bo));

                response.SetRecord(this.bolDeploymentMapper.MapBOToModel(this.dalDeploymentMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemple #4
0
        private async Task <ApiDeploymentRequestModel> PatchModel(string id, JsonPatchDocument <ApiDeploymentRequestModel> patch)
        {
            var record = await this.DeploymentService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiDeploymentRequestModel request = this.DeploymentModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Exemple #5
0
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiDeploymentRequestModel model)
 {
     this.ChannelIdRules();
     this.CreatedRules();
     this.DeployedByRules();
     this.DeployedToMachineIdsRules();
     this.EnvironmentIdRules();
     this.JSONRules();
     this.NameRules();
     this.ProjectGroupIdRules();
     this.ProjectIdRules();
     this.ReleaseIdRules();
     this.TaskIdRules();
     this.TenantIdRules();
     return(await this.ValidateAsync(model, id));
 }
Exemple #6
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IDeploymentRepository>();
            var model = new ApiDeploymentRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Deployment>())).Returns(Task.FromResult(new Deployment()));
            var service = new DeploymentService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.DeploymentModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLDeploymentMapperMock,
                                                mock.DALMapperMockFactory.DALDeploymentMapperMock,
                                                mock.BOLMapperMockFactory.BOLDeploymentRelatedMachineMapperMock,
                                                mock.DALMapperMockFactory.DALDeploymentRelatedMachineMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.DeploymentModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDeploymentRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Deployment>()));
        }
Exemple #7
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IDeploymentRepository>();
            var model = new ApiDeploymentRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new DeploymentService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.DeploymentModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLDeploymentMapperMock,
                                                mock.DALMapperMockFactory.DALDeploymentMapperMock,
                                                mock.BOLMapperMockFactory.BOLDeploymentRelatedMachineMapperMock,
                                                mock.DALMapperMockFactory.DALDeploymentRelatedMachineMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.bolDeploymentMapper.MapModelToBO(id, model);
                await this.deploymentRepository.Update(this.dalDeploymentMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiDeploymentResponseModel>(this.bolDeploymentMapper.MapBOToModel(this.dalDeploymentMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiDeploymentResponseModel>(validationResult));
            }
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiDeploymentModelMapper();
            var model  = new ApiDeploymentResponseModel();

            model.SetProperties("A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", "A", "A", "A", "A", "A");
            ApiDeploymentRequestModel response = mapper.MapResponseToRequest(model);

            response.ChannelId.Should().Be("A");
            response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.DeployedBy.Should().Be("A");
            response.DeployedToMachineIds.Should().Be("A");
            response.EnvironmentId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupId.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.ReleaseId.Should().Be("A");
            response.TaskId.Should().Be("A");
            response.TenantId.Should().Be("A");
        }
Exemple #10
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiDeploymentRequestModel model)
        {
            ApiDeploymentRequestModel request = await this.PatchModel(id, this.DeploymentModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual BODeployment MapModelToBO(
            string id,
            ApiDeploymentRequestModel model
            )
        {
            BODeployment boDeployment = new BODeployment();

            boDeployment.SetProperties(
                id,
                model.ChannelId,
                model.Created,
                model.DeployedBy,
                model.DeployedToMachineIds,
                model.EnvironmentId,
                model.JSON,
                model.Name,
                model.ProjectGroupId,
                model.ProjectId,
                model.ReleaseId,
                model.TaskId,
                model.TenantId);
            return(boDeployment);
        }
Exemple #12
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiDeploymentRequestModel> patch)
        {
            ApiDeploymentResponseModel record = await this.DeploymentService.Get(id);

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

                UpdateResponse <ApiDeploymentResponseModel> result = await this.DeploymentService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiDeploymentModelMapper();
            var model  = new ApiDeploymentRequestModel();

            model.SetProperties("A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", "A", "A", "A", "A", "A");

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

            patch.ApplyTo(response);
            response.ChannelId.Should().Be("A");
            response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.DeployedBy.Should().Be("A");
            response.DeployedToMachineIds.Should().Be("A");
            response.EnvironmentId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupId.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.ReleaseId.Should().Be("A");
            response.TaskId.Should().Be("A");
            response.TenantId.Should().Be("A");
        }