forked from Giannoudis/TimePeriodLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeTrimTest.cs
More file actions
97 lines (85 loc) · 5.25 KB
/
TimeTrimTest.cs
File metadata and controls
97 lines (85 loc) · 5.25 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// -- FILE ------------------------------------------------------------------
// name : TimeTrimTest.cs
// project : Itenso Time Period
// created : Jani Giannoudis - 2011.02.18
// language : C# 4.0
// environment: .NET 2.0
// copyright : (c) 2011-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using Itenso.TimePeriod;
using Xunit;
namespace Itenso.TimePeriodTests
{
// ------------------------------------------------------------------------
public sealed class TimeTrimTest : TestUnitBase
{
// ----------------------------------------------------------------------
[Trait("Category", "TimeTrim")]
[Fact]
public void MonthTest()
{
Assert.Equal( TimeTrim.Month( testDate ), new DateTime( testDate.Year, 1, 1 ) );
Assert.Equal( TimeTrim.Month( testDate, 6 ), new DateTime( testDate.Year, 6, 1 ) );
Assert.Equal( TimeTrim.Month( testDate, 6, 5 ), new DateTime( testDate.Year, 6, 5, 0, 0, 0 ) );
Assert.Equal( TimeTrim.Month( testDate, 6, 5, 4 ), new DateTime( testDate.Year, 6, 5, 4, 0, 0 ) );
Assert.Equal( TimeTrim.Month( testDate, 6, 5, 4, 23 ), new DateTime( testDate.Year, 6, 5, 4, 23, 0 ) );
Assert.Equal( TimeTrim.Month( testDate, 6, 5, 4, 23, 55 ), new DateTime( testDate.Year, 6, 5, 4, 23, 55 ) );
Assert.Equal( TimeTrim.Month( testDate, 6, 5, 4, 23, 55, 128 ), new DateTime( testDate.Year, 6, 5, 4, 23, 55, 128 ) );
} // MonthTest
// ----------------------------------------------------------------------
[Trait("Category", "TimeTrim")]
[Fact]
public void DayTest()
{
Assert.Equal( TimeTrim.Day( testDate ), new DateTime( testDate.Year, testDate.Month, 1 ) );
Assert.Equal( TimeTrim.Day( testDate, 5 ), new DateTime( testDate.Year, testDate.Month, 5, 0, 0, 0 ) );
Assert.Equal( TimeTrim.Day( testDate, 5, 4 ), new DateTime( testDate.Year, testDate.Month, 5, 4, 0, 0 ) );
Assert.Equal( TimeTrim.Day( testDate, 5, 4, 23 ), new DateTime( testDate.Year, testDate.Month, 5, 4, 23, 0 ) );
Assert.Equal( TimeTrim.Day( testDate, 5, 4, 23, 55 ), new DateTime( testDate.Year, testDate.Month, 5, 4, 23, 55 ) );
Assert.Equal( TimeTrim.Day( testDate, 5, 4, 23, 55, 128 ), new DateTime( testDate.Year, testDate.Month, 5, 4, 23, 55, 128 ) );
} // DayTest
// ----------------------------------------------------------------------
[Trait("Category", "TimeTrim")]
[Fact]
public void HourTest()
{
Assert.Equal( TimeTrim.Hour( testDate ), new DateTime( testDate.Year, testDate.Month, testDate.Day ) );
Assert.Equal( TimeTrim.Hour( testDate, 4 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, 4, 0, 0 ) );
Assert.Equal( TimeTrim.Hour( testDate, 4, 23 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, 4, 23, 0 ) );
Assert.Equal( TimeTrim.Hour( testDate, 4, 23, 55 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, 4, 23, 55 ) );
Assert.Equal( TimeTrim.Hour( testDate, 4, 23, 55, 128 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, 4, 23, 55, 128 ) );
} // HourTest
// ----------------------------------------------------------------------
[Trait("Category", "TimeTrim")]
[Fact]
public void MinuteTest()
{
Assert.Equal( TimeTrim.Minute( testDate ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 0, 0 ) );
Assert.Equal( TimeTrim.Minute( testDate, 23 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 23, 0 ) );
Assert.Equal( TimeTrim.Minute( testDate, 23, 55 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 23, 55 ) );
Assert.Equal( TimeTrim.Minute( testDate, 23, 55, 128 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 23, 55, 128 ) );
} // MinuteTest
// ----------------------------------------------------------------------
[Trait("Category", "TimeTrim")]
[Fact]
public void SecondTest()
{
Assert.Equal( TimeTrim.Second( testDate ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, 0 ) );
Assert.Equal( TimeTrim.Second( testDate, 55 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, 55 ) );
Assert.Equal( TimeTrim.Second( testDate, 55, 128 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, 55, 128 ) );
} // SecondTest
// ----------------------------------------------------------------------
[Trait("Category", "TimeTrim")]
[Fact]
public void MillisecondTest()
{
Assert.Equal( TimeTrim.Millisecond( testDate ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, testDate.Second ) );
Assert.Equal( TimeTrim.Millisecond( testDate, 128 ), new DateTime( testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, testDate.Second, 128 ) );
} // MillisecondTest
// ----------------------------------------------------------------------
// members
private DateTime testDate = new DateTime( 2000, 10, 2, 13, 45, 53, 673 );
} // class TimeTrimTest
} // namespace Itenso.TimePeriodTests
// -- EOF -------------------------------------------------------------------