Skip to content

Commit cf4403e

Browse files
committed
Merge pull request #74 from Tynamix/64_73_PluginRefactoring
64 73 plugin refactoring
2 parents d18b6c8 + 134cfb3 commit cf4403e

File tree

10 files changed

+317
-42
lines changed

10 files changed

+317
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,5 @@ FakesAssemblies/
176176
ObjectFillerNET.v2.ncrunchsolution
177177
ObjectFiller/ObjectFiller.v2.ncrunchproject
178178
ObjectFiller.Test/ObjectFiller.Test.v2.ncrunchproject
179+
.vs/config/applicationhost.config
180+
Output-Build.txt

Tynamix.ObjectFiller.Test/LoremIpsumPluginTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Linq;
3-
using Xunit;
3+
using Xunit;
44
using ObjectFiller.Test.TestPoco.Library;
55
using Tynamix.ObjectFiller;
66

@@ -17,7 +17,7 @@ public void Test_With_Many_MinWords_And_Many_MinSentences()
1717
{
1818
Filler<Book> book = new Filler<Book>();
1919
book.Setup()
20-
.OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.InDerFremde, 3, 9, minWords: 51));
20+
.OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.InDerFremde, 51, 100, 100));
2121

2222
var b = book.Create();
2323

@@ -67,7 +67,7 @@ public void Test_With_LoremIpsum_Seed_Settings()
6767
{
6868
Filler<Book> book = new Filler<Book>();
6969
book.Setup()
70-
.OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.LoremIpsum, seed: 1234));
70+
.OnProperty(x => x.ISBN).Use(new Lipsum(LipsumFlavor.LoremIpsum, 3, 5, 1, 5, 3, 1234));
7171

7272
var b = book.Create();
7373
var b1 = book.Create();

Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,87 @@
22

33
namespace Tynamix.ObjectFiller
44
{
5+
/// <summary>
6+
/// The date time range plugin.
7+
/// </summary>
58
public class DateTimeRange : IRandomizerPlugin<DateTime>, IRandomizerPlugin<DateTime?>
69
{
7-
private readonly DateTime _earliestDate;
8-
private readonly DateTime _latestDate;
10+
/// <summary>
11+
/// The earliest date.
12+
/// </summary>
13+
private readonly DateTime earliestDate;
914

15+
/// <summary>
16+
/// The latest date.
17+
/// </summary>
18+
private readonly DateTime latestDate;
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
22+
/// </summary>
23+
public DateTimeRange()
24+
{
25+
}
26+
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
29+
/// </summary>
30+
/// <param name="earliestDate">
31+
/// The earliest date.
32+
/// </param>
1033
public DateTimeRange(DateTime earliestDate)
1134
: this(earliestDate, DateTime.Now)
1235
{
1336
}
1437

38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
40+
/// </summary>
41+
/// <param name="earliestDate">
42+
/// The earliest date.
43+
/// </param>
44+
/// <param name="latestDate">
45+
/// The latest date.
46+
/// </param>
1547
public DateTimeRange(DateTime earliestDate, DateTime latestDate)
1648
{
17-
1849
if (earliestDate > latestDate)
1950
{
20-
this._latestDate = earliestDate;
21-
this._earliestDate = latestDate;
51+
this.latestDate = earliestDate;
52+
this.earliestDate = latestDate;
2253
}
2354
else if (earliestDate == latestDate)
2455
{
25-
this._latestDate = latestDate.AddMonths(Random.Next(1, 120));
26-
this._earliestDate = earliestDate;
56+
this.latestDate = latestDate.AddMonths(Random.Next(1, 120));
57+
this.earliestDate = earliestDate;
2758
}
2859
else
2960
{
30-
this._earliestDate = earliestDate;
31-
this._latestDate = latestDate;
61+
this.earliestDate = earliestDate;
62+
this.latestDate = latestDate;
3263
}
3364
}
3465

66+
/// <summary>
67+
/// Gets random data for type <see cref="T"/>
68+
/// </summary>
69+
/// <returns>Random data for type <see cref="T"/></returns>
3570
public DateTime GetValue()
3671
{
37-
var timeSpan = _latestDate.Subtract(_earliestDate);
72+
var timeSpan = this.latestDate.Subtract(this.earliestDate);
3873

3974
var diff = Random.NextLong(0, timeSpan.Ticks);
4075

41-
return _latestDate.AddTicks(diff * -1);
76+
return this.latestDate.AddTicks(diff * -1);
4277
}
4378

79+
/// <summary>
80+
/// Gets random data for type <see cref="T"/>
81+
/// </summary>
82+
/// <returns>Random data for type <see cref="T"/></returns>
4483
DateTime? IRandomizerPlugin<DateTime?>.GetValue()
4584
{
46-
return GetValue();
85+
return this.GetValue();
4786
}
4887
}
4988
}

Tynamix.ObjectFiller/Plugins/Double/DoubleRange.cs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
using System;
2-
31
namespace Tynamix.ObjectFiller
42
{
5-
public class DoubleRange : IRandomizerPlugin<double>, IRandomizerPlugin<double?>,IRandomizerPlugin<decimal>, IRandomizerPlugin<decimal?>
3+
/// <summary>
4+
/// The double range plugin
5+
/// </summary>
6+
public class DoubleRange : IRandomizerPlugin<double>, IRandomizerPlugin<double?>, IRandomizerPlugin<decimal>, IRandomizerPlugin<decimal?>
67
{
7-
private readonly double _minValue;
8-
private readonly double _maxValue;
8+
/// <summary>
9+
/// The min value.
10+
/// </summary>
11+
private readonly double minValue;
12+
13+
/// <summary>
14+
/// The max value.
15+
/// </summary>
16+
private readonly double maxValue;
917

1018
/// <summary>
19+
/// Initializes a new instance of the <see cref="DoubleRange"/> class.
1120
/// Use to define just a max value for the double randomizer. Min value will be 0!
1221
/// </summary>
13-
/// <param name="maxValue">Maximum double value</param>
22+
/// <param name="maxValue">
23+
/// Maximum double value
24+
/// </param>
1425
public DoubleRange(double maxValue)
1526
: this(0, maxValue)
1627
{
@@ -19,17 +30,23 @@ public DoubleRange(double maxValue)
1930

2031

2132
/// <summary>
33+
/// Initializes a new instance of the <see cref="DoubleRange"/> class.
2234
/// Use to define a min and max double value for the randomizer
2335
/// </summary>
24-
/// <param name="minValue">Min value</param>
25-
/// <param name="maxValue">Max value</param>
36+
/// <param name="minValue">
37+
/// Min value
38+
/// </param>
39+
/// <param name="maxValue">
40+
/// Max value
41+
/// </param>
2642
public DoubleRange(double minValue, double maxValue)
2743
{
28-
_minValue = minValue;
29-
_maxValue = maxValue;
44+
this.minValue = minValue;
45+
this.maxValue = maxValue;
3046
}
3147

3248
/// <summary>
49+
/// Initializes a new instance of the <see cref="DoubleRange"/> class.
3350
/// Use this to generate a double value between double.MinValue and double.MaxValue
3451
/// </summary>
3552
public DoubleRange()
@@ -38,21 +55,37 @@ public DoubleRange()
3855

3956
}
4057

58+
/// <summary>
59+
/// Gets random data for type <see cref="T"/>
60+
/// </summary>
61+
/// <returns>Random data for type <see cref="T"/></returns>
4162
public double GetValue()
4263
{
43-
return Random.NextDouble() * (_maxValue - _minValue) + _minValue;
64+
return Random.NextDouble() * (this.maxValue - this.minValue) + this.minValue;
4465
}
4566

67+
/// <summary>
68+
/// Gets random data for type <see cref="T"/>
69+
/// </summary>
70+
/// <returns>Random data for type <see cref="T"/></returns>
4671
double? IRandomizerPlugin<double?>.GetValue()
4772
{
48-
return GetValue();
73+
return this.GetValue();
4974
}
5075

76+
/// <summary>
77+
/// Gets random data for type <see cref="T"/>
78+
/// </summary>
79+
/// <returns>Random data for type <see cref="T"/></returns>
5180
decimal IRandomizerPlugin<decimal>.GetValue()
5281
{
53-
return (decimal) GetValue();
82+
return (decimal)GetValue();
5483
}
5584

85+
/// <summary>
86+
/// Gets random data for type <see cref="T"/>
87+
/// </summary>
88+
/// <returns>Random data for type <see cref="T"/></returns>
5689
decimal? IRandomizerPlugin<decimal?>.GetValue()
5790
{
5891
return (decimal)GetValue();

Tynamix.ObjectFiller/Plugins/Integer/IntRange.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,69 @@
11
namespace Tynamix.ObjectFiller
22
{
3+
using System;
4+
5+
/// <summary>
6+
/// The integer range plugin
7+
/// </summary>
38
public class IntRange : IRandomizerPlugin<int>, IRandomizerPlugin<int?>
49
{
5-
private readonly int _min;
6-
private readonly int _max;
10+
/// <summary>
11+
/// The min value
12+
/// </summary>
13+
private readonly int min;
14+
15+
/// <summary>
16+
/// The max value
17+
/// </summary>
18+
private readonly int max;
719

20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="IntRange"/> class.
22+
/// </summary>
23+
/// <param name="min">
24+
/// The min value
25+
/// </param>
26+
/// <param name="max">
27+
/// The max value
28+
/// </param>
829
public IntRange(int min, int max)
930
{
10-
_min = min;
11-
_max = max;
31+
this.min = min;
32+
this.max = max;
1233
}
1334

35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="IntRange"/> class.
37+
/// </summary>
38+
/// <param name="max">
39+
/// The max.
40+
/// </param>
1441
public IntRange(int max)
15-
: this(0, max)
42+
: this(int.MinValue, max)
1643
{
44+
}
1745

46+
/// <summary>
47+
/// Initializes a new instance of the <see cref="IntRange"/> class.
48+
/// </summary>
49+
public IntRange()
50+
: this(int.MinValue, int.MaxValue)
51+
{
1852
}
1953

54+
/// <summary>
55+
/// Gets random data for type <see cref="T"/>
56+
/// </summary>
57+
/// <returns>Random data for type <see cref="T"/></returns>
2058
public int GetValue()
2159
{
22-
return Random.Next(_min, _max);
60+
return Random.Next(this.min, this.max);
2361
}
2462

63+
/// <summary>
64+
/// Gets random data for type <see cref="T"/>
65+
/// </summary>
66+
/// <returns>Random data for type <see cref="T"/></returns>
2567
int? IRandomizerPlugin<int?>.GetValue()
2668
{
2769
return GetValue();

0 commit comments

Comments
 (0)