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

            createModel.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, TimeSpan.Parse("1"));
            CreateResponse <ApiQuoteTweetResponseModel> createResult = await client.QuoteTweetCreateAsync(createModel);

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

            ApiQuoteTweetResponseModel getResponse = await client.QuoteTweetGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.QuoteTweetDeleteAsync(2);

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

            ApiQuoteTweetResponseModel verifyResponse = await client.QuoteTweetGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Пример #2
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiQuoteTweetRequestModel model)
 {
     this.ContentRules();
     this.DateRules();
     this.RetweeterUserIdRules();
     this.SourceTweetIdRules();
     this.TimeRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiQuoteTweetResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiQuoteTweetRequestModel();

            model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, TimeSpan.Parse("1"));
            CreateResponse <ApiQuoteTweetResponseModel> result = await client.QuoteTweetCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiQuoteTweetRequestModel model)
        {
            CreateResponse <ApiQuoteTweetResponseModel> result = await this.QuoteTweetService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/QuoteTweets/{result.Record.QuoteTweetId}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Пример #5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiQuoteTweetModelMapper();
            var model  = new ApiQuoteTweetResponseModel();

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

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.RetweeterUserId.Should().Be(1);
            response.SourceTweetId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("0"));
        }
        public virtual async Task <CreateResponse <ApiQuoteTweetResponseModel> > Create(
            ApiQuoteTweetRequestModel model)
        {
            CreateResponse <ApiQuoteTweetResponseModel> response = new CreateResponse <ApiQuoteTweetResponseModel>(await this.QuoteTweetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolQuoteTweetMapper.MapModelToBO(default(int), model);
                var record = await this.QuoteTweetRepository.Create(this.DalQuoteTweetMapper.MapBOToEF(bo));

                response.SetRecord(this.BolQuoteTweetMapper.MapBOToModel(this.DalQuoteTweetMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiQuoteTweetRequestModel request = this.QuoteTweetModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Пример #8
0
        public virtual BOQuoteTweet MapModelToBO(
            int quoteTweetId,
            ApiQuoteTweetRequestModel model
            )
        {
            BOQuoteTweet boQuoteTweet = new BOQuoteTweet();

            boQuoteTweet.SetProperties(
                quoteTweetId,
                model.Content,
                model.Date,
                model.RetweeterUserId,
                model.SourceTweetId,
                model.Time);
            return(boQuoteTweet);
        }
Пример #9
0
        public void CreatePatch()
        {
            var mapper = new ApiQuoteTweetModelMapper();
            var model  = new ApiQuoteTweetRequestModel();

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

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

            patch.ApplyTo(response);
            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.RetweeterUserId.Should().Be(1);
            response.SourceTweetId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("0"));
        }
Пример #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IQuoteTweetRepository>();
            var model = new ApiQuoteTweetRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <QuoteTweet>())).Returns(Task.FromResult(new QuoteTweet()));
            var service = new QuoteTweetService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock,
                                                mock.DALMapperMockFactory.DALQuoteTweetMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiQuoteTweetRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <QuoteTweet>()));
        }
Пример #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IQuoteTweetRepository>();
            var model = new ApiQuoteTweetRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new QuoteTweetService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock,
                                                mock.DALMapperMockFactory.DALQuoteTweetMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Пример #12
0
        public virtual async Task <UpdateResponse <ApiQuoteTweetResponseModel> > Update(
            int quoteTweetId,
            ApiQuoteTweetRequestModel model)
        {
            var validationResult = await this.QuoteTweetModelValidator.ValidateUpdateAsync(quoteTweetId, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolQuoteTweetMapper.MapModelToBO(quoteTweetId, model);
                await this.QuoteTweetRepository.Update(this.DalQuoteTweetMapper.MapBOToEF(bo));

                var record = await this.QuoteTweetRepository.Get(quoteTweetId);

                return(new UpdateResponse <ApiQuoteTweetResponseModel>(this.BolQuoteTweetMapper.MapBOToModel(this.DalQuoteTweetMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiQuoteTweetResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiQuoteTweetRequestModel model)
        {
            ApiQuoteTweetRequestModel request = await this.PatchModel(id, this.QuoteTweetModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiQuoteTweetResponseModel> result = await this.QuoteTweetService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #15
0
        public virtual async Task <UpdateResponse <ApiQuoteTweetResponseModel> > QuoteTweetUpdateAsync(int id, ApiQuoteTweetRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/QuoteTweets/{id}", item).ConfigureAwait(false);

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