mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration.Memory;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace MalwareMultiScan.Tests.Scanner
|
|
{
|
|
public class ScanBackgroundJobTests
|
|
{
|
|
private Mock<IBus> _busMock;
|
|
private Mock<IScanBackend> _scanBackendMock;
|
|
private IScanBackgroundJob _scanBackgroundJob;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
var configuration = new ConfigurationRoot(new List<IConfigurationProvider>
|
|
{
|
|
new MemoryConfigurationProvider(new MemoryConfigurationSource())
|
|
})
|
|
{
|
|
["ResultsSubscriptionId"] = "mms.results"
|
|
};
|
|
|
|
_busMock = new Mock<IBus>();
|
|
|
|
_scanBackendMock = new Mock<IScanBackend>();
|
|
|
|
_scanBackendMock
|
|
.SetupGet(x => x.Id)
|
|
.Returns("dummy");
|
|
|
|
_scanBackendMock
|
|
.Setup(x => x.ScanAsync(It.IsAny<Uri>(), It.IsAny<CancellationToken>()))
|
|
.Returns(Task.FromResult(new[] {"Test"}));
|
|
|
|
_scanBackgroundJob = new ScanBackgroundJob(configuration, _busMock.Object,
|
|
Mock.Of<ILogger<ScanBackgroundJob>>(), _scanBackendMock.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestMessageProcessing()
|
|
{
|
|
await _scanBackgroundJob.Process(new ScanRequestMessage
|
|
{
|
|
Id = "test",
|
|
Uri = new Uri("http://test.com")
|
|
});
|
|
|
|
_scanBackendMock.Verify(
|
|
x => x.ScanAsync(It.IsAny<Uri>(), It.IsAny<CancellationToken>()));
|
|
|
|
_busMock.Verify(x => x.SendAsync("mms.results", It.Is<ScanResultMessage>(m =>
|
|
m.Succeeded && m.Backend == "dummy" && m.Id == "test" && m.Threats.Contains("Test"))));
|
|
}
|
|
}
|
|
} |