public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiActionTemplateRequestModel model)
 {
     this.ActionTypeRules();
     this.CommunityActionTemplateIdRules();
     this.JSONRules();
     this.NameRules();
     this.VersionRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiActionTemplateResponseModel> CreateRecord()
        {
            var model = new ApiActionTemplateRequestModel();

            model.SetProperties("B", "B", "B", "B", 2);
            CreateResponse <ApiActionTemplateResponseModel> result = await this.Client.ActionTemplateCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Exemplo n.º 3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiActionTemplateRequestModel model)
        {
            CreateResponse <ApiActionTemplateResponseModel> result = await this.ActionTemplateService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ActionTemplates/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void MapModelToBO()
        {
            var mapper = new BOLActionTemplateMapper();
            ApiActionTemplateRequestModel model = new ApiActionTemplateRequestModel();

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

            response.ActionType.Should().Be("A");
            response.CommunityActionTemplateId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.Version.Should().Be(1);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiActionTemplateModelMapper();
            var model  = new ApiActionTemplateResponseModel();

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

            response.ActionType.Should().Be("A");
            response.CommunityActionTemplateId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.Version.Should().Be(1);
        }
        public virtual async Task <CreateResponse <ApiActionTemplateResponseModel> > Create(
            ApiActionTemplateRequestModel model)
        {
            CreateResponse <ApiActionTemplateResponseModel> response = new CreateResponse <ApiActionTemplateResponseModel>(await this.actionTemplateModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolActionTemplateMapper.MapModelToBO(default(string), model);
                var record = await this.actionTemplateRepository.Create(this.dalActionTemplateMapper.MapBOToEF(bo));

                response.SetRecord(this.bolActionTemplateMapper.MapBOToModel(this.dalActionTemplateMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemplo n.º 7
0
        private async Task <ApiActionTemplateRequestModel> PatchModel(string id, JsonPatchDocument <ApiActionTemplateRequestModel> patch)
        {
            var record = await this.ActionTemplateService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiActionTemplateRequestModel request = this.ActionTemplateModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual BOActionTemplate MapModelToBO(
            string id,
            ApiActionTemplateRequestModel model
            )
        {
            BOActionTemplate boActionTemplate = new BOActionTemplate();

            boActionTemplate.SetProperties(
                id,
                model.ActionType,
                model.CommunityActionTemplateId,
                model.JSON,
                model.Name,
                model.Version);
            return(boActionTemplate);
        }
        public void CreatePatch()
        {
            var mapper = new ApiActionTemplateModelMapper();
            var model  = new ApiActionTemplateRequestModel();

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

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

            patch.ApplyTo(response);
            response.ActionType.Should().Be("A");
            response.CommunityActionTemplateId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.Version.Should().Be(1);
        }
Exemplo n.º 10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IActionTemplateRepository>();
            var model = new ApiActionTemplateRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ActionTemplate>())).Returns(Task.FromResult(new ActionTemplate()));
            var service = new ActionTemplateService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.ActionTemplateModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLActionTemplateMapperMock,
                                                    mock.DALMapperMockFactory.DALActionTemplateMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ActionTemplateModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiActionTemplateRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ActionTemplate>()));
        }
Exemplo n.º 11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IActionTemplateRepository>();
            var model = new ApiActionTemplateRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ActionTemplateService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.ActionTemplateModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLActionTemplateMapperMock,
                                                    mock.DALMapperMockFactory.DALActionTemplateMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.bolActionTemplateMapper.MapModelToBO(id, model);
                await this.actionTemplateRepository.Update(this.dalActionTemplateMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiActionTemplateResponseModel>(this.bolActionTemplateMapper.MapBOToModel(this.dalActionTemplateMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiActionTemplateResponseModel>(validationResult));
            }
        }
Exemplo n.º 13
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiActionTemplateRequestModel model)
        {
            ApiActionTemplateRequestModel request = await this.PatchModel(id, this.ActionTemplateModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 14
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiActionTemplateRequestModel> patch)
        {
            ApiActionTemplateResponseModel record = await this.ActionTemplateService.Get(id);

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

                UpdateResponse <ApiActionTemplateResponseModel> result = await this.ActionTemplateService.Update(id, model);

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