-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathDateTimeRangeTest.cs
69 lines (52 loc) · 2.22 KB
/
DateTimeRangeTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tynamix.ObjectFiller.Test
{
public class DateRangeTestClass
{
public DateTime Date { get; set; }
}
[TestClass]
public class DateTimeRangeTest
{
[TestMethod]
public void WhenGettingDatesBetweenNowAnd31DaysAgo()
{
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();
filler.Setup().OnType<DateTime>().Use(
new DateTimeRange(DateTime.Now.AddDays(-31)));
var d = filler.Create(1000);
Assert.IsTrue(d.All(x => x.Date < DateTime.Now && x.Date > DateTime.Now.AddDays(-31)));
}
[TestMethod]
public void WhenStartDateIsBiggerThenEndDateTheDatesShouldBeSwitched()
{
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();
filler.Setup().OnType<DateTime>().Use(
new DateTimeRange(DateTime.Now, DateTime.Now.AddDays(-31)));
var d = filler.Create(1000);
Assert.IsTrue(d.All(x => x.Date < DateTime.Now && x.Date > DateTime.Now.AddDays(-31)));
}
[TestMethod]
public void WhenStartDateAndEndDateIsSetItShouldFindOnlyDatesInBetweenThisTwoDates()
{
var startDate = new DateTime(2000, 11, 10);
var endDate = new DateTime(2006, 1, 30);
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();
filler.Setup().OnType<DateTime>().Use(new DateTimeRange(startDate, endDate));
var d = filler.Create(1000);
d.ToList().ForEach(x => Console.WriteLine(x.Date));
Assert.IsTrue(d.All(x => x.Date < endDate && x.Date > startDate));
}
[TestMethod]
public void WhenConstructorWithDateTimeNowWillBeCalledNoExceptionShouldBeThrown()
{
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();
filler.Setup().OnProperty(x => x.Date).Use(new DateTimeRange(DateTime.Now));
var dateTime = filler.Create();
Assert.IsTrue(dateTime.Date > DateTime.MinValue);
Assert.IsTrue(dateTime.Date < DateTime.MaxValue);
}
}
}