MalwareMultiScan/MalwareMultiScan.Tests/Api/ScanBackendServiceTests.cs

63 lines
1.8 KiB
C#
Raw Normal View History

2020-10-29 12:17:09 +02:00
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyNetQ;
using MalwareMultiScan.Api.Data.Configuration;
using MalwareMultiScan.Api.Data.Models;
using MalwareMultiScan.Api.Services.Implementations;
using MalwareMultiScan.Api.Services.Interfaces;
using MalwareMultiScan.Backends.Messages;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
2020-10-29 16:09:56 +02:00
namespace MalwareMultiScan.Tests.Api
2020-10-29 12:17:09 +02:00
{
public class ScanBackendServiceTests
{
private Mock<IBus> _busMock;
2020-10-29 16:09:56 +02:00
private IScanBackendService _scanBackendService;
2020-10-29 12:17:09 +02:00
[SetUp]
public void SetUp()
{
var configuration = new ConfigurationRoot(new List<IConfigurationProvider>
{
new MemoryConfigurationProvider(new MemoryConfigurationSource())
})
{
["BackendsConfiguration"] = "backends.yaml"
};
2020-10-29 16:09:56 +02:00
2020-10-29 12:17:09 +02:00
_busMock = new Mock<IBus>();
2020-10-29 16:09:56 +02:00
2020-10-29 12:17:09 +02:00
_scanBackendService = new ScanBackendService(
2020-10-29 16:09:56 +02:00
configuration,
_busMock.Object,
2020-10-29 12:17:09 +02:00
Mock.Of<ILogger<ScanBackendService>>());
}
[Test]
public void TestBackendsAreNotEmpty()
{
Assert.IsNotEmpty(_scanBackendService.List);
}
[Test]
public async Task TestQueueUrlScan()
{
await _scanBackendService.QueueUrlScan(
2020-10-29 16:09:56 +02:00
new ScanResult {Id = "test"},
new ScanBackend {Id = "dummy"},
2020-10-29 12:17:09 +02:00
"http://test.com"
);
_busMock.Verify(x => x.SendAsync(
"dummy", It.Is<ScanRequestMessage>(r =>
r.Id == "test" &&
r.Uri == new Uri("http://test.com"))), Times.Once);
}
}
}