Exemple #1
0
        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 ApiSchemaAPersonRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiSchemaAPersonResponseModel> createResult = await client.SchemaAPersonCreateAsync(createModel);

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

            ApiSchemaAPersonResponseModel getResponse = await client.SchemaAPersonGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.SchemaAPersonDeleteAsync(2);

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

            ApiSchemaAPersonResponseModel verifyResponse = await client.SchemaAPersonGetAsync(2);

            verifyResponse.Should().BeNull();
        }
        public void MapModelToBO()
        {
            var mapper = new BOLSchemaAPersonMapper();
            ApiSchemaAPersonRequestModel model = new ApiSchemaAPersonRequestModel();

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

            response.Name.Should().Be("A");
        }
Exemple #3
0
        private async Task <ApiSchemaAPersonResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiSchemaAPersonRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiSchemaAPersonResponseModel> result = await client.SchemaAPersonCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Exemple #4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiSchemaAPersonModelMapper();
            var model  = new ApiSchemaAPersonResponseModel();

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

            response.Name.Should().Be("A");
        }
Exemple #5
0
        public virtual BOSchemaAPerson MapModelToBO(
            int id,
            ApiSchemaAPersonRequestModel model
            )
        {
            BOSchemaAPerson boSchemaAPerson = new BOSchemaAPerson();

            boSchemaAPerson.SetProperties(
                id,
                model.Name);
            return(boSchemaAPerson);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiSchemaAPersonRequestModel model)
        {
            CreateResponse <ApiSchemaAPersonResponseModel> result = await this.SchemaAPersonService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SchemaAPersons/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Exemple #7
0
        public void CreatePatch()
        {
            var mapper = new ApiSchemaAPersonModelMapper();
            var model  = new ApiSchemaAPersonRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
Exemple #8
0
        public virtual async Task <CreateResponse <ApiSchemaAPersonResponseModel> > Create(
            ApiSchemaAPersonRequestModel model)
        {
            CreateResponse <ApiSchemaAPersonResponseModel> response = new CreateResponse <ApiSchemaAPersonResponseModel>(await this.schemaAPersonModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolSchemaAPersonMapper.MapModelToBO(default(int), model);
                var record = await this.schemaAPersonRepository.Create(this.dalSchemaAPersonMapper.MapBOToEF(bo));

                response.SetRecord(this.bolSchemaAPersonMapper.MapBOToModel(this.dalSchemaAPersonMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSchemaAPersonRequestModel request = this.SchemaAPersonModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISchemaAPersonRepository>();
            var model = new ApiSchemaAPersonRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SchemaAPerson>())).Returns(Task.FromResult(new SchemaAPerson()));
            var service = new SchemaAPersonService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.SchemaAPersonModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLSchemaAPersonMapperMock,
                                                   mock.DALMapperMockFactory.DALSchemaAPersonMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SchemaAPersonModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSchemaAPersonRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SchemaAPerson>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISchemaAPersonRepository>();
            var model = new ApiSchemaAPersonRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SchemaAPersonService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.SchemaAPersonModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLSchemaAPersonMapperMock,
                                                   mock.DALMapperMockFactory.DALSchemaAPersonMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SchemaAPersonModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Exemple #12
0
        public virtual async Task <UpdateResponse <ApiSchemaAPersonResponseModel> > Update(
            int id,
            ApiSchemaAPersonRequestModel model)
        {
            var validationResult = await this.schemaAPersonModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolSchemaAPersonMapper.MapModelToBO(id, model);
                await this.schemaAPersonRepository.Update(this.dalSchemaAPersonMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiSchemaAPersonResponseModel>(this.bolSchemaAPersonMapper.MapBOToModel(this.dalSchemaAPersonMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSchemaAPersonResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSchemaAPersonRequestModel model)
        {
            ApiSchemaAPersonRequestModel request = await this.PatchModel(id, this.SchemaAPersonModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiSchemaAPersonResponseModel> result = await this.SchemaAPersonService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemple #15
0
        public virtual async Task <UpdateResponse <ApiSchemaAPersonResponseModel> > SchemaAPersonUpdateAsync(int id, ApiSchemaAPersonRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/SchemaAPersons/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiSchemaAPersonResponseModel> >(httpResponse.Content.ContentToString()));
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSchemaAPersonRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }