removed pipeline stage
This commit is contained in:
parent
d46efe8812
commit
ea47f2c058
2 changed files with 8 additions and 623 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.Throws(new UserNotFoundException());
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(MockBehavior.Strict);
|
||||
removeTwitterAccountActionMock
|
||||
.Setup(x => x.ProcessAsync(It.Is<SyncTwitterUser>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.Throws(new UserHasBeenSuspendedException());
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(MockBehavior.Strict);
|
||||
removeTwitterAccountActionMock
|
||||
.Setup(x => x.ProcessAsync(It.Is<SyncTwitterUser>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.Throws(new Exception());
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new SyncTwitterUser
|
||||
{
|
||||
Id = userId2,
|
||||
FetchingErrorCount = 0
|
||||
});
|
||||
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.UpdateTwitterUserAsync(It.Is<SyncTwitterUser>(y => y.Id == userId2 && y.FetchingErrorCount == 1)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync((TwitterUser)null);
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new SyncTwitterUser
|
||||
{
|
||||
Id = userId2,
|
||||
FetchingErrorCount = 0
|
||||
});
|
||||
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.UpdateTwitterUserAsync(It.Is<SyncTwitterUser>(y => y.Id == userId2 && y.FetchingErrorCount == 1)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync((TwitterUser)null);
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new SyncTwitterUser
|
||||
{
|
||||
Id = userId2,
|
||||
FetchingErrorCount = 500
|
||||
});
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(MockBehavior.Strict);
|
||||
removeTwitterAccountActionMock
|
||||
.Setup(x => x.ProcessAsync(It.Is<SyncTwitterUser>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = true
|
||||
});
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new SyncTwitterUser
|
||||
{
|
||||
Id = userId2,
|
||||
FetchingErrorCount = 0
|
||||
});
|
||||
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.UpdateTwitterUserAsync(It.Is<SyncTwitterUser>(y => y.Id == userId2 && y.FetchingErrorCount == 1)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = true
|
||||
});
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new SyncTwitterUser
|
||||
{
|
||||
Id = userId2,
|
||||
FetchingErrorCount = 500
|
||||
});
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(MockBehavior.Strict);
|
||||
removeTwitterAccountActionMock
|
||||
.Setup(x => x.ProcessAsync(It.Is<SyncTwitterUser>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync((TwitterUser)null);
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(users.First());
|
||||
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.UpdateTwitterUserAsync(
|
||||
It.Is<SyncTwitterUser>(y => y.Id == userId1 && y.FetchingErrorCount == 1 && y.LastSync != default)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(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<SyncTwitterUser>
|
||||
{
|
||||
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<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(new TwitterUser
|
||||
{
|
||||
Protected = false,
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.Throws(new RateLimitExceededException());
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct2)))
|
||||
.ReturnsAsync(new SyncTwitterUser
|
||||
{
|
||||
Id = userId2,
|
||||
FetchingErrorCount = 20
|
||||
});
|
||||
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.UpdateTwitterUserAsync(It.Is<SyncTwitterUser>(y => y.Id == userId2 && y.FetchingErrorCount == 20)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue