public virtual async void TestCreate()
        {
            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;

            var model = new ApiFollowerClientRequestModel();

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

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

            result.Record.Blocked.Should().Be("B");
            result.Record.DateFollowed.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            result.Record.FollowedUserId.Should().Be(1);
            result.Record.FollowingUserId.Should().Be(1);
            result.Record.FollowRequestStatu.Should().Be("B");
            result.Record.Muted.Should().Be("B");
        }
예제 #2
0
        public virtual ApiFollowerClientRequestModel MapServerResponseToClientRequest(
            ApiFollowerServerResponseModel response)
        {
            var request = new ApiFollowerClientRequestModel();

            request.SetProperties(
                response.Blocked,
                response.DateFollowed,
                response.FollowedUserId,
                response.FollowingUserId,
                response.FollowRequestStatu,
                response.Muted);
            return(request);
        }
        public void MapClientResponseToRequest()
        {
            var mapper = new ApiFollowerModelMapper();
            var model  = new ApiFollowerClientResponseModel();

            model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A");
            ApiFollowerClientRequestModel response = mapper.MapClientResponseToRequest(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 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");
        }