tests: add unit tests
This commit is contained in:
@@ -31,7 +31,8 @@
|
|||||||
<CoverletOutput>./TestResults/coverage/</CoverletOutput>
|
<CoverletOutput>./TestResults/coverage/</CoverletOutput>
|
||||||
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
|
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
|
||||||
<Include>[SanctionsSearch.Worker]*</Include>
|
<Include>[SanctionsSearch.Worker]*</Include>
|
||||||
<Exclude>[SanctionsSearch.Worker]SanctionsSearch.Worker.Migrations*</Exclude>
|
<Exclude>[SanctionsSearch.Worker]SanctionsSearch.Worker.Migrations*,[SanctionsSearch.Worker]SanctionsSearch.Worker.Setup*,[SanctionsSearch.Worker]SanctionsSearch.Worker.Workers*</Exclude>
|
||||||
|
<ExcludeByFile>**/Program.cs</ExcludeByFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest">
|
<Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest">
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
namespace SanctionsSearch.Worker.Tests.Unit;
|
||||||
|
|
||||||
|
public class GetPagedRecordsResponseExtensionsTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void HasMorePages_WhenPageNumberIsLessThanTotalPages_ReturnsTrue()
|
||||||
|
{
|
||||||
|
var response = new GetPagedRecordsResponse
|
||||||
|
{
|
||||||
|
PageNumber = 1,
|
||||||
|
TotalPages = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
response.HasMorePages().Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HasMorePages_WhenPageNumberIsEqualToTotalPages_ReturnsFalse()
|
||||||
|
{
|
||||||
|
var response = new GetPagedRecordsResponse
|
||||||
|
{
|
||||||
|
PageNumber = 2,
|
||||||
|
TotalPages = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
response.HasMorePages().Should().BeFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
namespace SanctionsSearch.Worker.Tests.Unit;
|
||||||
|
|
||||||
|
public class OnspringOptionsTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void OnspringOptions_WhenCreated_ShouldHaveDefaultValues()
|
||||||
|
{
|
||||||
|
var onspringOptions = new OnspringOptions();
|
||||||
|
|
||||||
|
var searchRequestOptions = onspringOptions.SearchRequestOptions;
|
||||||
|
var searchResultOptions = onspringOptions.SearchResultOptions;
|
||||||
|
|
||||||
|
onspringOptions.BaseUrl.Should().Be("https://api.onspring.com");
|
||||||
|
onspringOptions.ApiKey.Should().Be(string.Empty);
|
||||||
|
onspringOptions.SearchIntervalInMinutes.Should().Be(1);
|
||||||
|
searchRequestOptions.AppId.Should().Be(0);
|
||||||
|
searchRequestOptions.NameFieldId.Should().Be(0);
|
||||||
|
searchRequestOptions.StatusFieldId.Should().Be(0);
|
||||||
|
searchRequestOptions.AwaitingProcessingStatusId.Should().Be(Guid.Empty);
|
||||||
|
searchRequestOptions.ProcessingStatusId.Should().Be(Guid.Empty);
|
||||||
|
searchRequestOptions.ProcessedSuccessStatusId.Should().Be(Guid.Empty);
|
||||||
|
searchRequestOptions.ProcessedErrorStatusId.Should().Be(Guid.Empty);
|
||||||
|
searchRequestOptions.ErrorFieldId.Should().Be(0);
|
||||||
|
searchResultOptions.AppId.Should().Be(0);
|
||||||
|
searchResultOptions.SearchRequestFieldId.Should().Be(0);
|
||||||
|
searchResultOptions.NameFieldId.Should().Be(0);
|
||||||
|
searchResultOptions.AddressFieldId.Should().Be(0);
|
||||||
|
searchResultOptions.TypeFieldId.Should().Be(0);
|
||||||
|
searchResultOptions.ProgramsFieldId.Should().Be(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
namespace SanctionsSearch.Worker.Extensions;
|
||||||
|
|
||||||
|
public class RecordFieldValueExtensionsTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetStringValue_WhenRecordFieldValueTypeIsString_ReturnsValue()
|
||||||
|
{
|
||||||
|
var value = "value";
|
||||||
|
|
||||||
|
var recordFieldValue = new StringFieldValue(1, value);
|
||||||
|
|
||||||
|
recordFieldValue.GetStringValue().Should().Be(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetStringValue_WhenRecordFieldValueTypeIsNotString_ReturnsEmptyString()
|
||||||
|
{
|
||||||
|
var recordFieldValue = new IntegerFieldValue(1, 1);
|
||||||
|
|
||||||
|
recordFieldValue.GetStringValue().Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetStringValue_WhenRecordFieldValueValueIsNull_ReturnsEmptyString()
|
||||||
|
{
|
||||||
|
var recordFieldValue = new StringFieldValue(1, null);
|
||||||
|
|
||||||
|
recordFieldValue.GetStringValue().Should().BeEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,12 +8,14 @@ global using FluentAssertions;
|
|||||||
global using Microsoft.Data.Sqlite;
|
global using Microsoft.Data.Sqlite;
|
||||||
global using Microsoft.EntityFrameworkCore;
|
global using Microsoft.EntityFrameworkCore;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
global using Moq;
|
global using Moq;
|
||||||
|
|
||||||
|
global using Onspring.API.SDK.Models;
|
||||||
|
|
||||||
global using RichardSzalay.MockHttp;
|
global using RichardSzalay.MockHttp;
|
||||||
|
|
||||||
|
global using SanctionsSearch.Worker.Extensions;
|
||||||
global using SanctionsSearch.Worker.Interfaces;
|
global using SanctionsSearch.Worker.Interfaces;
|
||||||
global using SanctionsSearch.Worker.Models;
|
global using SanctionsSearch.Worker.Models;
|
||||||
global using SanctionsSearch.Worker.Options;
|
global using SanctionsSearch.Worker.Options;
|
||||||
|
|||||||
@@ -2,8 +2,15 @@ namespace SanctionsSearch.Worker.Extensions;
|
|||||||
|
|
||||||
static class RecordFieldValueExtensions
|
static class RecordFieldValueExtensions
|
||||||
{
|
{
|
||||||
public static string GetStringValue(this RecordFieldValue recordFieldValue) =>
|
public static string GetStringValue(this RecordFieldValue recordFieldValue)
|
||||||
recordFieldValue.Type is not ResultValueType.String
|
{
|
||||||
? string.Empty
|
try
|
||||||
: recordFieldValue.AsString() ?? string.Empty;
|
{
|
||||||
|
return recordFieldValue.AsString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -105,11 +105,11 @@ class OnspringService(
|
|||||||
FieldId = _options.SearchRequestOptions.StatusFieldId,
|
FieldId = _options.SearchRequestOptions.StatusFieldId,
|
||||||
Value = _options.SearchRequestOptions.ProcessedErrorStatusId
|
Value = _options.SearchRequestOptions.ProcessedErrorStatusId
|
||||||
},
|
},
|
||||||
new StringFieldValue()
|
new StringFieldValue()
|
||||||
{
|
{
|
||||||
FieldId = _options.SearchRequestOptions.ErrorFieldId,
|
FieldId = _options.SearchRequestOptions.ErrorFieldId,
|
||||||
Value = "Unable to save all search results"
|
Value = "Unable to save all search results"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
: new ResultRecord()
|
: new ResultRecord()
|
||||||
@@ -122,11 +122,11 @@ class OnspringService(
|
|||||||
FieldId = _options.SearchRequestOptions.StatusFieldId,
|
FieldId = _options.SearchRequestOptions.StatusFieldId,
|
||||||
Value = _options.SearchRequestOptions.ProcessedSuccessStatusId
|
Value = _options.SearchRequestOptions.ProcessedSuccessStatusId
|
||||||
},
|
},
|
||||||
new StringFieldValue()
|
new StringFieldValue()
|
||||||
{
|
{
|
||||||
FieldId = _options.SearchRequestOptions.ErrorFieldId,
|
FieldId = _options.SearchRequestOptions.ErrorFieldId,
|
||||||
Value = string.Empty
|
Value = string.Empty
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user