Beispiel #1
0
        private async Task <ApiProxyResponseModel> CreateRecord()
        {
            var model = new ApiProxyRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #2
0
        public void MapModelToBO()
        {
            var mapper = new BOLProxyMapper();
            ApiProxyRequestModel model = new ApiProxyRequestModel();

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

            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
Beispiel #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiProxyModelMapper();
            var model  = new ApiProxyResponseModel();

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

            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
Beispiel #4
0
        public virtual async Task <IActionResult> Create([FromBody] ApiProxyRequestModel model)
        {
            CreateResponse <ApiProxyResponseModel> result = await this.ProxyService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Proxies/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOProxy MapModelToBO(
            string id,
            ApiProxyRequestModel model
            )
        {
            BOProxy boProxy = new BOProxy();

            boProxy.SetProperties(
                id,
                model.JSON,
                model.Name);
            return(boProxy);
        }
Beispiel #6
0
        public void CreatePatch()
        {
            var mapper = new ApiProxyModelMapper();
            var model  = new ApiProxyRequestModel();

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

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

            patch.ApplyTo(response);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
Beispiel #7
0
        public virtual async Task <CreateResponse <ApiProxyResponseModel> > Create(
            ApiProxyRequestModel model)
        {
            CreateResponse <ApiProxyResponseModel> response = new CreateResponse <ApiProxyResponseModel>(await this.proxyModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolProxyMapper.MapModelToBO(default(string), model);
                var record = await this.proxyRepository.Create(this.dalProxyMapper.MapBOToEF(bo));

                response.SetRecord(this.bolProxyMapper.MapBOToModel(this.dalProxyMapper.MapEFToBO(record)));
            }

            return(response);
        }
Beispiel #8
0
        private async Task <ApiProxyRequestModel> PatchModel(string id, JsonPatchDocument <ApiProxyRequestModel> patch)
        {
            var record = await this.ProxyService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProxyRequestModel request = this.ProxyModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IProxyRepository>();
            var model = new ApiProxyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Proxy>())).Returns(Task.FromResult(new Proxy()));
            var service = new ProxyService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ProxyModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLProxyMapperMock,
                                           mock.DALMapperMockFactory.DALProxyMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProxyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProxyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Proxy>()));
        }
Beispiel #10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IProxyRepository>();
            var model = new ApiProxyRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ProxyService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ProxyModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLProxyMapperMock,
                                           mock.DALMapperMockFactory.DALProxyMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ProxyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
Beispiel #11
0
        public virtual async Task <UpdateResponse <ApiProxyResponseModel> > Update(
            string id,
            ApiProxyRequestModel model)
        {
            var validationResult = await this.proxyModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolProxyMapper.MapModelToBO(id, model);
                await this.proxyRepository.Update(this.dalProxyMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiProxyResponseModel>(this.bolProxyMapper.MapBOToModel(this.dalProxyMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProxyResponseModel>(validationResult));
            }
        }
Beispiel #12
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiProxyRequestModel model)
        {
            ApiProxyRequestModel request = await this.PatchModel(id, this.ProxyModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #13
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiProxyRequestModel> patch)
        {
            ApiProxyResponseModel record = await this.ProxyService.Get(id);

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

                UpdateResponse <ApiProxyResponseModel> result = await this.ProxyService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiProxyRequestModel model)
 {
     this.JSONRules();
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
 public async Task <ValidationResult> ValidateCreateAsync(ApiProxyRequestModel model)
 {
     this.JSONRules();
     this.NameRules();
     return(await this.ValidateAsync(model));
 }