MonthCalendarTest.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // MonthCalendarTest.cs: Test case for MonthCalendar
  3. //
  4. // Authors:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Windows.Forms;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Windows.Forms
  15. {
  16. [TestFixture]
  17. [Ignore ("This test has to be completly reviewed")]
  18. public class MonthCalendarTest
  19. {
  20. [Test]
  21. public void MonthCalendarPropertyTest ()
  22. {
  23. Form myfrm = new Form ();
  24. myfrm.ShowInTaskbar = false;
  25. MonthCalendar myMonthCal1 = new MonthCalendar ();
  26. MonthCalendar myMonthCal2 = new MonthCalendar ();
  27. myMonthCal1.Name = "MonthCendar";
  28. myMonthCal1.TabIndex = 1;
  29. DateTime myDateTime = new DateTime ();
  30. // A
  31. myMonthCal1.AddAnnuallyBoldedDate (new DateTime (2005, 09, 01));
  32. Assert.AreEqual (new DateTime (2005, 09, 01), myMonthCal1.AnnuallyBoldedDates.GetValue (0), "#A1");
  33. // B
  34. Assert.AreEqual ("Window", myMonthCal1.BackColor.Name, "#B1");
  35. myMonthCal1.AddBoldedDate (new DateTime (2005, 09, 01));
  36. Assert.AreEqual (new DateTime (2005, 09, 01), myMonthCal1.BoldedDates.GetValue (0), "#B2");
  37. // C
  38. Assert.AreEqual (1, myMonthCal1.CalendarDimensions.Height, "#C1");
  39. Assert.AreEqual (1, myMonthCal1.CalendarDimensions.Width, "#C2");
  40. Assert.AreEqual (false, myMonthCal1.CalendarDimensions.IsEmpty, "#C3");
  41. // F
  42. Assert.AreEqual (Day.Default, myMonthCal1.FirstDayOfWeek, "#F1");
  43. myMonthCal1.FirstDayOfWeek = Day.Sunday;
  44. Assert.AreEqual (Day.Sunday, myMonthCal1.FirstDayOfWeek, "#F2");
  45. Assert.AreEqual ("WindowText", myMonthCal1.ForeColor.Name, "#F3");
  46. // M
  47. Assert.AreEqual (new DateTime (9998,12,31), myMonthCal1.MaxDate, "#M1");
  48. Assert.AreEqual (7, myMonthCal1.MaxSelectionCount, "#M2");
  49. Assert.AreEqual (new DateTime (1753,1,1), myMonthCal1.MinDate, "#M3");
  50. myMonthCal1.AddMonthlyBoldedDate (new DateTime (2005, 09, 01));
  51. Assert.AreEqual (new DateTime(2005, 09, 01), myMonthCal1.MonthlyBoldedDates.GetValue (0), "#M4");
  52. // S
  53. Assert.AreEqual (0, myMonthCal1.ScrollChange, "#S1");
  54. myMonthCal1.SelectionStart = new DateTime (2005,09,02);
  55. myMonthCal1.SelectionEnd = new DateTime (2005,09,03);
  56. Assert.AreEqual (new DateTime (2005,09,03), myMonthCal1.SelectionEnd, "#S2");
  57. //Assert.AreEqual (new SelectionRange (new DateTime(2005,09,02), new DateTime(2005,09,03)), myMonthCal1.SelectionRange, "#S3");
  58. Assert.AreEqual (new DateTime (2005,09,02), myMonthCal1.SelectionStart, "#S4");
  59. Assert.AreEqual (true, myMonthCal1.ShowToday, "#S5");
  60. Assert.AreEqual (true, myMonthCal1.ShowTodayCircle, "#S6");
  61. Assert.AreEqual (false, myMonthCal1.ShowWeekNumbers, "#S7");
  62. Assert.AreEqual (153, myMonthCal1.SingleMonthSize.Height, "#S8a");
  63. Assert.AreEqual (176, myMonthCal1.SingleMonthSize.Width, "#S8b");
  64. Assert.AreEqual (null, myMonthCal1.Site, "#S9");
  65. // T
  66. Assert.AreEqual ("ActiveCaption", myMonthCal1.TitleBackColor.Name, "#T1");
  67. Assert.AreEqual ("ActiveCaptionText", myMonthCal1.TitleForeColor.Name, "#T2");
  68. Assert.AreEqual (DateTime.Today, myMonthCal1.TodayDate, "#T3");
  69. Assert.AreEqual (false, myMonthCal1.TodayDateSet, "#T4");
  70. Assert.AreEqual ("GrayText", myMonthCal1.TrailingForeColor.Name, "#T5");
  71. myfrm.Dispose ();
  72. }
  73. [Test]
  74. [ExpectedException (typeof (ArgumentException))]
  75. public void MonthCalMaxSelectionCountException ()
  76. {
  77. MonthCalendar myMonthCal1 = new MonthCalendar ();
  78. myMonthCal1.MaxSelectionCount = 0 ; // value is less than 1
  79. }
  80. [Test]
  81. [ExpectedException (typeof (ArgumentException))]
  82. public void MonthCalMaxDateException ()
  83. {
  84. MonthCalendar myMonthCal1 = new MonthCalendar ();
  85. myMonthCal1.MaxDate = new DateTime (1752, 1, 1, 0, 0, 0, 0); // value is less than min date (01/01/1753)
  86. }
  87. [Test]
  88. [ExpectedException (typeof (ArgumentException))]
  89. public void MonthCalMinDateException ()
  90. {
  91. MonthCalendar myMonthCal1 = new MonthCalendar ();
  92. myMonthCal1.MinDate = new DateTime(1752, 1, 1, 0, 0, 0, 0); // Date earlier than 01/01/1753
  93. myMonthCal1.MinDate = new DateTime(9999, 12, 31, 0, 0, 0, 0); // Date greater than max date (01/01/1753)
  94. }
  95. [Test]
  96. [ExpectedException (typeof (ArgumentException))]
  97. public void MonthCalSelectRangeException ()
  98. {
  99. MonthCalendar myMonthCal1 = new MonthCalendar ();
  100. myMonthCal1.SelectionRange = new SelectionRange (new DateTime (1752, 01, 01), new DateTime (1752, 01, 02));
  101. myMonthCal1.SelectionRange = new SelectionRange (new DateTime (9999, 12, 30), new DateTime (9999, 12, 31));
  102. }
  103. [Test]
  104. public void AddAnnuallyBoldedDateTest ()
  105. {
  106. Form myForm = new Form ();
  107. myForm.ShowInTaskbar = false;
  108. MonthCalendar myMonthCal = new MonthCalendar ();
  109. myMonthCal.AddAnnuallyBoldedDate (new DateTime (2005, 09, 01));
  110. myForm.Controls.Add (myMonthCal);
  111. Assert.AreEqual (new DateTime (2005, 09, 01), myMonthCal.AnnuallyBoldedDates.GetValue (0), "#add1");
  112. myForm.Dispose ();
  113. }
  114. [Test]
  115. public void AddBoldedDateTest ()
  116. {
  117. Form myForm = new Form ();
  118. myForm.ShowInTaskbar = false;
  119. MonthCalendar myMonthCal = new MonthCalendar ();
  120. myMonthCal.AddBoldedDate (new DateTime (2005, 09, 02));
  121. myForm.Controls.Add (myMonthCal);
  122. Assert.AreEqual (new DateTime (2005, 09, 02), myMonthCal.BoldedDates.GetValue (0), "#add2");
  123. myForm.Dispose ();
  124. }
  125. [Test]
  126. public void AddMonthlyBoldedDateTest ()
  127. {
  128. Form myForm = new Form ();
  129. myForm.ShowInTaskbar = false;
  130. MonthCalendar myMonthCal = new MonthCalendar ();
  131. myMonthCal.AddMonthlyBoldedDate (new DateTime (2005, 09, 03));
  132. myForm.Controls.Add (myMonthCal);
  133. Assert.AreEqual (new DateTime (2005, 09, 03), myMonthCal.MonthlyBoldedDates.GetValue (0), "#add2");
  134. myForm.Dispose ();
  135. }
  136. [Test]
  137. public void GetDispalyRangeTest ()
  138. {
  139. Form myForm = new Form ();
  140. myForm.ShowInTaskbar = false;
  141. MonthCalendar myMonthCal = new MonthCalendar ();
  142. myForm.Controls.Add (myMonthCal);
  143. SelectionRange mySelRange = new SelectionRange ();
  144. mySelRange.Start = new DateTime (2005, 09, 01);
  145. mySelRange.End = new DateTime (2005, 09, 30);
  146. Assert.AreEqual (mySelRange.Start, myMonthCal.GetDisplayRange (true).Start, "#Get1");
  147. Assert.AreEqual (mySelRange.End, myMonthCal.GetDisplayRange (true).End, "#Get22");
  148. myForm.Dispose ();
  149. }
  150. [Test]
  151. public void HitTest ()
  152. {
  153. Form myForm = new Form ();
  154. myForm.ShowInTaskbar = false;
  155. MonthCalendar myMonthCal = new MonthCalendar ();
  156. myForm.Controls.Add (myMonthCal);
  157. Assert.AreEqual (new DateTime (01, 01, 01), myMonthCal.HitTest(10, 10).Time, "#Hit1");
  158. }
  159. }
  160. }