1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Tests
.Helpers
19 using Castle
.MonoRail
.Framework
.Helpers
;
21 using NUnit
.Framework
;
25 public class DateFormatHelperTestCase
27 private DateFormatHelper helper
= new DateFormatHelper();
30 public void FriendlyFormatWithDiffOfOneSecond()
32 Assert
.AreEqual("1 second ago",
33 helper
.FriendlyFormatFromNow( DateTime
.Now
.AddSeconds(-1) ));
37 public void FriendlyFormatWithDiffOfTenSeconds()
39 Assert
.AreEqual("10 seconds ago",
40 helper
.FriendlyFormatFromNow( DateTime
.Now
.AddSeconds(-10) ));
44 public void FriendlyFormatWithDiffOfTenMinutes()
46 Assert
.AreEqual("10 minutes ago",
47 helper
.FriendlyFormatFromNow( DateTime
.Now
.AddMinutes(-10) ));
51 public void FriendlyFormatWithDiffOf120Minutes()
53 Assert
.AreEqual("2 hours ago",
54 helper
.FriendlyFormatFromNow( DateTime
.Now
.AddMinutes(-120) ));
58 public void FriendlyFormatWithDiffOf17Hours()
60 Assert
.AreEqual("17 hours ago",
61 helper
.FriendlyFormatFromNow( DateTime
.Now
.AddMinutes(- (17 * 60 + 30) ) ));
65 public void FriendlyFormatWithDiffOf2Days()
67 Assert
.AreEqual("2 days ago",
68 helper
.FriendlyFormatFromNow( DateTime
.Now
.AddDays(-2) ));
72 public void AlternativeFriendlyFormatFromNow()
74 Assert
.AreEqual("Today", helper
.AlternativeFriendlyFormatFromNow( DateTime
.Now
));
78 public void AlternativeFriendlyFormatFromNowWith4Hours()
80 Assert
.AreEqual("Today", helper
.AlternativeFriendlyFormatFromNow( DateTime
.Now
.AddHours(-4) ));
84 public void AlternativeFriendlyFormatFromNowWith44Hours()
86 Assert
.AreEqual("Yesterday", helper
.AlternativeFriendlyFormatFromNow( DateTime
.Now
.AddHours(-44) ));
90 public void AlternativeFriendlyFormatFromNowWith3Days()
92 Assert
.AreEqual("3 days ago", helper
.AlternativeFriendlyFormatFromNow( DateTime
.Now
.AddDays(-3) ));
96 public void AlternativeFriendlyFormatFromNowWith120Days()
98 Assert
.AreEqual("4 months ago", helper
.AlternativeFriendlyFormatFromNow( DateTime
.Now
.AddDays(-120) ));
102 public void ToShortDate()
104 DateTime now
= DateTime
.Now
;
106 string expected
= now
.ToShortDateString();
107 Assert
.AreEqual(expected
, helper
.ToShortDate(now
));
108 Assert
.AreEqual(String
.Empty
, helper
.ToShortDate(null));
112 public void ToShortDateTime()
114 DateTime now
= DateTime
.Now
;
116 string expected
= now
.ToShortDateString() + " " + now
.ToShortTimeString();
117 Assert
.AreEqual(expected
, helper
.ToShortDateTime(now
));
118 Assert
.AreEqual(String
.Empty
, helper
.ToShortDateTime(null));