public async Task SocialFollowUnfollowTest()
        {
            // create a client
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            // create user1 and user2
            var postUserResponse1 = await TestUtilities.PostGenericUser(client);

            var postUserResponse2 = await TestUtilities.PostGenericUser(client);

            string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken);
            string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken);

            // user1 creates topic1 and topic2
            var postTopic1 = await TestUtilities.PostGenericTopic(client, auth1);

            var postTopic2 = await TestUtilities.PostGenericTopic(client, auth1);

            // user2 follows user1
            PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse1.UserHandle);
            await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth2);

            // when one user follows another, import of existing topics into the following topics feed
            // is done by a worker
            FeedResponseTopicView followingTopics1 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                // user2 gets the combined following topics feed
                followingTopics1 = await client.MyFollowing.GetTopicsAsync(auth2, null, 10);
            }, () =>
            {
                // wait until two topics are returned or the auto-retry helper times out
                Assert.AreEqual(2, followingTopics1.Data.Count);
            });

            // user2 unfollows user1
            await client.MyFollowing.DeleteFollowingUserAsync(postUserResponse1.UserHandle, auth2);

            // user2 gets the combined following topics feed after user2 unfollows user1
            var followingTopics2 = await client.MyFollowing.GetTopicsAsync(auth2, null, 10);

            // clean up: delete topics and users
            await TestUtilities.DeleteTopic(client, postTopic1.TopicHandle, auth1);

            await TestUtilities.DeleteTopic(client, postTopic2.TopicHandle, auth1);

            await TestUtilities.DeleteUser(client, auth1);

            await TestUtilities.DeleteUser(client, auth2);

            // validate: check that followingTopics1 contains both topics and followingTopics2 is empty
            Assert.AreEqual(2, followingTopics1.Data.Count);
            Assert.AreEqual(0, followingTopics2.Data.Count);

            Assert.AreEqual(postTopic2.TopicHandle, followingTopics1.Data[0].TopicHandle);
            Assert.AreEqual(FollowerStatus.Follow, followingTopics1.Data[0].User.FollowerStatus);
            Assert.AreEqual(postTopic1.TopicHandle, followingTopics1.Data[1].TopicHandle);
            Assert.AreEqual(FollowerStatus.Follow, followingTopics1.Data[1].User.FollowerStatus);
        }
Ejemplo n.º 2
0
        public async Task GetTopicsForUserUsingHandleTest()
        {
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

            var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken);

            var httpResponse1 = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle1 = httpResponse1.TopicHandle;

            var httpResponse2 = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle2 = httpResponse2.TopicHandle;

            // get the topics for this user
            FeedResponseTopicView topicListResponse = await client.UserTopics.GetTopicsAsync(user.UserHandle, auth, cursor : null, limit : 2);

            // Delete Topics
            await client.Topics.DeleteTopicAsync(topicHandle1, auth);

            await client.Topics.DeleteTopicAsync(topicHandle2, auth);

            // Delete user
            await TestUtilities.DeleteUser(client, auth);

            Assert.AreEqual(2, topicListResponse.Data.Count);
        }
Ejemplo n.º 3
0
        public async Task PopularUserTopicsTest_UsingUserHandle()
        {
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

            var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken);

            var httpResponse1 = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle1 = httpResponse1.TopicHandle;

            var httpResponse2 = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle2 = httpResponse2.TopicHandle;

            await client.TopicLikes.PostLikeAsync(topicHandle1, auth);

            // Wait for Service Bus - wait for the one and other checks will be ok as just a check of same data
            FeedResponseTopicView popularTopics1 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                // Get before delete it
                popularTopics1 = await client.MyTopics.GetPopularTopicsAsync(auth, null, 10);
            }, () =>
            {
                Assert.AreEqual(2, popularTopics1.Data.Count);
            });

            FeedResponseTopicView popularTopics2 = await client.UserTopics.GetPopularTopicsAsync(user.UserHandle, auth, null, 1);

            FeedResponseTopicView popularTopics3 = await client.UserTopics.GetPopularTopicsAsync(user.UserHandle, auth, int.Parse(popularTopics2.Cursor), 1);

            // Now Delete and check it
            await client.Topics.DeleteTopicAsync(topicHandle1, auth);

            // Wait for Service Bus
            FeedResponseTopicView popularTopics4 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                // Get before delete it
                popularTopics4 = await client.UserTopics.GetPopularTopicsAsync(user.UserHandle, auth, null, 10);
            }, () =>
            {
                Assert.AreEqual(1, popularTopics4.Data.Count);
            });

            // Delete another one and check again
            await client.Topics.DeleteTopicAsync(topicHandle2, auth);

            // Wait for Service Bus
            FeedResponseTopicView popularTopics5 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                // Get before delete it
                popularTopics5 = await client.UserTopics.GetPopularTopicsAsync(user.UserHandle, auth, null, 10);
            }, () =>
            {
                Assert.AreEqual(0, popularTopics5.Data.Count);
            });

            // final clean up
            await client.Users.DeleteUserAsync(auth);

            // Verify everything
            Assert.AreEqual(2, popularTopics1.Data.Count);
            Assert.AreEqual(1, popularTopics1.Data[0].TotalLikes);

            Assert.AreEqual(1, popularTopics2.Data.Count);
            Assert.AreEqual(1, popularTopics2.Data[0].TotalLikes);

            Assert.AreEqual(1, popularTopics3.Data.Count);
            Assert.AreEqual(0, popularTopics3.Data[0].TotalLikes);

            Assert.AreEqual(1, popularTopics4.Data.Count);
            Assert.AreEqual(0, popularTopics4.Data[0].TotalLikes);

            Assert.AreEqual(0, popularTopics5.Data.Count);
        }
Ejemplo n.º 4
0
        public async Task PopularUserTopicsTest()
        {
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

            var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken);

            var httpResponse1 = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle1 = httpResponse1.TopicHandle;

            var httpResponse2 = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle2 = httpResponse2.TopicHandle;

            await client.TopicLikes.PostLikeAsync(topicHandle1, auth);

            // Wait for Service Bus to update things since topic just deleted
            FeedResponseTopicView popularTopics1 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                popularTopics1 = await client.MyTopics.GetPopularTopicsAsync(auth, null, 10);
            }, () =>
            {
                Assert.AreEqual(2, popularTopics1.Data.Count);
            });

            // Get Popular User Topics
            FeedResponseTopicView popularTopics2 = await client.MyTopics.GetPopularTopicsAsync(auth, null, 10);

            FeedResponseTopicView popularTopics3 = await client.MyTopics.GetPopularTopicsAsync(auth, int.Parse(popularTopics2.Cursor), 1);

            // Delete then check
            await client.Topics.DeleteTopicAsync(topicHandle1, auth);

            // Wait for Service Bus to update things since topic just deleted
            FeedResponseTopicView popularTopics4 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                popularTopics4 = await client.MyTopics.GetPopularTopicsAsync(auth, null, 10);
            }, () =>
            {
                Assert.AreEqual(1, popularTopics4.Data.Count);
            });

            // Delete then check
            await client.Topics.DeleteTopicAsync(topicHandle2, auth);

            // Check but wait for Service Bus
            FeedResponseTopicView popularTopics5 = null;
            await TestUtilities.AutoRetryServiceBusHelper(
                async() =>
            {
                popularTopics5 = await client.MyTopics.GetPopularTopicsAsync(auth, null, 10);
            }, () =>
            {
                Assert.AreEqual(1, popularTopics5.Data.Count);
            });

            await client.Users.DeleteUserAsync(auth);

            // Verify
            Assert.AreEqual(2, popularTopics1.Data.Count);
            Assert.AreEqual(1, popularTopics1.Data[0].TotalLikes);
            Assert.AreEqual(true, popularTopics1.Data[0].Liked);
            Assert.AreEqual(0, popularTopics1.Data[1].TotalLikes);
            Assert.AreEqual(false, popularTopics1.Data[1].Liked);

            Assert.AreEqual(1, popularTopics2.Data.Count);
            Assert.AreEqual(1, popularTopics2.Data[0].TotalLikes);
            Assert.AreEqual(true, popularTopics2.Data[0].Liked);

            Assert.AreEqual(1, popularTopics3.Data.Count);
            Assert.AreEqual(0, popularTopics3.Data[0].TotalLikes);
            Assert.AreEqual(false, popularTopics3.Data[0].Liked);

            Assert.AreEqual(1, popularTopics4.Data.Count);
            Assert.AreEqual(0, popularTopics4.Data[0].TotalLikes);
            Assert.AreEqual(false, popularTopics4.Data[0].Liked);

            Assert.AreEqual(0, popularTopics5.Data.Count);
        }