From 1af9c7012c2590a071c812c5ad3a8e1b00e68981 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:41:59 -0500 Subject: [PATCH] feat: Add OfacFileService - Add initial OfacFileService including deps - Added Moq and MockHttp as dependencies for testing --- .../SanctionsSearch.Worker.Tests.csproj | 2 + .../Unit/OfacFileServiceTests.cs | 62 +++++++++++++++++++ src/SanctionsSearch.Worker.Tests/Usings.cs | 7 ++- .../SanctionsSearch.Worker.csproj | 1 + .../Services/OfacFileService.cs | 29 +++++++++ src/SanctionsSearch.Worker/Usings.cs | 1 + 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/SanctionsSearch.Worker.Tests/Unit/OfacFileServiceTests.cs create mode 100644 src/SanctionsSearch.Worker/Services/OfacFileService.cs diff --git a/src/SanctionsSearch.Worker.Tests/SanctionsSearch.Worker.Tests.csproj b/src/SanctionsSearch.Worker.Tests/SanctionsSearch.Worker.Tests.csproj index 815a0fe..b9f0b6b 100644 --- a/src/SanctionsSearch.Worker.Tests/SanctionsSearch.Worker.Tests.csproj +++ b/src/SanctionsSearch.Worker.Tests/SanctionsSearch.Worker.Tests.csproj @@ -11,6 +11,8 @@ + + diff --git a/src/SanctionsSearch.Worker.Tests/Unit/OfacFileServiceTests.cs b/src/SanctionsSearch.Worker.Tests/Unit/OfacFileServiceTests.cs new file mode 100644 index 0000000..272f8ab --- /dev/null +++ b/src/SanctionsSearch.Worker.Tests/Unit/OfacFileServiceTests.cs @@ -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> _mockLogger = new(); + private readonly Mock> _mockOptions = new(); + + [Fact] + public void Constructor_WhenCalledWithNullClient_ThrowsArgumentNullException() + { + var act = () => new OfacFileService( + null!, + _mockLogger.Object, + _mockOptions.Object + ); + + act.Should().Throw(); + } + + [Fact] + public void Constructor_WhenCalledWithNullLogger_ThrowsArgumentNullException() + { + var act = () => new OfacFileService( + _mockHttp.ToHttpClient(), + null!, + _mockOptions.Object + ); + + act.Should().Throw(); + } + + [Fact] + public void Constructor_WhenCalledWithNullOptions_ThrowsArgumentNullException() + { + var act = () => new OfacFileService( + _mockHttp.ToHttpClient(), + _mockLogger.Object, + null! + ); + + act.Should().Throw(); + } + + [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(); + } +} \ No newline at end of file diff --git a/src/SanctionsSearch.Worker.Tests/Usings.cs b/src/SanctionsSearch.Worker.Tests/Usings.cs index fbe49a3..3ad42eb 100644 --- a/src/SanctionsSearch.Worker.Tests/Usings.cs +++ b/src/SanctionsSearch.Worker.Tests/Usings.cs @@ -1 +1,6 @@ -using FluentAssertions; \ No newline at end of file +global using FluentAssertions; + +global using Microsoft.Extensions.Logging; +global using Microsoft.Extensions.Options; + +global using SanctionsSearch.Worker.Services; \ No newline at end of file diff --git a/src/SanctionsSearch.Worker/SanctionsSearch.Worker.csproj b/src/SanctionsSearch.Worker/SanctionsSearch.Worker.csproj index 688a06f..0aa2d4b 100644 --- a/src/SanctionsSearch.Worker/SanctionsSearch.Worker.csproj +++ b/src/SanctionsSearch.Worker/SanctionsSearch.Worker.csproj @@ -23,6 +23,7 @@ + diff --git a/src/SanctionsSearch.Worker/Services/OfacFileService.cs b/src/SanctionsSearch.Worker/Services/OfacFileService.cs new file mode 100644 index 0000000..95256a0 --- /dev/null +++ b/src/SanctionsSearch.Worker/Services/OfacFileService.cs @@ -0,0 +1,29 @@ +namespace SanctionsSearch.Worker.Services; + +interface IOfacFileService +{ +} + +class OfacFileService( + HttpClient client, + ILogger logger, + IOptionsSnapshot options +) : IOfacFileService +{ + private readonly HttpClient _client = client ?? throw new ArgumentNullException(nameof(client)); + private readonly ILogger _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; +} \ No newline at end of file diff --git a/src/SanctionsSearch.Worker/Usings.cs b/src/SanctionsSearch.Worker/Usings.cs index 943f86d..6b1abf1 100644 --- a/src/SanctionsSearch.Worker/Usings.cs +++ b/src/SanctionsSearch.Worker/Usings.cs @@ -2,3 +2,4 @@ global using SanctionsSearch.Worker; global using Serilog; global using Serilog.Formatting.Compact; global using Serilog.Exceptions; +global using Microsoft.Extensions.Options; \ No newline at end of file