Exemplo 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 ApiFollowerRequestModel();

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

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

            ApiFollowerResponseModel getResponse = await client.FollowerGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.FollowerDeleteAsync(2);

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

            ApiFollowerResponseModel verifyResponse = await client.FollowerGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Exemplo n.º 2
0
        public virtual ApiFollowerResponseModel MapBOToModel(
            BOFollower boFollower)
        {
            var model = new ApiFollowerResponseModel();

            model.SetProperties(boFollower.Id, boFollower.Blocked, boFollower.DateFollowed, boFollower.FollowRequestStatu, boFollower.FollowedUserId, boFollower.FollowingUserId, boFollower.Muted);

            return(model);
        }
Exemplo n.º 3
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiFollowerResponseModel response = await client.FollowerGetAsync(1);

            response.Should().NotBeNull();
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiFollowerResponseModel response = await this.FollowerService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Exemplo n.º 5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiFollowerModelMapper();
            var model  = new ApiFollowerResponseModel();

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

            response.Blocked.Should().Be("A");
            response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FollowRequestStatu.Should().Be("A");
            response.FollowedUserId.Should().Be(1);
            response.FollowingUserId.Should().Be(1);
            response.Muted.Should().Be("A");
        }
Exemplo n.º 6
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IFollowerRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Follower>(null));
            var service = new FollowerService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLFollowerMapperMock,
                                              mock.DALMapperMockFactory.DALFollowerMapperMock);

            ApiFollowerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 7
0
        public void MapBOToModel()
        {
            var        mapper = new BOLFollowerMapper();
            BOFollower bo     = new BOFollower();

            bo.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, "A");
            ApiFollowerResponseModel response = mapper.MapBOToModel(bo);

            response.Blocked.Should().Be("A");
            response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FollowRequestStatu.Should().Be("A");
            response.FollowedUserId.Should().Be(1);
            response.FollowingUserId.Should().Be(1);
            response.Id.Should().Be(1);
            response.Muted.Should().Be("A");
        }
Exemplo n.º 8
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiFollowerResponseModel model = await client.FollowerGetAsync(1);

            ApiFollowerModelMapper mapper = new ApiFollowerModelMapper();

            UpdateResponse <ApiFollowerResponseModel> updateResponse = await client.FollowerUpdateAsync(model.Id, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Exemplo n.º 9
0
        public async void Create_Errors()
        {
            FollowerControllerMockFacade mock = new FollowerControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiFollowerResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiFollowerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFollowerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFollowerResponseModel> >(mockResponse.Object));
            FollowerController controller = new FollowerController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiFollowerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiFollowerRequestModel>()));
        }
Exemplo n.º 10
0
        public async void All_Exists()
        {
            FollowerControllerMockFacade mock = new FollowerControllerMockFacade();
            var record  = new ApiFollowerResponseModel();
            var records = new List <ApiFollowerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            FollowerController controller = new FollowerController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiFollowerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Exemplo n.º 11
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiFollowerRequestModel> patch)
        {
            ApiFollowerResponseModel record = await this.FollowerService.Get(id);

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

                UpdateResponse <ApiFollowerResponseModel> result = await this.FollowerService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }