Beispiel #1
0
        public void SearchPostsByHashTagTest()
        {
            var mockApiWrapperBuilder = new MockMastodonApiWrapperBuilder
            {
                AllowAddContextToMastodonPostMethod  = true,
                AllowAddContextToMastodonPostsMethod = true,
                AllowGetPostsByHashTagMethod         = true,
                ActiveUserID = "2"
            };

            mockApiWrapperBuilder.SetupUsers(1, 2);
            mockApiWrapperBuilder.CreatePost(1, 1);
            mockApiWrapperBuilder.CreatePost(1, 2);
            mockApiWrapperBuilder.CreatePost(2, 3);

            var mockMastodonApiWrapper = mockApiWrapperBuilder.BuildMockMastodonApiWrapper();

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

            var result = herdApp.SearchPosts(new SearchMastodonPostsCommand
            {
                HavingHashTag = "#post_2"
            });

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

            mockMastodonApiWrapper.Verify(a => a.GetPostsByHashTag(It.IsAny <string>(), It.IsAny <MastodonPostContextOptions>(), It.IsAny <PagingOptions>()), Times.Once());
        }
Beispiel #2
0
        public void SystemErrorHandledCorrectlyTest()
        {
            var herdApp = new HerdApp(_mockData.Object, _mockHashTagRelevanceManager.Object, _mockMastodonApiWrapper.Object, _mockLogger.Object);
            var result  = herdApp.SearchPosts(null);

            Assert.False(result?.Success);
            Assert.True(result.HasSystemErrors);
            Assert.False(result.HasUserErrors);
            Assert.Single(result.Errors);
            Assert.Empty(result.UserErrors);
            Assert.Single(result.SystemErrors);
            Assert.Contains(new NullReferenceException().Message, result.SystemErrors.First().Message);
        }
Beispiel #3
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());
        }