Esempio n. 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 ApiSelfReferenceRequestModel();

            createModel.SetProperties(2, 2);
            CreateResponse <ApiSelfReferenceResponseModel> createResult = await client.SelfReferenceCreateAsync(createModel);

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

            ApiSelfReferenceResponseModel getResponse = await client.SelfReferenceGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.SelfReferenceDeleteAsync(2);

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

            ApiSelfReferenceResponseModel verifyResponse = await client.SelfReferenceGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Esempio n. 2
0
        private async Task <ApiSelfReferenceResponseModel> CreateRecord()
        {
            var model = new ApiSelfReferenceRequestModel();

            model.SetProperties(2, 2);
            CreateResponse <ApiSelfReferenceResponseModel> result = await this.Client.SelfReferenceCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiSelfReferenceModelMapper();
            var model  = new ApiSelfReferenceResponseModel();

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

            response.SelfReferenceId.Should().Be(1);
            response.SelfReferenceId2.Should().Be(1);
        }
        public void MapModelToBO()
        {
            var mapper = new BOLSelfReferenceMapper();
            ApiSelfReferenceRequestModel model = new ApiSelfReferenceRequestModel();

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

            response.SelfReferenceId.Should().Be(1);
            response.SelfReferenceId2.Should().Be(1);
        }
Esempio n. 5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiSelfReferenceRequestModel model)
        {
            CreateResponse <ApiSelfReferenceResponseModel> result = await this.SelfReferenceService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SelfReferences/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOSelfReference MapModelToBO(
            int id,
            ApiSelfReferenceRequestModel model
            )
        {
            BOSelfReference boSelfReference = new BOSelfReference();

            boSelfReference.SetProperties(
                id,
                model.SelfReferenceId,
                model.SelfReferenceId2);
            return(boSelfReference);
        }
        public void CreatePatch()
        {
            var mapper = new ApiSelfReferenceModelMapper();
            var model  = new ApiSelfReferenceRequestModel();

            model.SetProperties(1, 1);

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

            patch.ApplyTo(response);
            response.SelfReferenceId.Should().Be(1);
            response.SelfReferenceId2.Should().Be(1);
        }
Esempio n. 8
0
        private async Task <ApiSelfReferenceRequestModel> PatchModel(int id, JsonPatchDocument <ApiSelfReferenceRequestModel> patch)
        {
            var record = await this.SelfReferenceService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSelfReferenceRequestModel request = this.SelfReferenceModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Esempio n. 9
0
        public virtual async Task <CreateResponse <ApiSelfReferenceResponseModel> > Create(
            ApiSelfReferenceRequestModel model)
        {
            CreateResponse <ApiSelfReferenceResponseModel> response = new CreateResponse <ApiSelfReferenceResponseModel>(await this.SelfReferenceModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolSelfReferenceMapper.MapModelToBO(default(int), model);
                var record = await this.SelfReferenceRepository.Create(this.DalSelfReferenceMapper.MapBOToEF(bo));

                response.SetRecord(this.BolSelfReferenceMapper.MapBOToModel(this.DalSelfReferenceMapper.MapEFToBO(record)));
            }

            return(response);
        }
Esempio n. 10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISelfReferenceRepository>();
            var model = new ApiSelfReferenceRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SelfReference>())).Returns(Task.FromResult(new SelfReference()));
            var service = new SelfReferenceService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.SelfReferenceModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLSelfReferenceMapperMock,
                                                   mock.DALMapperMockFactory.DALSelfReferenceMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SelfReferenceModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSelfReferenceRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SelfReference>()));
        }
Esempio n. 11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISelfReferenceRepository>();
            var model = new ApiSelfReferenceRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SelfReferenceService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.SelfReferenceModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLSelfReferenceMapperMock,
                                                   mock.DALMapperMockFactory.DALSelfReferenceMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SelfReferenceModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Esempio n. 12
0
        public virtual async Task <UpdateResponse <ApiSelfReferenceResponseModel> > Update(
            int id,
            ApiSelfReferenceRequestModel model)
        {
            var validationResult = await this.SelfReferenceModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolSelfReferenceMapper.MapModelToBO(id, model);
                await this.SelfReferenceRepository.Update(this.DalSelfReferenceMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiSelfReferenceResponseModel>(this.BolSelfReferenceMapper.MapBOToModel(this.DalSelfReferenceMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSelfReferenceResponseModel>(validationResult));
            }
        }
Esempio n. 13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSelfReferenceRequestModel model)
        {
            ApiSelfReferenceRequestModel request = await this.PatchModel(id, this.SelfReferenceModelMapper.CreatePatch(model));

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

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

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

                UpdateResponse <ApiSelfReferenceResponseModel> result = await this.SelfReferenceService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Esempio n. 15
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSelfReferenceRequestModel model)
 {
     this.SelfReferenceIdRules();
     this.SelfReferenceId2Rules();
     return(await this.ValidateAsync(model, id));
 }
Esempio n. 16
0
        public virtual async Task <UpdateResponse <ApiSelfReferenceResponseModel> > SelfReferenceUpdateAsync(int id, ApiSelfReferenceRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/SelfReferences/{id}", item).ConfigureAwait(false);

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