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

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

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

            ApiTweetResponseModel getResponse = await client.TweetGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TweetDeleteAsync(2);

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

            ApiTweetResponseModel verifyResponse = await client.TweetGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Beispiel #2
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTweetRequestModel model)
 {
     this.ContentRules();
     this.DateRules();
     this.LocationIdRules();
     this.TimeRules();
     this.UserUserIdRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiTweetResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiTweetRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #4
0
        public virtual async Task <IActionResult> Create([FromBody] ApiTweetRequestModel model)
        {
            CreateResponse <ApiTweetResponseModel> result = await this.TweetService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Tweets/{result.Record.TweetId}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Beispiel #5
0
        public void MapModelToBO()
        {
            var mapper = new BOLTweetMapper();
            ApiTweetRequestModel model = new ApiTweetRequestModel();

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

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LocationId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("0"));
            response.UserUserId.Should().Be(1);
        }
Beispiel #6
0
        private async Task <ApiTweetRequestModel> PatchModel(int id, JsonPatchDocument <ApiTweetRequestModel> patch)
        {
            var record = await this.TweetService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTweetRequestModel request = this.TweetModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiTweetResponseModel> > Create(
            ApiTweetRequestModel model)
        {
            CreateResponse <ApiTweetResponseModel> response = new CreateResponse <ApiTweetResponseModel>(await this.TweetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolTweetMapper.MapModelToBO(default(int), model);
                var record = await this.TweetRepository.Create(this.DalTweetMapper.MapBOToEF(bo));

                response.SetRecord(this.BolTweetMapper.MapBOToModel(this.DalTweetMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public virtual BOTweet MapModelToBO(
            int tweetId,
            ApiTweetRequestModel model
            )
        {
            BOTweet boTweet = new BOTweet();

            boTweet.SetProperties(
                tweetId,
                model.Content,
                model.Date,
                model.LocationId,
                model.Time,
                model.UserUserId);
            return(boTweet);
        }
        public void CreatePatch()
        {
            var mapper = new ApiTweetModelMapper();
            var model  = new ApiTweetRequestModel();

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

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

            patch.ApplyTo(response);
            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LocationId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("0"));
            response.UserUserId.Should().Be(1);
        }
        public virtual async Task <UpdateResponse <ApiTweetResponseModel> > Update(
            int tweetId,
            ApiTweetRequestModel model)
        {
            var validationResult = await this.TweetModelValidator.ValidateUpdateAsync(tweetId, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolTweetMapper.MapModelToBO(tweetId, model);
                await this.TweetRepository.Update(this.DalTweetMapper.MapBOToEF(bo));

                var record = await this.TweetRepository.Get(tweetId);

                return(new UpdateResponse <ApiTweetResponseModel>(this.BolTweetMapper.MapBOToModel(this.DalTweetMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTweetResponseModel>(validationResult));
            }
        }
Beispiel #11
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTweetRequestModel model)
        {
            ApiTweetRequestModel request = await this.PatchModel(id, this.TweetModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #12
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITweetRepository>();
            var model = new ApiTweetRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Tweet>())).Returns(Task.FromResult(new Tweet()));
            var service = new TweetService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.TweetModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLTweetMapperMock,
                                           mock.DALMapperMockFactory.DALTweetMapperMock,
                                           mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock,
                                           mock.DALMapperMockFactory.DALQuoteTweetMapperMock,
                                           mock.BOLMapperMockFactory.BOLRetweetMapperMock,
                                           mock.DALMapperMockFactory.DALRetweetMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTweetRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Tweet>()));
        }
Beispiel #13
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITweetRepository>();
            var model = new ApiTweetRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new TweetService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.TweetModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLTweetMapperMock,
                                           mock.DALMapperMockFactory.DALTweetMapperMock,
                                           mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock,
                                           mock.DALMapperMockFactory.DALQuoteTweetMapperMock,
                                           mock.BOLMapperMockFactory.BOLRetweetMapperMock,
                                           mock.DALMapperMockFactory.DALRetweetMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TweetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTweetRequestModel> patch)
        {
            ApiTweetResponseModel record = await this.TweetService.Get(id);

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

                UpdateResponse <ApiTweetResponseModel> result = await this.TweetService.Update(id, model);

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

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