Template
63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using Strata.DecisionSupport.Biz.Parameters;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using VerifyNUnit;
|
|
using VerifyTests;
|
|
|
|
namespace Strata.DecisionSupport.Biz.Test.Unit
|
|
{
|
|
[ExcludeFromCodeCoverage]
|
|
[SetUpFixture]
|
|
public class UnitTestBase
|
|
{
|
|
protected VerifySettings verifySettings;
|
|
|
|
[OneTimeSetUp]
|
|
public void Setup()
|
|
{
|
|
verifySettings = TestExtensions.TestSettings();
|
|
}
|
|
protected virtual async Task VerifyQuery<T>(T queryInfo)
|
|
where T : class
|
|
{
|
|
var query = Query(queryInfo);
|
|
await Verifier.Verify(query, verifySettings)
|
|
.UseDirectory("snapshotQueries")
|
|
.UseFileName(TestContext.CurrentContext.TestName());
|
|
}
|
|
|
|
protected virtual async Task VerifyDictionary<T>(T queryInfo) where T : class
|
|
{
|
|
if (!(queryInfo is IWithDictionary withDictionary)) { return; }
|
|
var dictionary = withDictionary.Dictionary();
|
|
await Verifier.Verify(JsonSerializer.Serialize(dictionary), verifySettings)
|
|
.UseDirectory("snapshotDictionary")
|
|
.UseFileName(TestContext.CurrentContext.TestName());
|
|
}
|
|
|
|
protected virtual async Task VerifyParameters<T>(T queryInfo) where T : class
|
|
{
|
|
if (!(queryInfo is IWithParameters withParameters)) { return; }
|
|
var parameters = withParameters.Parameters();
|
|
string json = JsonSerializer.Serialize(parameters);
|
|
await Verifier.Verify(json, verifySettings)
|
|
.UseDirectory("snapshotParameters")
|
|
.UseFileName(TestContext.CurrentContext.TestName());
|
|
}
|
|
|
|
protected virtual async Task VerifyArgs<T>(T queryInfo) where T : class
|
|
{
|
|
if (!(queryInfo is IWithArgs withArgs)) { return; }
|
|
var args = withArgs.Args();
|
|
await Verifier.Verify(args, verifySettings)
|
|
.UseDirectory("snapshotArgs")
|
|
.UseFileName(TestContext.CurrentContext.TestName());
|
|
}
|
|
|
|
protected virtual string Query<T>(T queryInfo)
|
|
where T : class => "";
|
|
|
|
}
|
|
}
|