File tree Expand file tree Collapse file tree
tests/KnowledgeBaseServer.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public static Faker<Topic> Faker() =>
1818 new Faker < Topic > ( )
1919 . RuleFor ( x => x . Id , Guid . CreateVersion7 )
2020 . RuleFor ( x => x . Created , f => f . Date . PastOffset ( ) )
21- . RuleFor ( x => x . Name , f => f . Lorem . Sentence ( 3 ) ) ;
21+ . RuleFor ( x => x . Name , f => f . Lorem . Sentence ( ) ) ;
2222}
2323
2424public static partial class DbConnectionExtensions
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Diagnostics . CodeAnalysis ;
4+ using System . Linq ;
5+ using Bogus ;
6+
7+ namespace KnowledgeBaseServer . Tests ;
8+
9+ public static class FakerExtensions
10+ {
11+ public static IEnumerable < T > MakeUnique < T > ( this Faker faker , Func < Faker , T > generator )
12+ {
13+ return CreateItems ( ) . Distinct ( ) ;
14+
15+ [ SuppressMessage (
16+ "Blocker Bug" ,
17+ "S2190:Loops and recursions should not be infinite" ,
18+ Justification = "The method is intended to generate a potentially infinite sequence of items..."
19+ ) ]
20+ IEnumerable < T > CreateItems ( )
21+ {
22+ while ( true )
23+ {
24+ yield return generator ( faker ) ;
25+ }
26+ // ReSharper disable once IteratorNeverReturns
27+ }
28+ }
29+
30+ public static IEnumerable < TItem > MakeUnique < TItem , TProperty > (
31+ this Faker faker ,
32+ Func < Faker , TItem > generator ,
33+ Func < TItem , TProperty > uniquePropertySelector
34+ )
35+ where TProperty : notnull
36+ {
37+ return CreateItems ( ) . DistinctBy ( uniquePropertySelector ) ;
38+
39+ [ SuppressMessage (
40+ "Blocker Bug" ,
41+ "S2190:Loops and recursions should not be infinite" ,
42+ Justification = "The method is intended to generate a potentially infinite sequence of items."
43+ ) ]
44+ IEnumerable < TItem > CreateItems ( )
45+ {
46+ while ( true )
47+ {
48+ yield return generator ( faker ) ;
49+ }
50+ // ReSharper disable once IteratorNeverReturns
51+ }
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ public void ShouldReturnMemoryMatchingPhrases()
8383 public void ShouldFilterMatchingMemoriesByTopic_WhenTopicsAreProvided ( )
8484 {
8585 // arrange
86- var topics = _faker . Lorem . Words ( ) ;
86+ var topics = _faker . MakeUnique ( f => f . Lorem . Word ( ) ) . Take ( 3 ) . ToArray ( ) ;
8787 var searchPhrase = _faker . Lorem . Word ( ) ;
8888
8989 foreach ( var topic in topics )
@@ -266,7 +266,7 @@ public void ShouldReturnOnlyNonOutdatedMemories_WhenExcludingOutdated()
266266 public void ShouldFilterResults_WhenFilteringByTopicAndExcludingOutdated ( )
267267 {
268268 // arrange
269- var topics = _faker . Lorem . Words ( ) ;
269+ var topics = _faker . MakeUnique ( f => f . Lorem . Word ( ) ) . Take ( 3 ) . ToArray ( ) ;
270270 var searchPhrase = _faker . Lorem . Word ( ) ;
271271 var memoryIdsByTopic = new Dictionary < string , List < Guid > > ( ) ;
272272
You can’t perform that action at this time.
0 commit comments