File tree Expand file tree Collapse file tree 4 files changed +45
-4
lines changed Expand file tree Collapse file tree 4 files changed +45
-4
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace ObjectFiller . Test
9
9
{
10
+ using ObjectFiller . Test . TestPoco ;
11
+
10
12
[ TestClass ]
11
13
public class ListFillingTest
12
14
{
@@ -131,6 +133,16 @@ public void GenerateTestDataForADictionary()
131
133
}
132
134
}
133
135
136
+ [ TestMethod ]
137
+ public void GenerateDictionaryWithEnumeration ( )
138
+ {
139
+ var amountOfEnumValues = Enum . GetValues ( typeof ( TestEnum ) ) . Length ;
140
+ var filler = new Filler < Dictionary < TestEnum , string > > ( ) ;
141
+ var result = filler . Create ( ) ;
142
+
143
+ Assert . AreEqual ( amountOfEnumValues , result . Count ) ;
144
+ }
145
+
134
146
private Entity [ ] GetArray ( )
135
147
{
136
148
Filler < Entity > of = new Filler < Entity > ( ) ;
@@ -146,9 +158,7 @@ private Entity[] GetArray()
146
158
entities . Add ( of . Create ( ) ) ;
147
159
entities . Add ( of . Create ( ) ) ;
148
160
149
-
150
161
return entities . ToArray ( ) ;
151
162
}
152
-
153
163
}
154
164
}
Original file line number Diff line number Diff line change 82
82
<Compile Include =" TestPoco\SimpleList.cs" />
83
83
<Compile Include =" SaveFillerSetupTest.cs" />
84
84
<Compile Include =" EmailAddressesPluginTest.cs" />
85
+ <Compile Include =" TestPoco\TestEnum.cs" />
85
86
</ItemGroup >
86
87
<ItemGroup >
87
88
<ProjectReference Include =" ..\ObjectFiller\ObjectFiller.csproj" >
Original file line number Diff line number Diff line change
1
+ namespace ObjectFiller . Test . TestPoco
2
+ {
3
+ using System ;
4
+
5
+ [ Flags ]
6
+ public enum TestEnum
7
+ {
8
+ ValueOne ,
9
+ ValueTwo ,
10
+ ValueThree ,
11
+ ValueFour
12
+ }
13
+ }
Original file line number Diff line number Diff line change @@ -635,13 +635,30 @@ private IDictionary GetFilledDictionary(
635
635
Type keyType = propertyType . GetGenericArguments ( ) [ 0 ] ;
636
636
Type valueType = propertyType . GetGenericArguments ( ) [ 1 ] ;
637
637
638
- int maxDictionaryItems = Random . Next (
638
+ int maxDictionaryItems = 0 ;
639
+
640
+ if ( keyType . IsEnum )
641
+ {
642
+ maxDictionaryItems = Enum . GetValues ( keyType ) . Length ;
643
+ }
644
+ else
645
+ {
646
+ maxDictionaryItems = Random . Next (
639
647
currentSetupItem . DictionaryKeyMinCount ,
640
648
currentSetupItem . DictionaryKeyMaxCount ) ;
649
+ }
641
650
642
651
for ( int i = 0 ; i < maxDictionaryItems ; i ++ )
643
652
{
644
- object keyObject = this . CreateAndFillObject ( keyType , currentSetupItem , typeTracker ) ;
653
+ object keyObject = null ;
654
+ if ( keyType . IsEnum )
655
+ {
656
+ keyObject = Enum . GetValues ( keyType ) . GetValue ( i ) ;
657
+ }
658
+ else
659
+ {
660
+ keyObject = this . CreateAndFillObject ( keyType , currentSetupItem , typeTracker ) ;
661
+ }
645
662
646
663
if ( dictionary . Contains ( keyObject ) )
647
664
{
You can’t perform that action at this time.
0 commit comments