mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 14:01:13 +00:00
unit tests for API (99% coverage)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using EasyNetQ;
|
||||
using MalwareMultiScan.Api.Data.Configuration;
|
||||
using MalwareMultiScan.Api.Data.Models;
|
||||
using MalwareMultiScan.Api.Services.Interfaces;
|
||||
using MalwareMultiScan.Backends.Messages;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace MalwareMultiScan.Api.Services.Implementations
|
||||
{
|
||||
public class ScanBackendService : IScanBackendService
|
||||
{
|
||||
private readonly IBus _bus;
|
||||
private readonly ILogger<ScanBackendService> _logger;
|
||||
|
||||
public ScanBackendService(IConfiguration configuration, IBus bus, ILogger<ScanBackendService> logger)
|
||||
{
|
||||
_bus = bus;
|
||||
_logger = logger;
|
||||
|
||||
var configurationPath = configuration.GetValue<string>("BackendsConfiguration");
|
||||
|
||||
if (!File.Exists(configurationPath))
|
||||
throw new FileNotFoundException("Missing BackendsConfiguration YAML file", configurationPath);
|
||||
|
||||
var configurationContent = File.ReadAllText(configurationPath);
|
||||
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
|
||||
List = deserializer.Deserialize<ScanBackend[]>(configurationContent);
|
||||
}
|
||||
|
||||
public ScanBackend[] List { get; }
|
||||
|
||||
public async Task QueueUrlScan(ScanResult result, ScanBackend backend, string fileUrl)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
$"Queueing scan for {result.Id} on {backend.Id} at {fileUrl}");
|
||||
|
||||
await _bus.SendAsync(backend.Id, new ScanRequestMessage
|
||||
{
|
||||
Id = result.Id,
|
||||
Uri = new Uri(fileUrl)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user