Beispiel #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 ApiFollowingRequestModel();

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

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

            ApiFollowingResponseModel getResponse = await client.FollowingGetAsync("B");

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.FollowingDeleteAsync("B");

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

            ApiFollowingResponseModel verifyResponse = await client.FollowingGetAsync("B");

            verifyResponse.Should().BeNull();
        }
Beispiel #2
0
        private async Task <ApiFollowingResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiFollowingRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #3
0
        public void MapModelToBO()
        {
            var mapper = new BOLFollowingMapper();
            ApiFollowingRequestModel model = new ApiFollowingRequestModel();

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

            response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Muted.Should().Be("A");
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiFollowingModelMapper();
            var model  = new ApiFollowingResponseModel();

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

            response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Muted.Should().Be("A");
        }
Beispiel #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiFollowingRequestModel model)
        {
            CreateResponse <ApiFollowingResponseModel> result = await this.FollowingService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Followings/{result.Record.UserId}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOFollowing MapModelToBO(
            string userId,
            ApiFollowingRequestModel model
            )
        {
            BOFollowing boFollowing = new BOFollowing();

            boFollowing.SetProperties(
                userId,
                model.DateFollowed,
                model.Muted);
            return(boFollowing);
        }
        public void CreatePatch()
        {
            var mapper = new ApiFollowingModelMapper();
            var model  = new ApiFollowingRequestModel();

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

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

            patch.ApplyTo(response);
            response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Muted.Should().Be("A");
        }
Beispiel #8
0
        private async Task <ApiFollowingRequestModel> PatchModel(string id, JsonPatchDocument <ApiFollowingRequestModel> patch)
        {
            var record = await this.FollowingService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiFollowingRequestModel request = this.FollowingModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #9
0
        public virtual async Task <CreateResponse <ApiFollowingResponseModel> > Create(
            ApiFollowingRequestModel model)
        {
            CreateResponse <ApiFollowingResponseModel> response = new CreateResponse <ApiFollowingResponseModel>(await this.FollowingModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolFollowingMapper.MapModelToBO(default(string), model);
                var record = await this.FollowingRepository.Create(this.DalFollowingMapper.MapBOToEF(bo));

                response.SetRecord(this.BolFollowingMapper.MapBOToModel(this.DalFollowingMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IFollowingRepository>();
            var model = new ApiFollowingRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Following>())).Returns(Task.FromResult(new Following()));
            var service = new FollowingService(mock.LoggerMock.Object,
                                               mock.RepositoryMock.Object,
                                               mock.ModelValidatorMockFactory.FollowingModelValidatorMock.Object,
                                               mock.BOLMapperMockFactory.BOLFollowingMapperMock,
                                               mock.DALMapperMockFactory.DALFollowingMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.FollowingModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFollowingRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Following>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IFollowingRepository>();
            var model = new ApiFollowingRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new FollowingService(mock.LoggerMock.Object,
                                               mock.RepositoryMock.Object,
                                               mock.ModelValidatorMockFactory.FollowingModelValidatorMock.Object,
                                               mock.BOLMapperMockFactory.BOLFollowingMapperMock,
                                               mock.DALMapperMockFactory.DALFollowingMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.FollowingModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
Beispiel #12
0
        public virtual async Task <UpdateResponse <ApiFollowingResponseModel> > Update(
            string userId,
            ApiFollowingRequestModel model)
        {
            var validationResult = await this.FollowingModelValidator.ValidateUpdateAsync(userId, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolFollowingMapper.MapModelToBO(userId, model);
                await this.FollowingRepository.Update(this.DalFollowingMapper.MapBOToEF(bo));

                var record = await this.FollowingRepository.Get(userId);

                return(new UpdateResponse <ApiFollowingResponseModel>(this.BolFollowingMapper.MapBOToModel(this.DalFollowingMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiFollowingResponseModel>(validationResult));
            }
        }
Beispiel #13
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiFollowingRequestModel model)
        {
            ApiFollowingRequestModel request = await this.PatchModel(id, this.FollowingModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #14
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiFollowingRequestModel> patch)
        {
            ApiFollowingResponseModel record = await this.FollowingService.Get(id);

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

                UpdateResponse <ApiFollowingResponseModel> result = await this.FollowingService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiFollowingRequestModel model)
 {
     this.DateFollowedRules();
     this.MutedRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #16
0
        public virtual async Task <UpdateResponse <ApiFollowingResponseModel> > FollowingUpdateAsync(string id, ApiFollowingRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Followings/{id}", item).ConfigureAwait(false);

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