feat: Add OfacFileService

- Add initial OfacFileService including deps
- Added Moq and MockHttp as dependencies
  for testing
This commit is contained in:
Stevan Freeborn
2024-08-12 09:41:59 -05:00
parent 24aa6ff35c
commit 1af9c7012c
6 changed files with 101 additions and 1 deletions
@@ -11,6 +11,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" /> <PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.5.3" /> <PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="coverlet.collector" Version="6.0.0"> <PackageReference Include="coverlet.collector" Version="6.0.0">
@@ -0,0 +1,62 @@
using Moq;
using RichardSzalay.MockHttp;
namespace SanctionsSearch.Worker.Tests.Unit;
public class OfacFileServiceTests
{
private readonly MockHttpMessageHandler _mockHttp = new();
private readonly Mock<ILogger<OfacFileService>> _mockLogger = new();
private readonly Mock<IOptionsSnapshot<OfacFileServiceOptions>> _mockOptions = new();
[Fact]
public void Constructor_WhenCalledWithNullClient_ThrowsArgumentNullException()
{
var act = () => new OfacFileService(
null!,
_mockLogger.Object,
_mockOptions.Object
);
act.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithNullLogger_ThrowsArgumentNullException()
{
var act = () => new OfacFileService(
_mockHttp.ToHttpClient(),
null!,
_mockOptions.Object
);
act.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithNullOptions_ThrowsArgumentNullException()
{
var act = () => new OfacFileService(
_mockHttp.ToHttpClient(),
_mockLogger.Object,
null!
);
act.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithNullOptionsValue_ThrowsArgumentNullException()
{
_mockOptions.Setup(x => x.Value).Returns(() => null!);
var act = () => new OfacFileService(
_mockHttp.ToHttpClient(),
_mockLogger.Object,
_mockOptions.Object
);
act.Should().Throw<ArgumentNullException>();
}
}
+6 -1
View File
@@ -1 +1,6 @@
using FluentAssertions; global using FluentAssertions;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using SanctionsSearch.Worker.Services;
@@ -23,6 +23,7 @@
<ItemGroup> <ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Tests" /> <InternalsVisibleTo Include="$(AssemblyName).Tests" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -0,0 +1,29 @@
namespace SanctionsSearch.Worker.Services;
interface IOfacFileService
{
}
class OfacFileService(
HttpClient client,
ILogger<OfacFileService> logger,
IOptionsSnapshot<OfacFileServiceOptions> options
) : IOfacFileService
{
private readonly HttpClient _client = client ?? throw new ArgumentNullException(nameof(client));
private readonly ILogger<OfacFileService> _logger = logger ?? throw new ArgumentNullException(nameof(logger));
private readonly OfacFileServiceOptions _options = options?.Value ?? throw new ArgumentNullException(nameof(options));
}
class OfacFileServiceOptions
{
public string Url { get; set; } = string.Empty;
public string SdnFileName { get; set; } = string.Empty;
public string AddressFileName { get; set; } = string.Empty;
public string AltNamesFileName { get; set; } = string.Empty;
public string CommentsFileName { get; set; } = string.Empty;
public string ConPrimaryNameFileName { get; set; } = string.Empty;
public string ConAddressesFileName { get; set; } = string.Empty;
public string ConAltNamesFileName { get; set; } = string.Empty;
public string ConCommentsFileName { get; set; } = string.Empty;
}
+1
View File
@@ -2,3 +2,4 @@ global using SanctionsSearch.Worker;
global using Serilog; global using Serilog;
global using Serilog.Formatting.Compact; global using Serilog.Formatting.Compact;
global using Serilog.Exceptions; global using Serilog.Exceptions;
global using Microsoft.Extensions.Options;