From e5f069bbac64170f8d01cbaf8cc63be36f8507f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20K=C3=B6hler?= Date: Fri, 4 Mar 2016 13:21:38 +0100 Subject: [PATCH 1/3] #64 and #73 implemented. Lipsum plugin is worth to think about optional parameter?! --- .../LoremIpsumPluginTest.cs | 6 +- .../Plugins/DateTime/DateTimeRange.cs | 63 ++++++-- .../Plugins/Double/DoubleRange.cs | 59 +++++-- .../Plugins/Integer/IntRange.cs | 54 ++++++- Tynamix.ObjectFiller/Plugins/String/Lipsum.cs | 148 +++++++++++++++++- .../Plugins/String/MnemonicString.cs | 8 + .../Plugins/String/PatternGenerator.cs | 8 + .../Plugins/String/RealNames.cs | 8 + .../Plugins/String/StreetName.cs | 9 ++ 9 files changed, 321 insertions(+), 42 deletions(-) diff --git a/Tynamix.ObjectFiller.Test/LoremIpsumPluginTest.cs b/Tynamix.ObjectFiller.Test/LoremIpsumPluginTest.cs index 8b973cb..58996ab 100644 --- a/Tynamix.ObjectFiller.Test/LoremIpsumPluginTest.cs +++ b/Tynamix.ObjectFiller.Test/LoremIpsumPluginTest.cs @@ -1,6 +1,6 @@ using System; using System.Linq; - using Xunit; +using Xunit; using ObjectFiller.Test.TestPoco.Library; using Tynamix.ObjectFiller; @@ -17,7 +17,7 @@ public void Test_With_Many_MinWords_And_Many_MinSentences() { Filler book = new Filler(); book.Setup() - .OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.InDerFremde, 3, 9, minWords: 51)); + .OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.InDerFremde, 51, 100, 100)); var b = book.Create(); @@ -67,7 +67,7 @@ public void Test_With_LoremIpsum_Seed_Settings() { Filler book = new Filler(); book.Setup() - .OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.LoremIpsum, seed: 1234)); + .OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.LoremIpsum, 3, 5, 1, 5, 3, 1234)); var b = book.Create(); var b1 = book.Create(); diff --git a/Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs b/Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs index fe9d009..2ecda0e 100644 --- a/Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs +++ b/Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs @@ -2,48 +2,87 @@ namespace Tynamix.ObjectFiller { + /// + /// The date time range plugin. + /// public class DateTimeRange : IRandomizerPlugin, IRandomizerPlugin { - private readonly DateTime _earliestDate; - private readonly DateTime _latestDate; + /// + /// The earliest date. + /// + private readonly DateTime earliestDate; + /// + /// The latest date. + /// + private readonly DateTime latestDate; + + /// + /// Initializes a new instance of the class. + /// + public DateTimeRange() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The earliest date. + /// public DateTimeRange(DateTime earliestDate) : this(earliestDate, DateTime.Now) { } + /// + /// Initializes a new instance of the class. + /// + /// + /// The earliest date. + /// + /// + /// The latest date. + /// public DateTimeRange(DateTime earliestDate, DateTime latestDate) { - if (earliestDate > latestDate) { - this._latestDate = earliestDate; - this._earliestDate = latestDate; + this.latestDate = earliestDate; + this.earliestDate = latestDate; } else if (earliestDate == latestDate) { - this._latestDate = latestDate.AddMonths(Random.Next(1, 120)); - this._earliestDate = earliestDate; + this.latestDate = latestDate.AddMonths(Random.Next(1, 120)); + this.earliestDate = earliestDate; } else { - this._earliestDate = earliestDate; - this._latestDate = latestDate; + this.earliestDate = earliestDate; + this.latestDate = latestDate; } } + /// + /// Gets random data for type + /// + /// Random data for type public DateTime GetValue() { - var timeSpan = _latestDate.Subtract(_earliestDate); + var timeSpan = this.latestDate.Subtract(this.earliestDate); var diff = Random.NextLong(0, timeSpan.Ticks); - return _latestDate.AddTicks(diff * -1); + return this.latestDate.AddTicks(diff * -1); } + /// + /// Gets random data for type + /// + /// Random data for type DateTime? IRandomizerPlugin.GetValue() { - return GetValue(); + return this.GetValue(); } } } diff --git a/Tynamix.ObjectFiller/Plugins/Double/DoubleRange.cs b/Tynamix.ObjectFiller/Plugins/Double/DoubleRange.cs index a936983..5ae7982 100644 --- a/Tynamix.ObjectFiller/Plugins/Double/DoubleRange.cs +++ b/Tynamix.ObjectFiller/Plugins/Double/DoubleRange.cs @@ -1,16 +1,27 @@ -using System; - namespace Tynamix.ObjectFiller { - public class DoubleRange : IRandomizerPlugin, IRandomizerPlugin,IRandomizerPlugin, IRandomizerPlugin + /// + /// The double range plugin + /// + public class DoubleRange : IRandomizerPlugin, IRandomizerPlugin, IRandomizerPlugin, IRandomizerPlugin { - private readonly double _minValue; - private readonly double _maxValue; + /// + /// The min value. + /// + private readonly double minValue; + + /// + /// The max value. + /// + private readonly double maxValue; /// + /// Initializes a new instance of the class. /// Use to define just a max value for the double randomizer. Min value will be 0! /// - /// Maximum double value + /// + /// Maximum double value + /// public DoubleRange(double maxValue) : this(0, maxValue) { @@ -19,17 +30,23 @@ public DoubleRange(double maxValue) /// + /// Initializes a new instance of the class. /// Use to define a min and max double value for the randomizer /// - /// Min value - /// Max value + /// + /// Min value + /// + /// + /// Max value + /// public DoubleRange(double minValue, double maxValue) { - _minValue = minValue; - _maxValue = maxValue; + this.minValue = minValue; + this.maxValue = maxValue; } /// + /// Initializes a new instance of the class. /// Use this to generate a double value between double.MinValue and double.MaxValue /// public DoubleRange() @@ -38,21 +55,37 @@ public DoubleRange() } + /// + /// Gets random data for type + /// + /// Random data for type public double GetValue() { - return Random.NextDouble() * (_maxValue - _minValue) + _minValue; + return Random.NextDouble() * (this.maxValue - this.minValue) + this.minValue; } + /// + /// Gets random data for type + /// + /// Random data for type double? IRandomizerPlugin.GetValue() { - return GetValue(); + return this.GetValue(); } + /// + /// Gets random data for type + /// + /// Random data for type decimal IRandomizerPlugin.GetValue() { - return (decimal) GetValue(); + return (decimal)GetValue(); } + /// + /// Gets random data for type + /// + /// Random data for type decimal? IRandomizerPlugin.GetValue() { return (decimal)GetValue(); diff --git a/Tynamix.ObjectFiller/Plugins/Integer/IntRange.cs b/Tynamix.ObjectFiller/Plugins/Integer/IntRange.cs index 5351eec..3f322be 100644 --- a/Tynamix.ObjectFiller/Plugins/Integer/IntRange.cs +++ b/Tynamix.ObjectFiller/Plugins/Integer/IntRange.cs @@ -1,27 +1,69 @@ namespace Tynamix.ObjectFiller { + using System; + + /// + /// The integer range plugin + /// public class IntRange : IRandomizerPlugin, IRandomizerPlugin { - private readonly int _min; - private readonly int _max; + /// + /// The min value + /// + private readonly int min; + + /// + /// The max value + /// + private readonly int max; + /// + /// Initializes a new instance of the class. + /// + /// + /// The min value + /// + /// + /// The max value + /// public IntRange(int min, int max) { - _min = min; - _max = max; + this.min = min; + this.max = max; } + /// + /// Initializes a new instance of the class. + /// + /// + /// The max. + /// public IntRange(int max) - : this(0, max) + : this(int.MinValue, max) { + } + /// + /// Initializes a new instance of the class. + /// + public IntRange() + : this(int.MinValue, int.MaxValue) + { } + /// + /// Gets random data for type + /// + /// Random data for type public int GetValue() { - return Random.Next(_min, _max); + return Random.Next(this.min, this.max); } + /// + /// Gets random data for type + /// + /// Random data for type int? IRandomizerPlugin.GetValue() { return GetValue(); diff --git a/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs b/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs index e444a29..86429c9 100644 --- a/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs +++ b/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs @@ -4,7 +4,11 @@ namespace Tynamix.ObjectFiller { + using System.Runtime.CompilerServices; + /// + /// The lipsum flavor. + /// public enum LipsumFlavor { /// @@ -130,16 +134,96 @@ public class Lipsum : IRandomizerPlugin /// private readonly Dictionary map; + /// + /// The random. + /// private System.Random random; /// /// Initializes a new instance of the class. /// - /// + public Lipsum() + : this(LipsumFlavor.LoremIpsum) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// /// The flavor for the generated text /// - /// - /// The count of generated paragraphs. + public Lipsum(LipsumFlavor lipsumFlavor) + : this(lipsumFlavor, 10) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The flavor for the generated text + /// + /// + /// The min words of the generated text. + /// + public Lipsum(LipsumFlavor lipsumFlavor, int minWords) + : this(lipsumFlavor, minWords, 50) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The flavor for the generated text + /// + /// + /// The min words of the generated text. + /// + /// + /// The max words of the generated text. + /// + public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords) + : this(lipsumFlavor, minWords, maxWords, 3) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The flavor for the generated text + /// + /// + /// The min words of the generated text. + /// + /// + /// The max words of the generated text. + /// + /// + /// The min sentences of the generated text + /// + public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences) + : this(lipsumFlavor, minWords, maxWords, minSentences, 8) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The flavor for the generated text + /// + /// + /// The min words of the generated text. + /// + /// + /// The max words of the generated text. /// /// /// The min sentences of the generated text @@ -147,19 +231,67 @@ public class Lipsum : IRandomizerPlugin /// /// The max sentences of the generated text /// + public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences, int maxSentences) + : this(lipsumFlavor, minWords, maxWords, minSentences, maxSentences, 3) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The flavor for the generated text + /// /// /// The min words of the generated text. /// /// /// The max words of the generated text. /// - /// + /// + /// The min sentences of the generated text + /// + /// + /// The max sentences of the generated text + /// + /// + /// The count of generated paragraphs. + /// + public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences, int maxSentences, int paragraphs) + : this(lipsumFlavor, minWords, maxWords, minSentences, maxSentences, paragraphs, null) + + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The flavor for the generated text + /// + /// + /// The min words of the generated text. + /// + /// + /// The max words of the generated text. + /// + /// + /// The min sentences of the generated text + /// + /// + /// The max sentences of the generated text + /// + /// + /// The count of generated paragraphs. + /// + /// /// The seed for randomizer to get the same result with the same seed. /// - public Lipsum(LipsumFlavor flavor, int paragraphs = 3, int minSentences = 3, int maxSentences = 8, - int minWords = 10, int maxWords = 50, int? seed = null) + public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences, int maxSentences, int paragraphs, int? randomSeed) { - this.flavor = flavor; + this.flavor = lipsumFlavor; this.paragraphs = paragraphs; this.minSentences = minSentences; this.maxSentences = maxSentences < minSentences ? minSentences : maxSentences; @@ -174,7 +306,7 @@ public Lipsum(LipsumFlavor flavor, int paragraphs = 3, int minSentences = 3, int { LipsumFlavor.LeMasque, LeMasque } }; - this.seed = seed; + this.seed = randomSeed; this.random = new System.Random(); } diff --git a/Tynamix.ObjectFiller/Plugins/String/MnemonicString.cs b/Tynamix.ObjectFiller/Plugins/String/MnemonicString.cs index 64c0303..e825e9f 100644 --- a/Tynamix.ObjectFiller/Plugins/String/MnemonicString.cs +++ b/Tynamix.ObjectFiller/Plugins/String/MnemonicString.cs @@ -31,6 +31,14 @@ public class MnemonicString : IRandomizerPlugin /// private readonly int wordMaxLength; + /// + /// Initializes a new instance of the class. + /// + public MnemonicString() + : this(1) + { + } + /// /// Initializes a new instance of the class. /// diff --git a/Tynamix.ObjectFiller/Plugins/String/PatternGenerator.cs b/Tynamix.ObjectFiller/Plugins/String/PatternGenerator.cs index 6f6c6aa..e10951e 100644 --- a/Tynamix.ObjectFiller/Plugins/String/PatternGenerator.cs +++ b/Tynamix.ObjectFiller/Plugins/String/PatternGenerator.cs @@ -86,6 +86,14 @@ public class PatternGenerator : IRandomizerPlugin #region PatternGenerator class implementation + /// + /// Initializes a new instance of the class. + /// + public PatternGenerator() + : this("{A:3-22}") + { + } + /// /// Creates values based on a pattern. /// diff --git a/Tynamix.ObjectFiller/Plugins/String/RealNames.cs b/Tynamix.ObjectFiller/Plugins/String/RealNames.cs index 6259614..0b28858 100644 --- a/Tynamix.ObjectFiller/Plugins/String/RealNames.cs +++ b/Tynamix.ObjectFiller/Plugins/String/RealNames.cs @@ -57,6 +57,14 @@ public class RealNames : IRandomizerPlugin /// private readonly string[] lastNames; + /// + /// Initializes a new instance of the class. + /// + public RealNames() + : this(NameStyle.FirstNameLastName) + { + } + /// /// Initializes a new instance of the class. /// diff --git a/Tynamix.ObjectFiller/Plugins/String/StreetName.cs b/Tynamix.ObjectFiller/Plugins/String/StreetName.cs index 288fc35..7fb7d28 100644 --- a/Tynamix.ObjectFiller/Plugins/String/StreetName.cs +++ b/Tynamix.ObjectFiller/Plugins/String/StreetName.cs @@ -59,6 +59,15 @@ public class StreetName : IRandomizerPlugin /// protected readonly List AllStreetNames; + /// + /// Initializes a new instance of the class. + /// It will use streets of London by default + /// + public StreetName() + : this(City.London) + { + } + /// /// Initializes a new instance of the class. /// From fd4ae09fc22a0b8274d5753f87f8b3b5d59db8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20K=C3=B6hler?= Date: Fri, 4 Mar 2016 15:49:04 +0100 Subject: [PATCH 2/3] Lipsum plugin constructor with all parameters changed to be with optional parameters #64 --- Tynamix.ObjectFiller/Plugins/String/Lipsum.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs b/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs index 86429c9..eb2cecb 100644 --- a/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs +++ b/Tynamix.ObjectFiller/Plugins/String/Lipsum.cs @@ -156,7 +156,6 @@ public Lipsum() public Lipsum(LipsumFlavor lipsumFlavor) : this(lipsumFlavor, 10) { - } /// @@ -171,7 +170,6 @@ public Lipsum(LipsumFlavor lipsumFlavor) public Lipsum(LipsumFlavor lipsumFlavor, int minWords) : this(lipsumFlavor, minWords, 50) { - } /// @@ -189,7 +187,6 @@ public Lipsum(LipsumFlavor lipsumFlavor, int minWords) public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords) : this(lipsumFlavor, minWords, maxWords, 3) { - } /// @@ -210,7 +207,6 @@ public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords) public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences) : this(lipsumFlavor, minWords, maxWords, minSentences, 8) { - } /// @@ -234,7 +230,6 @@ public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSent public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences, int maxSentences) : this(lipsumFlavor, minWords, maxWords, minSentences, maxSentences, 3) { - } /// @@ -262,7 +257,6 @@ public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSent : this(lipsumFlavor, minWords, maxWords, minSentences, maxSentences, paragraphs, null) { - } /// @@ -289,7 +283,7 @@ public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSent /// /// The seed for randomizer to get the same result with the same seed. /// - public Lipsum(LipsumFlavor lipsumFlavor, int minWords, int maxWords, int minSentences, int maxSentences, int paragraphs, int? randomSeed) + public Lipsum(LipsumFlavor lipsumFlavor, int minWords = 10, int maxWords = 50, int minSentences = 3, int maxSentences = 8, int paragraphs = 3, int? randomSeed = null) { this.flavor = lipsumFlavor; this.paragraphs = paragraphs; From 134cfb34e1e0f7b6628c60ee55078197c4997abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20K=C3=B6hler?= Date: Fri, 4 Mar 2016 15:49:41 +0100 Subject: [PATCH 3/3] gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 91fb72a..94ce00b 100644 --- a/.gitignore +++ b/.gitignore @@ -176,3 +176,5 @@ FakesAssemblies/ ObjectFillerNET.v2.ncrunchsolution ObjectFiller/ObjectFiller.v2.ncrunchproject ObjectFiller.Test/ObjectFiller.Test.v2.ncrunchproject +.vs/config/applicationhost.config +Output-Build.txt