mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using MalwareMultiScan.Api.Services.Interfaces;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration.Memory;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace MalwareMultiScan.Tests.Api
|
|
{
|
|
public class ReceiverHostedServiceTests
|
|
{
|
|
private Mock<IBus> _busMock;
|
|
private IReceiverHostedService _receiverHostedService;
|
|
private Mock<IScanResultService> _scanResultServiceMock;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_busMock = new Mock<IBus>();
|
|
|
|
_busMock
|
|
.Setup(x => x.Receive("mms.results", It.IsAny<Func<ScanResultMessage, Task>>()))
|
|
.Callback<string, Func<ScanResultMessage, Task>>((s, func) =>
|
|
{
|
|
var task = func.Invoke(new ScanResultMessage
|
|
{
|
|
Id = "test",
|
|
Backend = "dummy",
|
|
Duration = 100,
|
|
Succeeded = true,
|
|
Threats = new[] {"Test"}
|
|
});
|
|
|
|
task.Wait();
|
|
});
|
|
|
|
_scanResultServiceMock = new Mock<IScanResultService>();
|
|
|
|
var configuration = new ConfigurationRoot(new List<IConfigurationProvider>
|
|
{
|
|
new MemoryConfigurationProvider(new MemoryConfigurationSource())
|
|
})
|
|
{
|
|
["ResultsSubscriptionId"] = "mms.results"
|
|
};
|
|
|
|
var httpClientFactoryMock = new Mock<IHttpClientFactory>();
|
|
|
|
_receiverHostedService = new ReceiverHostedService(
|
|
_busMock.Object,
|
|
configuration,
|
|
_scanResultServiceMock.Object,
|
|
Mock.Of<ILogger<ReceiverHostedService>>(),
|
|
httpClientFactoryMock.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestBusReceiveScanResultMessage()
|
|
{
|
|
await _receiverHostedService.StartAsync(default);
|
|
|
|
_scanResultServiceMock.Verify(x => x.UpdateScanResultForBackend(
|
|
"test", "dummy", 100, true, true, new[] {"Test"}), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestBusIsDisposedOnStop()
|
|
{
|
|
await _receiverHostedService.StopAsync(default);
|
|
|
|
_busMock.Verify(x => x.Dispose(), Times.Once);
|
|
}
|
|
}
|
|
} |