Beispiel #1
0
        public void SearchUserIncludingFollowingAndFollowersTest()
        {
            var mockApiWrapperBuilder = new MockMastodonApiWrapperBuilder
            {
                ActiveUserID = "2",
                AllowAddContextToMastodonUsersMethod = true,
                AllowGetMastodonAccountMethod        = true,
            };

            mockApiWrapperBuilder.SetupUsers(1, 2, 11);
            mockApiWrapperBuilder.SetupFollowRelationship(1, 2);
            mockApiWrapperBuilder.SetupFollowRelationship(1, 11);
            mockApiWrapperBuilder.SetupFollowRelationship(2, 11);
            mockApiWrapperBuilder.SetupFollowRelationship(11, 2);

            var mockMastodonApiWrapper = mockApiWrapperBuilder.BuildMockMastodonApiWrapper();
            var herdApp = new HerdApp(_mockData.Object, _mockHashTagRelevanceManager.Object, mockMastodonApiWrapper.Object, _mockLogger.Object);

            var result = herdApp.SearchUsers(new SearchMastodonUsersCommand
            {
                UserID           = "11",
                IncludeFollowers = true,
                IncludeFollowing = true
            });

            Assert.True(result?.Success);
            Assert.Single(result.Data.Users);
            var user = result.Data.Users[0];

            Assert.Equal("11", user.MastodonUserId);

            Assert.Single(user.Following);
            Assert.Equal("2", user.Following[0].MastodonUserId);

            Assert.Equal(2, user.Followers.Count);
            Assert.Equal("1", user.Followers[0].MastodonUserId);
            Assert.Equal("2", user.Followers[1].MastodonUserId);

            mockMastodonApiWrapper.Verify(a => a.AddContextToMastodonUsers(It.IsAny <IEnumerable <MastodonUser> >(), It.IsAny <MastodonUserContextOptions>()), Times.Once());
            mockMastodonApiWrapper.Verify(a => a.GetMastodonAccount(It.IsAny <string>(), It.IsAny <MastodonUserContextOptions>()), Times.Once());
        }
Beispiel #2
0
        public void SearchPostsOnPublicTimelineTest()
        {
            var mockApiWrapperBuilder = new MockMastodonApiWrapperBuilder
            {
                AllowAddContextToMastodonPostMethod  = true,
                AllowAddContextToMastodonPostsMethod = true,
                AllowGetPostsOnPublicTimelineMethod  = true,
                ActiveUserID = "2"
            };

            mockApiWrapperBuilder.SetupUsers(1, 2, 3, 4);
            mockApiWrapperBuilder.SetupFollowRelationship(2, 3);
            mockApiWrapperBuilder.SetupFollowRelationship(2, 4);

            mockApiWrapperBuilder.CreatePost(1, 1);
            mockApiWrapperBuilder.CreatePost(1, 2);
            mockApiWrapperBuilder.CreatePost(2, 3);
            mockApiWrapperBuilder.CreatePost(3, 4);
            mockApiWrapperBuilder.CreatePost(3, 5);
            mockApiWrapperBuilder.CreatePost(4, 6);

            var mockMastodonApiWrapper = mockApiWrapperBuilder.BuildMockMastodonApiWrapper();

            var herdApp = new HerdApp(_mockData.Object, _mockHashTagRelevanceManager.Object, mockMastodonApiWrapper.Object, _mockLogger.Object);

            var result = herdApp.SearchPosts(new SearchMastodonPostsCommand
            {
                OnlyOnPublicTimeline = true
            });

            Assert.True(result?.Success);
            Assert.Equal(5, result.Data.Posts.Count);
            Assert.Equal("1", result.Data.Posts[0].Id);
            Assert.Equal("2", result.Data.Posts[1].Id);
            Assert.Equal("4", result.Data.Posts[2].Id);
            Assert.Equal("5", result.Data.Posts[3].Id);
            Assert.Equal("6", result.Data.Posts[4].Id);

            mockMastodonApiWrapper.Verify(a => a.GetPostsOnPublicTimeline(It.IsAny <MastodonPostContextOptions>(), It.IsAny <PagingOptions>()), Times.Once());
        }