Example #1
0
        private async Task <ApiChannelResponseModel> CreateRecord()
        {
            var model = new ApiChannelRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Example #2
0
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiChannelRequestModel model)
 {
     this.DataVersionRules();
     this.JSONRules();
     this.LifecycleIdRules();
     this.NameRules();
     this.ProjectIdRules();
     this.TenantTagsRules();
     return(await this.ValidateAsync(model, id));
 }
        public virtual async Task <IActionResult> Create([FromBody] ApiChannelRequestModel model)
        {
            CreateResponse <ApiChannelResponseModel> result = await this.ChannelService.Create(model);

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiChannelRequestModel request = this.ChannelModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiChannelResponseModel> > Create(
            ApiChannelRequestModel model)
        {
            CreateResponse <ApiChannelResponseModel> response = new CreateResponse <ApiChannelResponseModel>(await this.channelModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolChannelMapper.MapModelToBO(default(string), model);
                var record = await this.channelRepository.Create(this.dalChannelMapper.MapBOToEF(bo));

                response.SetRecord(this.bolChannelMapper.MapBOToModel(this.dalChannelMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiChannelModelMapper();
            var model  = new ApiChannelResponseModel();

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

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.LifecycleId.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
        public virtual BOChannel MapModelToBO(
            string id,
            ApiChannelRequestModel model
            )
        {
            BOChannel boChannel = new BOChannel();

            boChannel.SetProperties(
                id,
                model.DataVersion,
                model.JSON,
                model.LifecycleId,
                model.Name,
                model.ProjectId,
                model.TenantTags);
            return(boChannel);
        }
Example #8
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IChannelRepository>();
            var model = new ApiChannelRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Channel>())).Returns(Task.FromResult(new Channel()));
            var service = new ChannelService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ChannelModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLChannelMapperMock,
                                             mock.DALMapperMockFactory.DALChannelMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ChannelModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiChannelRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Channel>()));
        }
Example #9
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IChannelRepository>();
            var model = new ApiChannelRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ChannelService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ChannelModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLChannelMapperMock,
                                             mock.DALMapperMockFactory.DALChannelMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ChannelModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
        public void CreatePatch()
        {
            var mapper = new ApiChannelModelMapper();
            var model  = new ApiChannelRequestModel();

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

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

            patch.ApplyTo(response);
            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.LifecycleId.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
        public virtual async Task <UpdateResponse <ApiChannelResponseModel> > Update(
            string id,
            ApiChannelRequestModel model)
        {
            var validationResult = await this.channelModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolChannelMapper.MapModelToBO(id, model);
                await this.channelRepository.Update(this.dalChannelMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiChannelResponseModel>(this.bolChannelMapper.MapBOToModel(this.dalChannelMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiChannelResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiChannelRequestModel model)
        {
            ApiChannelRequestModel request = await this.PatchModel(id, this.ChannelModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiChannelResponseModel> result = await this.ChannelService.Update(id, model);

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