public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiSchemaBPersonRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiSchemaBPersonResponseModel> createResult = await client.SchemaBPersonCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiSchemaBPersonResponseModel getResponse = await client.SchemaBPersonGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.SchemaBPersonDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiSchemaBPersonResponseModel verifyResponse = await client.SchemaBPersonGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Example #2
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiSchemaBPersonModelMapper();
            var model  = new ApiSchemaBPersonResponseModel();

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

            response.Name.Should().Be("A");
        }
        private async Task <ApiSchemaBPersonResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiSchemaBPersonRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiSchemaBPersonResponseModel> result = await client.SchemaBPersonCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Example #4
0
        public void MapModelToBO()
        {
            var mapper = new BOLSchemaBPersonMapper();
            ApiSchemaBPersonRequestModel model = new ApiSchemaBPersonRequestModel();

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

            response.Name.Should().Be("A");
        }
Example #5
0
        public virtual BOSchemaBPerson MapModelToBO(
            int id,
            ApiSchemaBPersonRequestModel model
            )
        {
            BOSchemaBPerson boSchemaBPerson = new BOSchemaBPerson();

            boSchemaBPerson.SetProperties(
                id,
                model.Name);
            return(boSchemaBPerson);
        }
Example #6
0
        public void CreatePatch()
        {
            var mapper = new ApiSchemaBPersonModelMapper();
            var model  = new ApiSchemaBPersonRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiSchemaBPersonRequestModel model)
        {
            CreateResponse <ApiSchemaBPersonResponseModel> result = await this.SchemaBPersonService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SchemaBPersons/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Example #8
0
        public virtual async Task <CreateResponse <ApiSchemaBPersonResponseModel> > Create(
            ApiSchemaBPersonRequestModel model)
        {
            CreateResponse <ApiSchemaBPersonResponseModel> response = new CreateResponse <ApiSchemaBPersonResponseModel>(await this.SchemaBPersonModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolSchemaBPersonMapper.MapModelToBO(default(int), model);
                var record = await this.SchemaBPersonRepository.Create(this.DalSchemaBPersonMapper.MapBOToEF(bo));

                response.SetRecord(this.BolSchemaBPersonMapper.MapBOToModel(this.DalSchemaBPersonMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiSchemaBPersonRequestModel> PatchModel(int id, JsonPatchDocument <ApiSchemaBPersonRequestModel> patch)
        {
            var record = await this.SchemaBPersonService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSchemaBPersonRequestModel request = this.SchemaBPersonModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Example #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISchemaBPersonRepository>();
            var model = new ApiSchemaBPersonRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SchemaBPerson>())).Returns(Task.FromResult(new SchemaBPerson()));
            var service = new SchemaBPersonService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.SchemaBPersonModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLSchemaBPersonMapperMock,
                                                   mock.DALMapperMockFactory.DALSchemaBPersonMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SchemaBPersonModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSchemaBPersonRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SchemaBPerson>()));
        }
Example #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISchemaBPersonRepository>();
            var model = new ApiSchemaBPersonRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SchemaBPersonService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.SchemaBPersonModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLSchemaBPersonMapperMock,
                                                   mock.DALMapperMockFactory.DALSchemaBPersonMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SchemaBPersonModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Example #12
0
        public virtual async Task <UpdateResponse <ApiSchemaBPersonResponseModel> > Update(
            int id,
            ApiSchemaBPersonRequestModel model)
        {
            var validationResult = await this.SchemaBPersonModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolSchemaBPersonMapper.MapModelToBO(id, model);
                await this.SchemaBPersonRepository.Update(this.DalSchemaBPersonMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiSchemaBPersonResponseModel>(this.BolSchemaBPersonMapper.MapBOToModel(this.DalSchemaBPersonMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSchemaBPersonResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSchemaBPersonRequestModel model)
        {
            ApiSchemaBPersonRequestModel request = await this.PatchModel(id, this.SchemaBPersonModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSchemaBPersonRequestModel> patch)
        {
            ApiSchemaBPersonResponseModel record = await this.SchemaBPersonService.Get(id);

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

                UpdateResponse <ApiSchemaBPersonResponseModel> result = await this.SchemaBPersonService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSchemaBPersonRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
Example #16
0
        public virtual async Task <UpdateResponse <ApiSchemaBPersonResponseModel> > SchemaBPersonUpdateAsync(int id, ApiSchemaBPersonRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/SchemaBPersons/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiSchemaBPersonResponseModel> >(httpResponse.Content.ContentToString()));
        }