public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IFollowerService service = testServer.Host.Services.GetService(typeof(IFollowerService)) as IFollowerService;
            var model = new ApiFollowerServerRequestModel();

            model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, "B", "B");
            CreateResponse <ApiFollowerServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.FollowerDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiFollowerServerResponseModel verifyResponse = await service.Get(2);

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

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IFollowerService, IFollowerRepository>();

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

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiFollowerServerModelMapper();
            var model  = new ApiFollowerServerResponseModel();

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

            response.Should().NotBeNull();
            response.Blocked.Should().Be("A");
            response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FollowedUserId.Should().Be(1);
            response.FollowingUserId.Should().Be(1);
            response.FollowRequestStatu.Should().Be("A");
            response.Muted.Should().Be("A");
        }
        public async void Create_Errors()
        {
            FollowerControllerMockFacade mock = new FollowerControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiFollowerServerResponseModel> >(null as ApiFollowerServerResponseModel);
            var mockRecord   = new ApiFollowerServerResponseModel();

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFollowerServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFollowerServerResponseModel> >(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 ApiFollowerServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiFollowerServerRequestModel>()));
        }
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiFollowerServerModelMapper();
            ApplicationDbContext           context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IFollowerService               service = testServer.Host.Services.GetService(typeof(IFollowerService)) as IFollowerService;
            ApiFollowerServerResponseModel model   = await service.Get(1);

            ApiFollowerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, "B", "B");

            UpdateResponse <ApiFollowerClientResponseModel> updateResponse = await client.FollowerUpdateAsync(model.Id, request);

            context.Entry(context.Set <Follower>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Follower>().ToList()[0].Blocked.Should().Be("B");
            context.Set <Follower>().ToList()[0].DateFollowed.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Follower>().ToList()[0].FollowedUserId.Should().Be(1);
            context.Set <Follower>().ToList()[0].FollowingUserId.Should().Be(1);
            context.Set <Follower>().ToList()[0].FollowRequestStatu.Should().Be("B");
            context.Set <Follower>().ToList()[0].Muted.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Blocked.Should().Be("B");
            updateResponse.Record.DateFollowed.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.FollowedUserId.Should().Be(1);
            updateResponse.Record.FollowingUserId.Should().Be(1);
            updateResponse.Record.FollowRequestStatu.Should().Be("B");
            updateResponse.Record.Muted.Should().Be("B");
        }
        public async void All_Exists()
        {
            FollowerControllerMockFacade mock = new FollowerControllerMockFacade();
            var record  = new ApiFollowerServerResponseModel();
            var records = new List <ApiFollowerServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).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, string.Empty);

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

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

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

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

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