Skip to content

Commit 34a8ec0

Browse files
committed
Unittest for bugfix
1 parent 7d2a169 commit 34a8ec0

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
4+
namespace Tynamix.ObjectFiller.Test.BugfixTests
5+
{
6+
[TestClass]
7+
public class Bug129WrongDateTimeGeneration
8+
{
9+
public class TestEntity
10+
{
11+
public DateTime Date { get; set; }
12+
}
13+
14+
[TestMethod]
15+
public void InvalidDateTimeValuesDueToDaylightSavingsTime()
16+
{
17+
Filler<TestEntity> filler = new Filler<TestEntity>();
18+
19+
filler.Setup().OnType<DateTime>().Use(new DateTimeRange(new DateTime(2007, 3, 11, 1, 0, 0, DateTimeKind.Unspecified), new DateTime(2007, 3, 11, 4, 00, 0, DateTimeKind.Unspecified)));
20+
21+
for (int i = 0; i < 1000; i++)
22+
{
23+
var result = filler.Create();
24+
Assert.IsFalse(TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time").IsInvalidTime(result.Date));
25+
}
26+
27+
28+
29+
}
30+
}
31+
}

Tynamix.ObjectFiller/Plugins/DateTime/DateTimeRange.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class DateTimeRange : IRandomizerPlugin<DateTime>, IRandomizerPlugin<Date
2121
/// Initializes a new instance of the <see cref="DateTimeRange"/> class.
2222
/// </summary>
2323
public DateTimeRange()
24+
: this(DateTime.MinValue)
2425
{
2526
}
2627

@@ -73,7 +74,8 @@ public DateTime GetValue()
7374

7475
var diff = Random.NextLong(0, timeSpan.Ticks);
7576

76-
return this.latestDate.AddTicks(diff * -1);
77+
var generatedDate = this.latestDate.AddTicks(diff * -1);
78+
return TimeZoneInfo.Utc.IsInvalidTime(generatedDate) ? GetValue() : generatedDate;
7779
}
7880

7981
/// <summary>

Tynamix.ObjectFiller/Tynamix.ObjectFiller.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net35;net452;</TargetFrameworks>
55
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
6-
<Version>1.5.6</Version>
6+
<Version>1.5.7</Version>
77
<Authors>Roman Lautner, Hendrik L., Christian Harlass, GothikX</Authors>
88
<Company>Tynamix</Company>
99
<PackageLicenseUrl></PackageLicenseUrl>

0 commit comments

Comments
 (0)