Ejemplo 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 ApiPostLinkRequestModel();

            createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2);
            CreateResponse <ApiPostLinkResponseModel> createResult = await client.PostLinkCreateAsync(createModel);

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

            ApiPostLinkResponseModel getResponse = await client.PostLinkGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.PostLinkDeleteAsync(2);

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

            ApiPostLinkResponseModel verifyResponse = await client.PostLinkGetAsync(2);

            verifyResponse.Should().BeNull();
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPostLinkRequestModel model)
 {
     this.CreationDateRules();
     this.LinkTypeIdRules();
     this.PostIdRules();
     this.RelatedPostIdRules();
     return(await this.ValidateAsync(model, id));
 }
Ejemplo n.º 3
0
        private async Task <ApiPostLinkResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiPostLinkRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2);
            CreateResponse <ApiPostLinkResponseModel> result = await client.PostLinkCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Ejemplo n.º 4
0
        public void MapModelToBO()
        {
            var mapper = new BOLPostLinkMapper();
            ApiPostLinkRequestModel model = new ApiPostLinkRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            BOPostLink response = mapper.MapModelToBO(1, model);

            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LinkTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RelatedPostId.Should().Be(1);
        }
Ejemplo n.º 5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiPostLinkModelMapper();
            var model  = new ApiPostLinkResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            ApiPostLinkRequestModel response = mapper.MapResponseToRequest(model);

            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LinkTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RelatedPostId.Should().Be(1);
        }
Ejemplo n.º 6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiPostLinkRequestModel model)
        {
            CreateResponse <ApiPostLinkResponseModel> result = await this.PostLinkService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PostLinks/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Ejemplo n.º 7
0
        public virtual async Task <CreateResponse <ApiPostLinkResponseModel> > Create(
            ApiPostLinkRequestModel model)
        {
            CreateResponse <ApiPostLinkResponseModel> response = new CreateResponse <ApiPostLinkResponseModel>(await this.PostLinkModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolPostLinkMapper.MapModelToBO(default(int), model);
                var record = await this.PostLinkRepository.Create(this.DalPostLinkMapper.MapBOToEF(bo));

                response.SetRecord(this.BolPostLinkMapper.MapBOToModel(this.DalPostLinkMapper.MapEFToBO(record)));
            }

            return(response);
        }
Ejemplo n.º 8
0
        public virtual BOPostLink MapModelToBO(
            int id,
            ApiPostLinkRequestModel model
            )
        {
            BOPostLink boPostLink = new BOPostLink();

            boPostLink.SetProperties(
                id,
                model.CreationDate,
                model.LinkTypeId,
                model.PostId,
                model.RelatedPostId);
            return(boPostLink);
        }
Ejemplo n.º 9
0
        private async Task <ApiPostLinkRequestModel> PatchModel(int id, JsonPatchDocument <ApiPostLinkRequestModel> patch)
        {
            var record = await this.PostLinkService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiPostLinkRequestModel request = this.PostLinkModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Ejemplo n.º 10
0
        public void CreatePatch()
        {
            var mapper = new ApiPostLinkModelMapper();
            var model  = new ApiPostLinkRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);

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

            patch.ApplyTo(response);
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LinkTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RelatedPostId.Should().Be(1);
        }
Ejemplo n.º 11
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPostLinkRepository>();
            var model = new ApiPostLinkRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostLink>())).Returns(Task.FromResult(new PostLink()));
            var service = new PostLinkService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLPostLinkMapperMock,
                                              mock.DALMapperMockFactory.DALPostLinkMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostLinkRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PostLink>()));
        }
Ejemplo n.º 12
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IPostLinkRepository>();
            var model = new ApiPostLinkRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PostLinkService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLPostLinkMapperMock,
                                              mock.DALMapperMockFactory.DALPostLinkMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Ejemplo n.º 13
0
        public virtual async Task <UpdateResponse <ApiPostLinkResponseModel> > Update(
            int id,
            ApiPostLinkRequestModel model)
        {
            var validationResult = await this.PostLinkModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolPostLinkMapper.MapModelToBO(id, model);
                await this.PostLinkRepository.Update(this.DalPostLinkMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiPostLinkResponseModel>(this.BolPostLinkMapper.MapBOToModel(this.DalPostLinkMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiPostLinkResponseModel>(validationResult));
            }
        }
Ejemplo n.º 14
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPostLinkRequestModel model)
        {
            ApiPostLinkRequestModel request = await this.PatchModel(id, this.PostLinkModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Ejemplo n.º 15
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPostLinkRequestModel> patch)
        {
            ApiPostLinkResponseModel record = await this.PostLinkService.Get(id);

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

                UpdateResponse <ApiPostLinkResponseModel> result = await this.PostLinkService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Ejemplo n.º 16
0
        public virtual async Task <UpdateResponse <ApiPostLinkResponseModel> > PostLinkUpdateAsync(int id, ApiPostLinkRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/PostLinks/{id}", item).ConfigureAwait(false);

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