Skip to content

Commit

Permalink
Merge branch '70_Collectionizer_plugin'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynamix committed Mar 8, 2016
2 parents f1f3dfb + 82bf144 commit 83f7526
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Tynamix.ObjectFiller.Test/CollectionizerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Tynamix.ObjectFiller;
using Xunit;
Expand All @@ -10,10 +11,26 @@ public class CollectionizerPoco
public IEnumerable<string> MnemonicStrings { get; set; }

public List<int> IntRange { get; set; }

public ArrayList ArrayList { get; set; }
}

public class CollectionizerTest
{
[Fact]
public void TestCityNames()
{
var filler = new Filler<CollectionizerPoco>();

filler.Setup()
.OnProperty(x => x.ArrayList)
.Use(new Collectionizer<string, MnemonicString>(new MnemonicString(1, 20, 25), 3, 10));

var arrayList = filler.Create();
Assert.True(arrayList.ArrayList.Count >= 3 && arrayList.ArrayList.Count <= 10);
Assert.True(arrayList.ArrayList.ToArray().Cast<string>().All(x => x.Length >= 20 && x.Length <= 25));
}

[Fact]
public void TestMnemonicStringPlugin()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;

namespace Tynamix.ObjectFiller
{
Expand All @@ -8,6 +9,9 @@ namespace Tynamix.ObjectFiller
/// <typeparam name="T">Typeparameter of of the target List</typeparam>
/// <typeparam name="TRandomizer">Plugin which will be used to create the List</typeparam>
public class Collectionizer<T, TRandomizer> : IRandomizerPlugin<List<T>>
#if !NETSTD
, IRandomizerPlugin<ArrayList>
#endif
where TRandomizer : IRandomizerPlugin<T>, new()
{
private readonly IRandomizerPlugin<T> randomizerToUse;
Expand Down Expand Up @@ -105,5 +109,20 @@ public List<T> GetValue()

return result;
}

#if !NETSTD
/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
ArrayList IRandomizerPlugin<ArrayList>.GetValue()
{
ArrayList arrayList = new ArrayList();
arrayList.AddRange(this.GetValue());

return arrayList;
}
#endif
}

}
5 changes: 5 additions & 0 deletions Tynamix.ObjectFiller/Setup/FillerSetupItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Collections;

namespace Tynamix.ObjectFiller
{
using System;
Expand Down Expand Up @@ -152,6 +154,9 @@ private void SetDefaultRandomizer()
this.TypeToRandomFunc[typeof(IntPtr?)] = () => default(IntPtr);
this.TypeToRandomFunc[typeof(TimeSpan)] = () => new TimeSpan(Random.Next());
this.TypeToRandomFunc[typeof(TimeSpan?)] = () => new TimeSpan(Random.Next());
#if !NETSTD
this.TypeToRandomFunc[typeof(ArrayList)] = () => ((IRandomizerPlugin<ArrayList>)new Collectionizer<string, MnemonicString>()).GetValue();
#endif
}
}
}

0 comments on commit 83f7526

Please sign in to comment.