Пример #1
0
        private async Task <ApiArtifactResponseModel> CreateRecord()
        {
            var model = new ApiArtifactRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
		public async Task<ValidationResult> ValidateUpdateAsync(string id, ApiArtifactRequestModel model)
		{
			this.CreatedRules();
			this.EnvironmentIdRules();
			this.FilenameRules();
			this.JSONRules();
			this.ProjectIdRules();
			this.RelatedDocumentIdsRules();
			this.TenantIdRules();
			return await this.ValidateAsync(model, id);
		}
        public virtual async Task <IActionResult> Create([FromBody] ApiArtifactRequestModel model)
        {
            CreateResponse <ApiArtifactResponseModel> result = await this.ArtifactService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Artifacts/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        private async Task <ApiArtifactRequestModel> PatchModel(string id, JsonPatchDocument <ApiArtifactRequestModel> patch)
        {
            var record = await this.ArtifactService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiArtifactRequestModel request = this.ArtifactModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Пример #5
0
        public virtual async Task <CreateResponse <ApiArtifactResponseModel> > Create(
            ApiArtifactRequestModel model)
        {
            CreateResponse <ApiArtifactResponseModel> response = new CreateResponse <ApiArtifactResponseModel>(await this.artifactModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolArtifactMapper.MapModelToBO(default(string), model);
                var record = await this.artifactRepository.Create(this.dalArtifactMapper.MapBOToEF(bo));

                response.SetRecord(this.bolArtifactMapper.MapBOToModel(this.dalArtifactMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiArtifactModelMapper();
            var model  = new ApiArtifactResponseModel();

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

            response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.EnvironmentId.Should().Be("A");
            response.Filename.Should().Be("A");
            response.JSON.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.RelatedDocumentIds.Should().Be("A");
            response.TenantId.Should().Be("A");
        }
Пример #7
0
        public virtual BOArtifact MapModelToBO(
            string id,
            ApiArtifactRequestModel model
            )
        {
            BOArtifact boArtifact = new BOArtifact();

            boArtifact.SetProperties(
                id,
                model.Created,
                model.EnvironmentId,
                model.Filename,
                model.JSON,
                model.ProjectId,
                model.RelatedDocumentIds,
                model.TenantId);
            return(boArtifact);
        }
Пример #8
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IArtifactRepository>();
            var model = new ApiArtifactRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Artifact>())).Returns(Task.FromResult(new Artifact()));
            var service = new ArtifactService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.ArtifactModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLArtifactMapperMock,
                                              mock.DALMapperMockFactory.DALArtifactMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ArtifactModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiArtifactRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Artifact>()));
        }
Пример #9
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IArtifactRepository>();
            var model = new ApiArtifactRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ArtifactService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.ArtifactModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLArtifactMapperMock,
                                              mock.DALMapperMockFactory.DALArtifactMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ArtifactModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
Пример #10
0
        public void CreatePatch()
        {
            var mapper = new ApiArtifactModelMapper();
            var model  = new ApiArtifactRequestModel();

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

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

            patch.ApplyTo(response);
            response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.EnvironmentId.Should().Be("A");
            response.Filename.Should().Be("A");
            response.JSON.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.RelatedDocumentIds.Should().Be("A");
            response.TenantId.Should().Be("A");
        }
Пример #11
0
        public virtual async Task <UpdateResponse <ApiArtifactResponseModel> > Update(
            string id,
            ApiArtifactRequestModel model)
        {
            var validationResult = await this.artifactModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolArtifactMapper.MapModelToBO(id, model);
                await this.artifactRepository.Update(this.dalArtifactMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiArtifactResponseModel>(this.bolArtifactMapper.MapBOToModel(this.dalArtifactMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiArtifactResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiArtifactRequestModel model)
        {
            ApiArtifactRequestModel request = await this.PatchModel(id, this.ArtifactModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiArtifactResponseModel> result = await this.ArtifactService.Update(id, model);

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