fix tests
This commit is contained in:
parent
662f97e53c
commit
d1c5a59247
2 changed files with 306 additions and 20 deletions
|
@ -45,14 +45,17 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
catch (UserNotFoundException)
|
||||
{
|
||||
await ProcessNotFoundUserAsync(user);
|
||||
continue;
|
||||
}
|
||||
catch (UserHasBeenSuspendedException)
|
||||
{
|
||||
await ProcessNotFoundUserAsync(user);
|
||||
continue;
|
||||
}
|
||||
catch (RateLimitExceededException)
|
||||
{
|
||||
await ProcessRateLimitExceededAsync(user);
|
||||
continue;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
|
|
@ -159,25 +159,14 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct2)))
|
||||
.Returns((TwitterUser) null);
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.PurgeUser(It.Is<string>(y => y == acct2)));
|
||||
.Throws(new UserNotFoundException());
|
||||
|
||||
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);
|
||||
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);
|
||||
|
@ -194,7 +183,71 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProcessAsync_Unfound_OverThreshold_Test()
|
||||
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.GetUser(It.Is<string>(y => y == acct1)))
|
||||
.Returns(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUser(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_Error_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var userId1 = 1;
|
||||
|
@ -236,8 +289,83 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct2)))
|
||||
.Returns((TwitterUser)null);
|
||||
|
||||
//twitterUserServiceMock
|
||||
// .Setup(x => x.PurgeUser(It.Is<string>(y => y == acct2)));
|
||||
|
||||
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.PurgeUser(It.Is<string>(y => y == acct2)));
|
||||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct1)))
|
||||
.Returns(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct2)))
|
||||
.Returns((TwitterUser)null);
|
||||
|
||||
//twitterUserServiceMock
|
||||
// .Setup(x => x.PurgeUser(It.Is<string>(y => y == acct2)));
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
|
@ -313,7 +441,22 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
Protected = true
|
||||
});
|
||||
|
||||
//twitterUserServiceMock
|
||||
// .Setup(x => x.PurgeUser(It.Is<string>(y => y == acct2)));
|
||||
|
||||
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
|
||||
|
||||
|
@ -331,7 +474,147 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProcessAsync_Unfound_NotInit_Test()
|
||||
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.GetUser(It.Is<string>(y => y == acct1)))
|
||||
.Returns(new TwitterUser
|
||||
{
|
||||
Protected = false
|
||||
});
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct2)))
|
||||
.Returns(new TwitterUser
|
||||
{
|
||||
Protected = true
|
||||
});
|
||||
|
||||
//twitterUserServiceMock
|
||||
// .Setup(x => x.PurgeUser(It.Is<string>(y => y == acct2)));
|
||||
|
||||
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.GetUser(It.Is<string>(y => y == acct1)))
|
||||
// .Returns(new TwitterUser
|
||||
// {
|
||||
// Protected = false
|
||||
// });
|
||||
|
||||
// twitterUserServiceMock
|
||||
// .Setup(x => x.GetUser(It.Is<string>(y => y == acct2)))
|
||||
// .Returns(new TwitterUser
|
||||
// {
|
||||
// Protected = true
|
||||
// });
|
||||
|
||||
// var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
// 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_NotInit_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var userId1 = 1;
|
||||
|
@ -361,8 +644,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct1)))
|
||||
.Returns((TwitterUser)null);
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.PurgeUser(It.Is<string>(y => y == acct1)));
|
||||
//twitterUserServiceMock
|
||||
// .Setup(x => x.PurgeUser(It.Is<string>(y => y == acct1)));
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
|
|
Reference in a new issue