mirror of
https://github.com/NicolasConstant/BirdsiteLive
synced 2025-06-05 21:49:16 +02:00
adding tests for new pipeline
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="Processors\TweetsCleanUp\" />
|
||||||
<Folder Include="Tools\" />
|
<Folder Include="Tools\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ using BirdsiteLive.Twitter.Models;
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
namespace BirdsiteLive.Pipeline.Tests.Processors
|
namespace BirdsiteLive.Pipeline.Tests.Processors.Federation
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class RefreshTwitterUserStatusProcessorTests
|
public class RefreshTwitterUserStatusProcessorTests
|
||||||
@@ -60,7 +60,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||||||
var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None);
|
var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None);
|
||||||
|
|
||||||
#region Validations
|
#region Validations
|
||||||
Assert.AreEqual(2 , result.Length);
|
Assert.AreEqual(2, result.Length);
|
||||||
Assert.IsTrue(result.Any(x => x.User.Id == userId1));
|
Assert.IsTrue(result.Any(x => x.User.Id == userId1));
|
||||||
Assert.IsTrue(result.Any(x => x.User.Id == userId2));
|
Assert.IsTrue(result.Any(x => x.User.Id == userId2));
|
||||||
|
|
@@ -9,7 +9,7 @@ using BirdsiteLive.Pipeline.Processors.Federation;
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
namespace BirdsiteLive.Pipeline.Tests.Processors
|
namespace BirdsiteLive.Pipeline.Tests.Processors.Federation
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class RetrieveFollowersProcessorTests
|
public class RetrieveFollowersProcessorTests
|
@@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
namespace BirdsiteLive.Pipeline.Tests.Processors
|
namespace BirdsiteLive.Pipeline.Tests.Processors.Federation
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class RetrieveTwitterUsersProcessorTests
|
public class RetrieveTwitterUsersProcessorTests
|
||||||
@@ -190,7 +190,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||||||
|
|
||||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
|
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
|
||||||
processor.WaitFactor = 1;
|
processor.WaitFactor = 1;
|
||||||
var t =processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
|
var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
|
||||||
|
|
||||||
await Task.WhenAny(t, Task.Delay(50));
|
await Task.WhenAny(t, Task.Delay(50));
|
||||||
|
|
@@ -0,0 +1,160 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using BirdsiteLive.DAL.Models;
|
||||||
|
using BirdsiteLive.Domain;
|
||||||
|
using BirdsiteLive.Pipeline.Models;
|
||||||
|
using BirdsiteLive.Pipeline.Processors.Federation;
|
||||||
|
using BirdsiteLive.Pipeline.Processors.TweetsCleanUp;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Moq;
|
||||||
|
|
||||||
|
namespace BirdsiteLive.Pipeline.Tests.Processors.TweetsCleanUp
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class DeleteTweetsProcessorTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Process_DeleteTweet_Test()
|
||||||
|
{
|
||||||
|
#region Stubs
|
||||||
|
var tweetId = 42;
|
||||||
|
var tweet = new TweetToDelete
|
||||||
|
{
|
||||||
|
Tweet = new SyncTweet
|
||||||
|
{
|
||||||
|
Id = tweetId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mocks
|
||||||
|
var serviceMock = new Mock<IActivityPubService>(MockBehavior.Strict);
|
||||||
|
serviceMock
|
||||||
|
.Setup(x => x.DeleteNoteAsync(It.Is<SyncTweet>(y => y.Id == tweetId)))
|
||||||
|
.Returns(Task.CompletedTask);
|
||||||
|
|
||||||
|
var loggerMock = new Mock<ILogger<DeleteTweetsProcessor>>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object);
|
||||||
|
var result = await processor.ProcessAsync(tweet, CancellationToken.None);
|
||||||
|
|
||||||
|
#region Validations
|
||||||
|
serviceMock.VerifyAll();
|
||||||
|
loggerMock.VerifyAll();
|
||||||
|
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
Assert.IsTrue(result.DeleteSuccessful);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Process_DeleteTweet_NotFound_Test()
|
||||||
|
{
|
||||||
|
#region Stubs
|
||||||
|
var tweetId = 42;
|
||||||
|
var tweet = new TweetToDelete
|
||||||
|
{
|
||||||
|
Tweet = new SyncTweet
|
||||||
|
{
|
||||||
|
Id = tweetId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mocks
|
||||||
|
var serviceMock = new Mock<IActivityPubService>(MockBehavior.Strict);
|
||||||
|
serviceMock
|
||||||
|
.Setup(x => x.DeleteNoteAsync(It.Is<SyncTweet>(y => y.Id == tweetId)))
|
||||||
|
.Throws(new HttpRequestException("not found", null, HttpStatusCode.NotFound));
|
||||||
|
|
||||||
|
var loggerMock = new Mock<ILogger<DeleteTweetsProcessor>>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object);
|
||||||
|
var result = await processor.ProcessAsync(tweet, CancellationToken.None);
|
||||||
|
|
||||||
|
#region Validations
|
||||||
|
serviceMock.VerifyAll();
|
||||||
|
loggerMock.VerifyAll();
|
||||||
|
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
Assert.IsTrue(result.DeleteSuccessful);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Process_DeleteTweet_HttpError_Test()
|
||||||
|
{
|
||||||
|
#region Stubs
|
||||||
|
var tweetId = 42;
|
||||||
|
var tweet = new TweetToDelete
|
||||||
|
{
|
||||||
|
Tweet = new SyncTweet
|
||||||
|
{
|
||||||
|
Id = tweetId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mocks
|
||||||
|
var serviceMock = new Mock<IActivityPubService>(MockBehavior.Strict);
|
||||||
|
serviceMock
|
||||||
|
.Setup(x => x.DeleteNoteAsync(It.Is<SyncTweet>(y => y.Id == tweetId)))
|
||||||
|
.Throws(new HttpRequestException("bad gateway", null, HttpStatusCode.BadGateway));
|
||||||
|
|
||||||
|
var loggerMock = new Mock<ILogger<DeleteTweetsProcessor>>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object);
|
||||||
|
var result = await processor.ProcessAsync(tweet, CancellationToken.None);
|
||||||
|
|
||||||
|
#region Validations
|
||||||
|
serviceMock.VerifyAll();
|
||||||
|
loggerMock.VerifyAll();
|
||||||
|
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
Assert.IsFalse(result.DeleteSuccessful);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Process_DeleteTweet_GenericException_Test()
|
||||||
|
{
|
||||||
|
#region Stubs
|
||||||
|
var tweetId = 42;
|
||||||
|
var tweet = new TweetToDelete
|
||||||
|
{
|
||||||
|
Tweet = new SyncTweet
|
||||||
|
{
|
||||||
|
Id = tweetId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mocks
|
||||||
|
var serviceMock = new Mock<IActivityPubService>(MockBehavior.Strict);
|
||||||
|
serviceMock
|
||||||
|
.Setup(x => x.DeleteNoteAsync(It.Is<SyncTweet>(y => y.Id == tweetId)))
|
||||||
|
.Throws(new Exception());
|
||||||
|
|
||||||
|
var loggerMock = new Mock<ILogger<DeleteTweetsProcessor>>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object);
|
||||||
|
var result = await processor.ProcessAsync(tweet, CancellationToken.None);
|
||||||
|
|
||||||
|
#region Validations
|
||||||
|
serviceMock.VerifyAll();
|
||||||
|
loggerMock.VerifyAll();
|
||||||
|
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
Assert.IsFalse(result.DeleteSuccessful);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Threading.Tasks.Dataflow;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using BirdsiteLive.Common.Settings;
|
||||||
|
using BirdsiteLive.DAL.Contracts;
|
||||||
|
using BirdsiteLive.DAL.Models;
|
||||||
|
using BirdsiteLive.Pipeline.Models;
|
||||||
|
using BirdsiteLive.Pipeline.Processors.TweetsCleanUp;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Moq;
|
||||||
|
using Org.BouncyCastle.Crypto;
|
||||||
|
|
||||||
|
namespace BirdsiteLive.Pipeline.Tests.Processors.TweetsCleanUp
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class RetrieveTweetsToDeleteProcessorTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Process_Test()
|
||||||
|
{
|
||||||
|
#region Stubs
|
||||||
|
var settings = new InstanceSettings
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
var bufferBlock = new BufferBlock<TweetToDelete>();
|
||||||
|
|
||||||
|
var tweetId1 = 42;
|
||||||
|
var tweetId2 = 43;
|
||||||
|
|
||||||
|
var tweet1 = new SyncTweet
|
||||||
|
{
|
||||||
|
Id = tweetId1
|
||||||
|
};
|
||||||
|
var tweet2 = new SyncTweet
|
||||||
|
{
|
||||||
|
Id = tweetId2
|
||||||
|
};
|
||||||
|
var batch = new List<SyncTweet>
|
||||||
|
{
|
||||||
|
tweet1,
|
||||||
|
tweet2
|
||||||
|
};
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mocks
|
||||||
|
var dalMock = new Mock<ISyncTweetsPostgresDal>(MockBehavior.Strict);
|
||||||
|
dalMock
|
||||||
|
.Setup(x => x.GetTweetsOlderThanAsync(It.IsAny<DateTime>(), It.Is<long>(y => y == -1), It.Is<int>(y => y == 100)))
|
||||||
|
.ReturnsAsync(batch);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var processor = new RetrieveTweetsToDeleteProcessor(dalMock.Object, settings);
|
||||||
|
processor.GetTweetsAsync(bufferBlock, CancellationToken.None);
|
||||||
|
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
#region Validations
|
||||||
|
dalMock.VerifyAll();
|
||||||
|
|
||||||
|
Assert.AreEqual(batch.Count, bufferBlock.Count);
|
||||||
|
|
||||||
|
bufferBlock.TryReceiveAll(out var all);
|
||||||
|
foreach (var tweet in all)
|
||||||
|
{
|
||||||
|
Assert.IsTrue(batch.Any(x => x.Id == tweet.Tweet.Id));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
namespace BirdsiteLive.Pipeline.Tests.Processors.TweetsCleanUp;
|
||||||
|
|
||||||
|
public class SaveDeletedTweetStatusProcessorTests
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
namespace BirdsiteLive.Pipeline.Tests;
|
||||||
|
|
||||||
|
public class TweetCleanUpPipelineTests
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user