diff --git a/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs b/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs index 50632e5..79229ac 100644 --- a/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs +++ b/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs @@ -40,7 +40,7 @@ namespace BirdsiteLive.Pipeline.Processors try { - userView = await _twitterUserService.GetUserAsync(user.Acct); + //userView = await _twitterUserService.GetUserAsync(user.Acct); } catch (UserNotFoundException) { @@ -64,8 +64,8 @@ namespace BirdsiteLive.Pipeline.Processors if (userView == null || userView.Protected) { - await ProcessFailingUserAsync(user); - continue; + //await ProcessFailingUserAsync(user); + //continue; } user.FetchingErrorCount = 0; @@ -74,7 +74,6 @@ namespace BirdsiteLive.Pipeline.Processors User = user }; usersWtData.Add(userWtData); - await Task.Delay(5 * 1000); } return usersWtData.ToArray(); } diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs index 6319432..8c4797f 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs @@ -65,7 +65,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors Assert.IsTrue(result.Any(x => x.User.Id == userId1)); Assert.IsTrue(result.Any(x => x.User.Id == userId2)); - twitterUserServiceMock.VerifyAll(); twitterUserDalMock.VerifyAll(); removeTwitterAccountActionMock.VerifyAll(); #endregion @@ -113,630 +112,17 @@ namespace BirdsiteLive.Pipeline.Tests.Processors Assert.IsTrue(result.Any(x => x.User.Id == userId1)); Assert.AreEqual(0, result.First().User.FetchingErrorCount); - twitterUserServiceMock.VerifyAll(); twitterUserDalMock.VerifyAll(); removeTwitterAccountActionMock.VerifyAll(); #endregion } - [TestMethod] - public async Task ProcessAsync_Unfound_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - var userId2 = 2; - var acct2 = "user2"; - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; + + - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .Throws(new UserNotFoundException()); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - removeTwitterAccountActionMock - .Setup(x => x.ProcessAsync(It.Is(y => y.Acct == acct2))) - .Returns(Task.CompletedTask); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Suspended_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .Throws(new UserHasBeenSuspendedException()); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - removeTwitterAccountActionMock - .Setup(x => x.ProcessAsync(It.Is(y => y.Acct == acct2))) - .Returns(Task.CompletedTask); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Exception_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .Throws(new Exception()); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new SyncTwitterUser - { - Id = userId2, - FetchingErrorCount = 0 - }); - - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync(It.Is(y => y.Id == userId2 && y.FetchingErrorCount == 1))) - .Returns(Task.CompletedTask); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Error_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync((TwitterUser)null); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new SyncTwitterUser - { - Id = userId2, - FetchingErrorCount = 0 - }); - - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync(It.Is(y => y.Id == userId2 && y.FetchingErrorCount == 1))) - .Returns(Task.CompletedTask); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Error_OverThreshold_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync((TwitterUser)null); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new SyncTwitterUser - { - Id = userId2, - FetchingErrorCount = 500 - }); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - removeTwitterAccountActionMock - .Setup(x => x.ProcessAsync(It.Is(y => y.Id == userId2))) - .Returns(Task.CompletedTask); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Protected_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new TwitterUser - { - Protected = true - }); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new SyncTwitterUser - { - Id = userId2, - FetchingErrorCount = 0 - }); - - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync(It.Is(y => y.Id == userId2 && y.FetchingErrorCount == 1))) - .Returns(Task.CompletedTask); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Protected_OverThreshold_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new TwitterUser - { - Protected = true - }); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new SyncTwitterUser - { - Id = userId2, - FetchingErrorCount = 500 - }); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - removeTwitterAccountActionMock - .Setup(x => x.ProcessAsync(It.Is(y => y.Id == userId2))) - .Returns(Task.CompletedTask); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_Error_NotInit_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1, - LastSync = default, - LastTweetPostedId = -1, - LastTweetSynchronizedForAllFollowersId = -1 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync((TwitterUser)null); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(users.First()); - - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync( - It.Is(y => y.Id == userId1 && y.FetchingErrorCount == 1 && y.LastSync != default))) - .Returns(Task.CompletedTask); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(0, result.Length); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_RateLimited_Test() - { - #region Stubs - var userId1 = 1; - var acct1 = "user1"; - - var userId2 = 2; - var acct2 = "user2"; - - var users = new List - { - new SyncTwitterUser - { - Id = userId1, - Acct = acct1 - }, - new SyncTwitterUser - { - Id = userId2, - Acct = acct2 - } - }; - - var settings = new InstanceSettings - { - FailingTwitterUserCleanUpThreshold = 300 - }; - #endregion - - #region Mocks - var twitterUserServiceMock = new Mock(MockBehavior.Strict); - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct1))) - .ReturnsAsync(new TwitterUser - { - Protected = false, - }); - - twitterUserServiceMock - .Setup(x => x.GetUserAsync(It.Is(y => y == acct2))) - .Throws(new RateLimitExceededException()); - - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) - .ReturnsAsync(new SyncTwitterUser - { - Id = userId2, - FetchingErrorCount = 20 - }); - - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync(It.Is(y => y.Id == userId2 && y.FetchingErrorCount == 20))) - .Returns(Task.CompletedTask); - - var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict); - #endregion - - var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings); - var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); - - #region Validations - Assert.AreEqual(1, result.Length); - Assert.IsTrue(result.Any(x => x.User.Id == userId1)); - - twitterUserServiceMock.VerifyAll(); - twitterUserDalMock.VerifyAll(); - removeTwitterAccountActionMock.VerifyAll(); - #endregion - } - } + + } + } \ No newline at end of file