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 ApiCompositePrimaryKeyRequestModel();

            createModel.SetProperties(2);
            CreateResponse <ApiCompositePrimaryKeyResponseModel> createResult = await client.CompositePrimaryKeyCreateAsync(createModel);

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

            ApiCompositePrimaryKeyResponseModel getResponse = await client.CompositePrimaryKeyGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.CompositePrimaryKeyDeleteAsync(2);

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

            ApiCompositePrimaryKeyResponseModel verifyResponse = await client.CompositePrimaryKeyGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Exemplo n.º 2
0
        public void MapModelToBO()
        {
            var mapper = new BOLCompositePrimaryKeyMapper();
            ApiCompositePrimaryKeyRequestModel model = new ApiCompositePrimaryKeyRequestModel();

            model.SetProperties(1);
            BOCompositePrimaryKey response = mapper.MapModelToBO(1, model);

            response.Id2.Should().Be(1);
        }
        private async Task <ApiCompositePrimaryKeyResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiCompositePrimaryKeyRequestModel();

            model.SetProperties(2);
            CreateResponse <ApiCompositePrimaryKeyResponseModel> result = await client.CompositePrimaryKeyCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Exemplo n.º 4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiCompositePrimaryKeyModelMapper();
            var model  = new ApiCompositePrimaryKeyResponseModel();

            model.SetProperties(1, 1);
            ApiCompositePrimaryKeyRequestModel response = mapper.MapResponseToRequest(model);

            response.Id2.Should().Be(1);
        }
        public virtual BOCompositePrimaryKey MapModelToBO(
            int id,
            ApiCompositePrimaryKeyRequestModel model
            )
        {
            BOCompositePrimaryKey boCompositePrimaryKey = new BOCompositePrimaryKey();

            boCompositePrimaryKey.SetProperties(
                id,
                model.Id2);
            return(boCompositePrimaryKey);
        }
Exemplo n.º 6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiCompositePrimaryKeyRequestModel model)
        {
            CreateResponse <ApiCompositePrimaryKeyResponseModel> result = await this.CompositePrimaryKeyService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/CompositePrimaryKeys/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Exemplo n.º 7
0
        public void CreatePatch()
        {
            var mapper = new ApiCompositePrimaryKeyModelMapper();
            var model  = new ApiCompositePrimaryKeyRequestModel();

            model.SetProperties(1);

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

            patch.ApplyTo(response);
            response.Id2.Should().Be(1);
        }
Exemplo n.º 8
0
        private async Task <ApiCompositePrimaryKeyRequestModel> PatchModel(int id, JsonPatchDocument <ApiCompositePrimaryKeyRequestModel> patch)
        {
            var record = await this.CompositePrimaryKeyService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiCompositePrimaryKeyRequestModel request = this.CompositePrimaryKeyModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiCompositePrimaryKeyResponseModel> > Create(
            ApiCompositePrimaryKeyRequestModel model)
        {
            CreateResponse <ApiCompositePrimaryKeyResponseModel> response = new CreateResponse <ApiCompositePrimaryKeyResponseModel>(await this.CompositePrimaryKeyModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolCompositePrimaryKeyMapper.MapModelToBO(default(int), model);
                var record = await this.CompositePrimaryKeyRepository.Create(this.DalCompositePrimaryKeyMapper.MapBOToEF(bo));

                response.SetRecord(this.BolCompositePrimaryKeyMapper.MapBOToModel(this.DalCompositePrimaryKeyMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemplo n.º 10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ICompositePrimaryKeyRepository>();
            var model = new ApiCompositePrimaryKeyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <CompositePrimaryKey>())).Returns(Task.FromResult(new CompositePrimaryKey()));
            var service = new CompositePrimaryKeyService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.CompositePrimaryKeyModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLCompositePrimaryKeyMapperMock,
                                                         mock.DALMapperMockFactory.DALCompositePrimaryKeyMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.CompositePrimaryKeyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCompositePrimaryKeyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <CompositePrimaryKey>()));
        }
Exemplo n.º 11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ICompositePrimaryKeyRepository>();
            var model = new ApiCompositePrimaryKeyRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new CompositePrimaryKeyService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.CompositePrimaryKeyModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLCompositePrimaryKeyMapperMock,
                                                         mock.DALMapperMockFactory.DALCompositePrimaryKeyMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.CompositePrimaryKeyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <UpdateResponse <ApiCompositePrimaryKeyResponseModel> > Update(
            int id,
            ApiCompositePrimaryKeyRequestModel model)
        {
            var validationResult = await this.CompositePrimaryKeyModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolCompositePrimaryKeyMapper.MapModelToBO(id, model);
                await this.CompositePrimaryKeyRepository.Update(this.DalCompositePrimaryKeyMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiCompositePrimaryKeyResponseModel>(this.BolCompositePrimaryKeyMapper.MapBOToModel(this.DalCompositePrimaryKeyMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiCompositePrimaryKeyResponseModel>(validationResult));
            }
        }
Exemplo n.º 13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiCompositePrimaryKeyRequestModel model)
        {
            ApiCompositePrimaryKeyRequestModel request = await this.PatchModel(id, this.CompositePrimaryKeyModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCompositePrimaryKeyRequestModel> patch)
        {
            ApiCompositePrimaryKeyResponseModel record = await this.CompositePrimaryKeyService.Get(id);

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

                UpdateResponse <ApiCompositePrimaryKeyResponseModel> result = await this.CompositePrimaryKeyService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 15
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiCompositePrimaryKeyRequestModel model)
 {
     this.Id2Rules();
     return(await this.ValidateAsync(model, id));
 }
Exemplo n.º 16
0
        public virtual async Task <UpdateResponse <ApiCompositePrimaryKeyResponseModel> > CompositePrimaryKeyUpdateAsync(int id, ApiCompositePrimaryKeyRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/CompositePrimaryKeys/{id}", item).ConfigureAwait(false);

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