Skip to content

Commit b7460fb

Browse files
committed
tests
1 parent ab9d8e5 commit b7460fb

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Reflection;
2+
using ManagedCode.MarkdownLd.Kb.Pipeline;
3+
using Shouldly;
4+
5+
namespace ManagedCode.MarkdownLd.Kb.Tests.Integration;
6+
7+
public sealed class KnowledgeExtractionCacheDesignGuardTests
8+
{
9+
[Test]
10+
public void Cache_types_do_not_define_non_literal_static_fields()
11+
{
12+
var cacheNamespace = typeof(FileKnowledgeExtractionCache).Namespace;
13+
var cacheTypes = typeof(FileKnowledgeExtractionCache).Assembly
14+
.GetTypes()
15+
.Where(type =>
16+
type.Namespace == cacheNamespace &&
17+
(typeof(IKnowledgeExtractionCache).IsAssignableFrom(type) ||
18+
type.Name.StartsWith("KnowledgeExtractionCache", StringComparison.Ordinal) ||
19+
type == typeof(KnowledgeExtractionChunkFingerprint)))
20+
.ToArray();
21+
22+
var offenders = cacheTypes
23+
.SelectMany(type => type
24+
.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
25+
.Where(field => !field.IsLiteral)
26+
.Select(field => string.Concat(type.FullName, ".", field.Name)))
27+
.ToArray();
28+
29+
offenders.ShouldBeEmpty();
30+
}
31+
}

0 commit comments

Comments
 (0)