Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Tynamix.ObjectFiller.Test/LoremIpsumPluginTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using Xunit;
using Xunit;
using ObjectFiller.Test.TestPoco.Library;
using Tynamix.ObjectFiller;

Expand All @@ -17,7 +17,7 @@ public void Test_With_Many_MinWords_And_Many_MinSentences()
{
Filler<Book> book = new Filler<Book>();
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();

Expand Down Expand Up @@ -67,7 +67,7 @@ public void Test_With_LoremIpsum_Seed_Settings()
{
Filler<Book> book = new Filler<Book>();
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();
Expand Down
63 changes: 51 additions & 12 deletions Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,87 @@

namespace Tynamix.ObjectFiller
{
/// <summary>
/// The date time range plugin.
/// </summary>
public class DateTimeRange : IRandomizerPlugin<DateTime>, IRandomizerPlugin<DateTime?>
{
private readonly DateTime _earliestDate;
private readonly DateTime _latestDate;
/// <summary>
/// The earliest date.
/// </summary>
private readonly DateTime earliestDate;

/// <summary>
/// The latest date.
/// </summary>
private readonly DateTime latestDate;

/// <summary>
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
/// </summary>
public DateTimeRange()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
/// </summary>
/// <param name="earliestDate">
/// The earliest date.
/// </param>
public DateTimeRange(DateTime earliestDate)
: this(earliestDate, DateTime.Now)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
/// </summary>
/// <param name="earliestDate">
/// The earliest date.
/// </param>
/// <param name="latestDate">
/// The latest date.
/// </param>
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;
}
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
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);
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
DateTime? IRandomizerPlugin<DateTime?>.GetValue()
{
return GetValue();
return this.GetValue();
}
}
}
59 changes: 46 additions & 13 deletions Tynamix.ObjectFiller/Plugins/Double/DoubleRange.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
using System;

namespace Tynamix.ObjectFiller
{
public class DoubleRange : IRandomizerPlugin<double>, IRandomizerPlugin<double?>,IRandomizerPlugin<decimal>, IRandomizerPlugin<decimal?>
/// <summary>
/// The double range plugin
/// </summary>
public class DoubleRange : IRandomizerPlugin<double>, IRandomizerPlugin<double?>, IRandomizerPlugin<decimal>, IRandomizerPlugin<decimal?>
{
private readonly double _minValue;
private readonly double _maxValue;
/// <summary>
/// The min value.
/// </summary>
private readonly double minValue;

/// <summary>
/// The max value.
/// </summary>
private readonly double maxValue;

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


/// <summary>
/// Initializes a new instance of the <see cref="DoubleRange"/> class.
/// Use to define a min and max double value for the randomizer
/// </summary>
/// <param name="minValue">Min value</param>
/// <param name="maxValue">Max value</param>
/// <param name="minValue">
/// Min value
/// </param>
/// <param name="maxValue">
/// Max value
/// </param>
public DoubleRange(double minValue, double maxValue)
{
_minValue = minValue;
_maxValue = maxValue;
this.minValue = minValue;
this.maxValue = maxValue;
}

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

}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
public double GetValue()
{
return Random.NextDouble() * (_maxValue - _minValue) + _minValue;
return Random.NextDouble() * (this.maxValue - this.minValue) + this.minValue;
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
double? IRandomizerPlugin<double?>.GetValue()
{
return GetValue();
return this.GetValue();
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
decimal IRandomizerPlugin<decimal>.GetValue()
{
return (decimal) GetValue();
return (decimal)GetValue();
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
decimal? IRandomizerPlugin<decimal?>.GetValue()
{
return (decimal)GetValue();
Expand Down
54 changes: 48 additions & 6 deletions Tynamix.ObjectFiller/Plugins/Integer/IntRange.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,69 @@
namespace Tynamix.ObjectFiller
{
using System;

/// <summary>
/// The integer range plugin
/// </summary>
public class IntRange : IRandomizerPlugin<int>, IRandomizerPlugin<int?>
{
private readonly int _min;
private readonly int _max;
/// <summary>
/// The min value
/// </summary>
private readonly int min;

/// <summary>
/// The max value
/// </summary>
private readonly int max;

/// <summary>
/// Initializes a new instance of the <see cref="IntRange"/> class.
/// </summary>
/// <param name="min">
/// The min value
/// </param>
/// <param name="max">
/// The max value
/// </param>
public IntRange(int min, int max)
{
_min = min;
_max = max;
this.min = min;
this.max = max;
}

/// <summary>
/// Initializes a new instance of the <see cref="IntRange"/> class.
/// </summary>
/// <param name="max">
/// The max.
/// </param>
public IntRange(int max)
: this(0, max)
: this(int.MinValue, max)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="IntRange"/> class.
/// </summary>
public IntRange()
: this(int.MinValue, int.MaxValue)
{
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
public int GetValue()
{
return Random.Next(_min, _max);
return Random.Next(this.min, this.max);
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
int? IRandomizerPlugin<int?>.GetValue()
{
return GetValue();
Expand Down
Loading