Skip to content

Commit 83f7526

Browse files
committed
Merge branch '70_Collectionizer_plugin'
2 parents f1f3dfb + 82bf144 commit 83f7526

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Tynamix.ObjectFiller.Test/CollectionizerTest.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System.Collections;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Tynamix.ObjectFiller;
45
using Xunit;
@@ -10,10 +11,26 @@ public class CollectionizerPoco
1011
public IEnumerable<string> MnemonicStrings { get; set; }
1112

1213
public List<int> IntRange { get; set; }
14+
15+
public ArrayList ArrayList { get; set; }
1316
}
1417

1518
public class CollectionizerTest
1619
{
20+
[Fact]
21+
public void TestCityNames()
22+
{
23+
var filler = new Filler<CollectionizerPoco>();
24+
25+
filler.Setup()
26+
.OnProperty(x => x.ArrayList)
27+
.Use(new Collectionizer<string, MnemonicString>(new MnemonicString(1, 20, 25), 3, 10));
28+
29+
var arrayList = filler.Create();
30+
Assert.True(arrayList.ArrayList.Count >= 3 && arrayList.ArrayList.Count <= 10);
31+
Assert.True(arrayList.ArrayList.ToArray().Cast<string>().All(x => x.Length >= 20 && x.Length <= 25));
32+
}
33+
1734
[Fact]
1835
public void TestMnemonicStringPlugin()
1936
{

Tynamix.ObjectFiller/Plugins/Collectionizer.cs Tynamix.ObjectFiller/Plugins/List/Collectionizer.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System.Collections;
2+
using System.Collections.Generic;
23

34
namespace Tynamix.ObjectFiller
45
{
@@ -8,6 +9,9 @@ namespace Tynamix.ObjectFiller
89
/// <typeparam name="T">Typeparameter of of the target List</typeparam>
910
/// <typeparam name="TRandomizer">Plugin which will be used to create the List</typeparam>
1011
public class Collectionizer<T, TRandomizer> : IRandomizerPlugin<List<T>>
12+
#if !NETSTD
13+
, IRandomizerPlugin<ArrayList>
14+
#endif
1115
where TRandomizer : IRandomizerPlugin<T>, new()
1216
{
1317
private readonly IRandomizerPlugin<T> randomizerToUse;
@@ -105,5 +109,20 @@ public List<T> GetValue()
105109

106110
return result;
107111
}
112+
113+
#if !NETSTD
114+
/// <summary>
115+
/// Gets random data for type <see cref="T"/>
116+
/// </summary>
117+
/// <returns>Random data for type <see cref="T"/></returns>
118+
ArrayList IRandomizerPlugin<ArrayList>.GetValue()
119+
{
120+
ArrayList arrayList = new ArrayList();
121+
arrayList.AddRange(this.GetValue());
122+
123+
return arrayList;
124+
}
125+
#endif
108126
}
127+
109128
}

Tynamix.ObjectFiller/Setup/FillerSetupItem.cs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// </summary>
99
// --------------------------------------------------------------------------------------------------------------------
1010

11+
using System.Collections;
12+
1113
namespace Tynamix.ObjectFiller
1214
{
1315
using System;
@@ -152,6 +154,9 @@ private void SetDefaultRandomizer()
152154
this.TypeToRandomFunc[typeof(IntPtr?)] = () => default(IntPtr);
153155
this.TypeToRandomFunc[typeof(TimeSpan)] = () => new TimeSpan(Random.Next());
154156
this.TypeToRandomFunc[typeof(TimeSpan?)] = () => new TimeSpan(Random.Next());
157+
#if !NETSTD
158+
this.TypeToRandomFunc[typeof(ArrayList)] = () => ((IRandomizerPlugin<ArrayList>)new Collectionizer<string, MnemonicString>()).GetValue();
159+
#endif
155160
}
156161
}
157162
}

0 commit comments

Comments
 (0)