コード例 #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiFeedRequestModel model)
 {
     this.FeedTypeRules();
     this.FeedUriRules();
     this.JSONRules();
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
コード例 #2
0
        private async Task <ApiFeedResponseModel> CreateRecord()
        {
            var model = new ApiFeedRequestModel();

            model.SetProperties("B", "B", "B", "B");
            CreateResponse <ApiFeedResponseModel> result = await this.Client.FeedCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
コード例 #3
0
ファイル: TestBOLFeedMapper.cs プロジェクト: daniefer/samples
        public void MapModelToBO()
        {
            var mapper = new BOLFeedMapper();
            ApiFeedRequestModel model = new ApiFeedRequestModel();

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

            response.FeedType.Should().Be("A");
            response.FeedUri.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
コード例 #4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiFeedModelMapper();
            var model  = new ApiFeedResponseModel();

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

            response.FeedType.Should().Be("A");
            response.FeedUri.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
コード例 #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiFeedRequestModel model)
        {
            CreateResponse <ApiFeedResponseModel> result = await this.FeedService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Feeds/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #6
0
        public virtual async Task <CreateResponse <ApiFeedResponseModel> > Create(
            ApiFeedRequestModel model)
        {
            CreateResponse <ApiFeedResponseModel> response = new CreateResponse <ApiFeedResponseModel>(await this.feedModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolFeedMapper.MapModelToBO(default(string), model);
                var record = await this.feedRepository.Create(this.dalFeedMapper.MapBOToEF(bo));

                response.SetRecord(this.bolFeedMapper.MapBOToModel(this.dalFeedMapper.MapEFToBO(record)));
            }

            return(response);
        }
コード例 #7
0
        private async Task <ApiFeedRequestModel> PatchModel(string id, JsonPatchDocument <ApiFeedRequestModel> patch)
        {
            var record = await this.FeedService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiFeedRequestModel request = this.FeedModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #8
0
        public virtual BOFeed MapModelToBO(
            string id,
            ApiFeedRequestModel model
            )
        {
            BOFeed boFeed = new BOFeed();

            boFeed.SetProperties(
                id,
                model.FeedType,
                model.FeedUri,
                model.JSON,
                model.Name);
            return(boFeed);
        }
コード例 #9
0
        public void CreatePatch()
        {
            var mapper = new ApiFeedModelMapper();
            var model  = new ApiFeedRequestModel();

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

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

            patch.ApplyTo(response);
            response.FeedType.Should().Be("A");
            response.FeedUri.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
コード例 #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IFeedRepository>();
            var model = new ApiFeedRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Feed>())).Returns(Task.FromResult(new Feed()));
            var service = new FeedService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.FeedModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLFeedMapperMock,
                                          mock.DALMapperMockFactory.DALFeedMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.FeedModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFeedRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Feed>()));
        }
コード例 #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IFeedRepository>();
            var model = new ApiFeedRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new FeedService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.FeedModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLFeedMapperMock,
                                          mock.DALMapperMockFactory.DALFeedMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.FeedModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
コード例 #12
0
        public virtual async Task <UpdateResponse <ApiFeedResponseModel> > Update(
            string id,
            ApiFeedRequestModel model)
        {
            var validationResult = await this.feedModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolFeedMapper.MapModelToBO(id, model);
                await this.feedRepository.Update(this.dalFeedMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiFeedResponseModel>(this.bolFeedMapper.MapBOToModel(this.dalFeedMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiFeedResponseModel>(validationResult));
            }
        }
コード例 #13
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiFeedRequestModel model)
        {
            ApiFeedRequestModel request = await this.PatchModel(id, this.FeedModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #14
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiFeedRequestModel> patch)
        {
            ApiFeedResponseModel record = await this.FeedService.Get(id);

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

                UpdateResponse <ApiFeedResponseModel> result = await this.FeedService.Update(id, model);

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