test(backend): cover step 17 modules and extract stubs
Add tests for partnership workflow, middleman adaptation and idea notifications; extract reusable test stubs into separate files; add architecture guard forbidding object-valued dictionaries in data contracts.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TarninaHub.Tests.Architecture;
|
||||
|
||||
/// <summary>
|
||||
/// Guarantees that data contracts never expose object-valued dictionaries.
|
||||
/// Such dictionaries break CBOR deserialization of SurrealDB rows and force
|
||||
/// lossy conversions, so only string-valued maps are allowed.
|
||||
/// </summary>
|
||||
public class NoObjectValuedDictionariesTests
|
||||
{
|
||||
private static readonly Regex Forbidden = new(@"Dictionary<string,\s*object", RegexOptions.Compiled);
|
||||
|
||||
[Fact]
|
||||
public void DataContracts_MustNotUseObjectValuedDictionaries()
|
||||
{
|
||||
var root = FindRepositoryRoot();
|
||||
var files = new List<string>();
|
||||
|
||||
foreach (var directory in new[]
|
||||
{
|
||||
Path.Combine(root, "backend", "Application", "Dtos"),
|
||||
Path.Combine(root, "backend", "Application", "Abstractions"),
|
||||
Path.Combine(root, "backend", "Domain"),
|
||||
})
|
||||
{
|
||||
files.AddRange(Directory.GetFiles(directory, "*.cs", SearchOption.AllDirectories));
|
||||
}
|
||||
|
||||
files.AddRange(Directory.GetFiles(
|
||||
Path.Combine(root, "backend", "Infrastructure", "Persistence"),
|
||||
"*Row.cs",
|
||||
SearchOption.AllDirectories));
|
||||
|
||||
var offenders = files
|
||||
.Where(file => Forbidden.IsMatch(File.ReadAllText(file)))
|
||||
.Select(file => Path.GetRelativePath(root, file))
|
||||
.OrderBy(path => path, StringComparer.Ordinal)
|
||||
.ToList();
|
||||
|
||||
Assert.True(
|
||||
offenders.Count == 0,
|
||||
"Object-valued dictionaries are forbidden in data contracts. " +
|
||||
"Use string-valued maps instead:\n" + string.Join(Environment.NewLine, offenders));
|
||||
}
|
||||
|
||||
private static string FindRepositoryRoot()
|
||||
{
|
||||
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
|
||||
while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "TarninaHub.slnx")))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
Assert.NotNull(directory);
|
||||
|
||||
return directory!.FullName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user