forked from VahidN/DNTPersianUtils.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersianCultureTests.cs
150 lines (126 loc) · 5.82 KB
/
PersianCultureTests.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DNTPersianUtils.Core.Tests
{
[TestClass]
public class PersianCultureTests
{
[TestMethod]
public void Test_GetPersianWeekDayName_Works()
{
var dt = new DateTime(2017, 1, 10, 10, 20, 2);
var actual = dt.GetPersianWeekDayName();
Assert.AreEqual(expected: "سه شنبه", actual: actual);
}
[TestMethod]
public void Test_GetPersianMonthName_Works()
{
var actual = 10.GetPersianMonthName();
Assert.AreEqual(expected: "دی", actual: actual);
}
[TestMethod]
public void Test_PersianCulture_Works()
{
Assert.IsTrue(PersianCulture.Instance.Calendar is PersianCalendar);
Assert.IsTrue(PersianCulture.Instance.DateTimeFormat.Calendar is PersianCalendar);
}
[TestMethod]
public void Test_GetPersianYear_Works()
{
var date = new DateTime(2014, 4, 20);
var year = date.GetPersianYear();
Assert.AreEqual(year, 1393);
}
[TestMethod]
public void Test_GetPersianMonth_Works()
{
var date = new DateTime(2014, 4, 20);
var month = date.GetPersianMonth();
Assert.AreEqual(month, 1);
}
[TestMethod]
public void Test_GetPersianDayOfMonth_Works()
{
var date = new DateTime(2014, 4, 20);
var dayOfMonth = date.GetPersianDayOfMonth();
Assert.AreEqual(dayOfMonth, 31);
}
[TestMethod]
public void Test_PersianStopwords_Works()
{
Assert.IsTrue(PersianStopwords.List.Contains("احتراما"));
}
[TestMethod]
public void Test_ApplyRle_Works()
{
Assert.IsTrue("سلام".ApplyRle().StartsWith(UnicodeConstants.RleChar));
}
[TestMethod]
public void Test_WrapInDirectionalDiv_Works()
{
Assert.IsTrue("تست".WrapInDirectionalDiv().Equals("<div style='text-align: right; font-family:tahoma; font-size:9pt;' dir='rtl'>تست</div>"));
}
[TestMethod]
public void Test_GetPersianYearStartAndEndDates_Works()
{
var persianCalendar = new PersianCalendar();
var persianYear = 1397.GetPersianYearStartAndEndDates();
Assert.AreEqual(expected: new DateTime(1397, 1, 1, persianCalendar), actual: persianYear.StartDate);
Assert.AreEqual(expected: new DateTime(1397, 12, 29, 23, 59, 59, persianCalendar), actual: persianYear.EndDate);
}
[TestMethod]
public void Test_GetPersianMonthStartAndEndDates_Works()
{
var persianCalendar = new PersianCalendar();
var persianMonth = 1397.GetPersianMonthStartAndEndDates(5);
Assert.AreEqual(expected: new DateTime(1397, 5, 1, persianCalendar), actual: persianMonth.StartDate);
Assert.AreEqual(expected: new DateTime(1397, 5, 31, 23, 59, 59, persianCalendar), actual: persianMonth.EndDate);
}
[TestMethod]
public void Test_GetPersianMonthStartAndEndDates_For_Dates_Works()
{
var persianCalendar = new PersianCalendar();
var date = new DateTime(1398, 5, 13, persianCalendar);
var persianMonth = date.GetPersianMonthStartAndEndDates();
Assert.AreEqual(expected: new DateTime(1398, 5, 1, persianCalendar), actual: persianMonth.StartDate);
Assert.AreEqual(expected: new DateTime(1398, 5, 31, 23, 59, 59, persianCalendar), actual: persianMonth.EndDate);
}
[TestMethod]
public void Test_GetPersianWeekStartAndEndDates_For_Dates_Works_1()
{
var persianCalendar = new PersianCalendar();
var date = new DateTime(1398, 5, 13, persianCalendar);
var persianWeek = date.GetPersianWeekStartAndEndDates();
Assert.AreEqual(expected: new DateTime(1398, 5, 12, persianCalendar), actual: persianWeek.StartDate);
Assert.AreEqual(expected: new DateTime(1398, 5, 18, 23, 59, 59, persianCalendar), actual: persianWeek.EndDate);
}
[TestMethod]
public void Test_GetPersianWeekStartAndEndDates_For_Dates_Works_Saturday()
{
var persianCalendar = new PersianCalendar();
var date = new DateTime(1398, 5, 12, persianCalendar);
var persianWeek = date.GetPersianWeekStartAndEndDates();
Assert.AreEqual(expected: new DateTime(1398, 5, 12, persianCalendar), actual: persianWeek.StartDate);
Assert.AreEqual(expected: new DateTime(1398, 5, 18, 23, 59, 59, persianCalendar), actual: persianWeek.EndDate);
}
[TestMethod]
public void Test_GetPersianWeekStartAndEndDates_For_Dates_Works_2()
{
var persianCalendar = new PersianCalendar();
var date = new DateTime(1398, 5, 21, persianCalendar);
var persianWeek = date.GetPersianWeekStartAndEndDates();
Assert.AreEqual(expected: new DateTime(1398, 5, 19, persianCalendar), actual: persianWeek.StartDate);
Assert.AreEqual(expected: new DateTime(1398, 5, 25, 23, 59, 59, persianCalendar), actual: persianWeek.EndDate);
}
[TestMethod]
public void Test_GetPersianWeekStartAndEndDates_For_Dates_Works_3()
{
var persianCalendar = new PersianCalendar();
var date = new DateTime(1398, 5, 30, persianCalendar);
var persianWeek = date.GetPersianWeekStartAndEndDates();
Assert.AreEqual(expected: new DateTime(1398, 5, 26, persianCalendar), actual: persianWeek.StartDate);
Assert.AreEqual(expected: new DateTime(1398, 6, 1, 23, 59, 59, persianCalendar), actual: persianWeek.EndDate);
}
}
}