File tree Expand file tree Collapse file tree
tests/MarkdownLd.Kb.Tests/Integration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments