From 82bf144be650b17d37b00465a50fb3e25e062d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20K=C3=B6hler?= Date: Tue, 8 Mar 2016 23:59:34 +0100 Subject: [PATCH] #65 implemented --- .../CollectionizerTest.cs | 19 ++++++++++++++++- .../Plugins/{ => List}/Collectionizer.cs | 21 ++++++++++++++++++- Tynamix.ObjectFiller/Setup/FillerSetupItem.cs | 5 +++++ 3 files changed, 43 insertions(+), 2 deletions(-) rename Tynamix.ObjectFiller/Plugins/{ => List}/Collectionizer.cs (88%) diff --git a/Tynamix.ObjectFiller.Test/CollectionizerTest.cs b/Tynamix.ObjectFiller.Test/CollectionizerTest.cs index 66e8f93..c13d1e0 100644 --- a/Tynamix.ObjectFiller.Test/CollectionizerTest.cs +++ b/Tynamix.ObjectFiller.Test/CollectionizerTest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; using System.Linq; using Tynamix.ObjectFiller; using Xunit; @@ -10,10 +11,26 @@ public class CollectionizerPoco public IEnumerable MnemonicStrings { get; set; } public List IntRange { get; set; } + + public ArrayList ArrayList { get; set; } } public class CollectionizerTest { + [Fact] + public void TestCityNames() + { + var filler = new Filler(); + + filler.Setup() + .OnProperty(x => x.ArrayList) + .Use(new Collectionizer(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().All(x => x.Length >= 20 && x.Length <= 25)); + } + [Fact] public void TestMnemonicStringPlugin() { diff --git a/Tynamix.ObjectFiller/Plugins/Collectionizer.cs b/Tynamix.ObjectFiller/Plugins/List/Collectionizer.cs similarity index 88% rename from Tynamix.ObjectFiller/Plugins/Collectionizer.cs rename to Tynamix.ObjectFiller/Plugins/List/Collectionizer.cs index 9169561..2a4ec7d 100644 --- a/Tynamix.ObjectFiller/Plugins/Collectionizer.cs +++ b/Tynamix.ObjectFiller/Plugins/List/Collectionizer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; namespace Tynamix.ObjectFiller { @@ -8,6 +9,9 @@ namespace Tynamix.ObjectFiller /// Typeparameter of of the target List /// Plugin which will be used to create the List public class Collectionizer : IRandomizerPlugin> +#if !NETSTD + , IRandomizerPlugin +#endif where TRandomizer : IRandomizerPlugin, new() { private readonly IRandomizerPlugin randomizerToUse; @@ -105,5 +109,20 @@ public List GetValue() return result; } + +#if !NETSTD + /// + /// Gets random data for type + /// + /// Random data for type + ArrayList IRandomizerPlugin.GetValue() + { + ArrayList arrayList = new ArrayList(); + arrayList.AddRange(this.GetValue()); + + return arrayList; + } +#endif } + } diff --git a/Tynamix.ObjectFiller/Setup/FillerSetupItem.cs b/Tynamix.ObjectFiller/Setup/FillerSetupItem.cs index 0e0977d..1e56b2b 100644 --- a/Tynamix.ObjectFiller/Setup/FillerSetupItem.cs +++ b/Tynamix.ObjectFiller/Setup/FillerSetupItem.cs @@ -8,6 +8,8 @@ // // -------------------------------------------------------------------------------------------------------------------- +using System.Collections; + namespace Tynamix.ObjectFiller { using System; @@ -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)new Collectionizer()).GetValue(); +#endif } } }