Kaynağa Gözat

* MonthCalendar.cs: On 2.0, throw ArgumentOutOfRangeException instead
of ArgumentException in MaxSelectionCount, MaxDate and MinDate.
Provide useful exception messages.
* MonthCalendarTest.cs: Fixed exception tests for MaxSelectionCount,
MaxDate and MinDate on 2.0 profile. Removed extra tabs.

svn path=/trunk/mcs/; revision=70141

Gert Driesen 19 yıl önce
ebeveyn
işleme
7acef11d9b

+ 6 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,9 @@
+2006-12-27  Gert Driesen  <[email protected]>
+
+	* MonthCalendar.cs: On 2.0, throw ArgumentOutOfRangeException instead
+	of ArgumentException in MaxSelectionCount, MaxDate and MinDate.
+	Provide useful exception messages.
+
 2006-12-27  Rolf Bjarne Kvinge  <[email protected]>
 
 	* TrackBar.cs: Remove a warning.

+ 45 - 5
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs

@@ -30,6 +30,7 @@ using System.Collections;
 using System.ComponentModel;
 using System.ComponentModel.Design;
 using System.Drawing;
+using System.Globalization;
 using System.Windows.Forms;
 using System.Runtime.InteropServices;
 
@@ -364,7 +365,16 @@ namespace System.Windows.Forms {
 		public DateTime MaxDate {
 			set {
 				if (value < MinDate) {
-					throw new ArgumentException();
+					string msg = string.Format (CultureInfo.CurrentCulture,
+						"Value of '{0}' is not valid for 'MaxDate'. 'MaxDate' " +
+						"must be greater than or equal to MinDate.",
+						value.ToString ("d", CultureInfo.CurrentCulture));
+#if NET_2_0
+					throw new ArgumentOutOfRangeException ("MaxDate",
+						msg);
+#else
+					throw new ArgumentException (msg);
+#endif
 				}
 
 				if (max_date != value) {
@@ -381,7 +391,16 @@ namespace System.Windows.Forms {
 		public int MaxSelectionCount {
 			set {
 				if (value < 1) {
-					throw new ArgumentException();
+					string msg = string.Format (CultureInfo.CurrentCulture,
+						"Value of '{0}' is not valid for 'MaxSelectionCount'. " +
+						"'MaxSelectionCount' must be greater than or equal to {1}.",
+						value, 1);
+#if NET_2_0
+					throw new ArgumentOutOfRangeException ("MaxSelectionCount",
+						msg);
+#else
+					throw new ArgumentException (msg);
+#endif
 				}
 		
 				// can't set selectioncount less than already selected dates
@@ -401,12 +420,33 @@ namespace System.Windows.Forms {
 		// the minimum date allowed to be selected on this month calendar
 		public DateTime MinDate {
 			set {
-				if (value < new DateTime (1753, 1, 1)) {
-					throw new ArgumentException();
+				DateTime absoluteMinDate = new DateTime (1753, 1, 1);
+
+				if (value < absoluteMinDate) {
+					string msg = string.Format (CultureInfo.CurrentCulture,
+						"Value of '{0}' is not valid for 'MinDate'. 'MinDate' " +
+						"must be greater than or equal to {1}.",
+						value.ToString ("d", CultureInfo.CurrentCulture),
+						absoluteMinDate.ToString ("d", CultureInfo.CurrentCulture));
+#if NET_2_0
+					throw new ArgumentOutOfRangeException ("MinDate",
+						msg);
+#else
+					throw new ArgumentException (msg);
+#endif
 				}
 
 				if (value > MaxDate) {
-					throw new ArgumentException();
+					string msg = string.Format (CultureInfo.CurrentCulture,
+						"Value of '{0}' is not valid for 'MinDate'. 'MinDate' " +
+						"must be less than MaxDate.",
+						value.ToString ("d", CultureInfo.CurrentCulture));
+#if NET_2_0
+					throw new ArgumentOutOfRangeException ("MinDate",
+						msg);
+#else
+					throw new ArgumentException (msg);
+#endif
 				}
 
 				if (max_date != value) {

+ 5 - 0
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog

@@ -1,3 +1,8 @@
+2006-12-27  Gert Driesen  <[email protected]>
+
+	* MonthCalendarTest.cs: Fixed exception tests for MaxSelectionCount,
+	MaxDate and MinDate on 2.0 profile. Removed extra tabs.
+
 2006-12-27  Jonathan Pobst  <[email protected]>
 
 	* ToolStripButtonTest.cs, ToolStripComboBoxTest.cs, ToolStripControlHostTest.cs,

+ 95 - 18
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/MonthCalendarTest.cs

@@ -8,9 +8,10 @@
 //
 
 using System;
-using System.Windows.Forms;
 using System.Drawing;
 using System.Reflection;
+using System.Windows.Forms;
+
 using NUnit.Framework;
 
 namespace MonoTests.System.Windows.Forms
@@ -20,7 +21,14 @@ namespace MonoTests.System.Windows.Forms
 	{
 		private bool clickRaised;
 		private bool doubleClickRaised;
-		
+
+		[SetUp]
+		public void SetUp ()
+		{
+			clickRaised = false;
+			doubleClickRaised = false;
+		}
+
 		[Test]
 		public void ClickEventTest ()
 		{
@@ -55,7 +63,6 @@ namespace MonoTests.System.Windows.Forms
 	[TestFixture]
 	public class MonthCalendarTest
 	{
-
 		[Test]
 		public void MonthCalendarPropertyTest ()
 		{
@@ -119,32 +126,105 @@ namespace MonoTests.System.Windows.Forms
 			myfrm.Dispose ();
 		}
 	
-		[Test]		
-		[ExpectedException (typeof (ArgumentException))]
+		[Test]
 		public void MonthCalMaxSelectionCountException ()
 		{
 			MonthCalendar myMonthCal1 = new MonthCalendar ();
-			myMonthCal1.MaxSelectionCount = 0 ; // value is less than 1
+
+			try {
+				myMonthCal1.MaxSelectionCount = 0; // value is less than 1
+				Assert.Fail ("#A1");
+#if NET_2_0
+			} catch (ArgumentOutOfRangeException ex) {
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
+				Assert.IsNotNull (ex.Message, "#A3");
+				Assert.IsNotNull (ex.ParamName, "#A4");
+				Assert.AreEqual ("MaxSelectionCount", ex.ParamName, "#A5");
+				Assert.IsNull (ex.InnerException, "#A6");
+			}
+#else
+			} catch (ArgumentException ex) {
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+				Assert.IsNotNull (ex.Message, "#A3");
+				Assert.IsNull (ex.ParamName, "#A4");
+				Assert.IsNull (ex.InnerException, "#A5");
+			}
+#endif
 		}
 
-		[Test]		
-		[ExpectedException (typeof (ArgumentException))]
+		[Test]
 		public void MonthCalMaxDateException ()
 		{
 			MonthCalendar myMonthCal1 = new MonthCalendar ();
-			myMonthCal1.MaxDate = new DateTime (1752, 1, 1, 0, 0, 0, 0); // value is less than min date (01/01/1753)
+
+			try {
+				myMonthCal1.MaxDate = new DateTime (1752, 1, 1, 0, 0, 0, 0); // value is less than min date (01/01/1753)
+				Assert.Fail ("#A1");
+#if NET_2_0
+			} catch (ArgumentOutOfRangeException ex) {
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
+				Assert.IsNotNull (ex.Message, "#A3");
+				Assert.IsNotNull (ex.ParamName, "#A4");
+				Assert.AreEqual ("MaxDate", ex.ParamName, "#A5");
+				Assert.IsNull (ex.InnerException, "#A6");
+			}
+#else
+			} catch (ArgumentException ex) {
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+				Assert.IsNotNull (ex.Message, "#A3");
+				Assert.IsNull (ex.ParamName, "#A4");
+				Assert.IsNull (ex.InnerException, "#A5");
+			}
+#endif
 		}
 
-		[Test]		
-		[ExpectedException (typeof (ArgumentException))]
+		[Test]
 		public void MonthCalMinDateException ()
 		{
 			MonthCalendar myMonthCal1 = new MonthCalendar ();
-			myMonthCal1.MinDate = new DateTime(1752, 1, 1, 0, 0, 0, 0); // Date earlier than 01/01/1753
-			myMonthCal1.MinDate = new DateTime(9999, 12, 31, 0, 0, 0, 0); // Date greater than max date (01/01/1753)
+
+			try {
+				myMonthCal1.MinDate = new DateTime (1752, 1, 1, 0, 0, 0, 0); // Date earlier than 01/01/1753
+				Assert.Fail ("#A1");
+#if NET_2_0
+			} catch (ArgumentOutOfRangeException ex) {
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
+				Assert.IsNotNull (ex.Message, "#A3");
+				Assert.IsNotNull (ex.ParamName, "#A4");
+				Assert.AreEqual ("MinDate", ex.ParamName, "#A5");
+				Assert.IsNull (ex.InnerException, "#A6");
+			}
+#else
+			} catch (ArgumentException ex) {
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+				Assert.IsNotNull (ex.Message, "#A3");
+				Assert.IsNull (ex.ParamName, "#A4");
+				Assert.IsNull (ex.InnerException, "#A5");
+			}
+#endif
+
+			try {
+				myMonthCal1.MinDate = new DateTime (9999, 12, 31, 0, 0, 0, 0); // Date greater than max date
+				Assert.Fail ("#B1");
+#if NET_2_0
+			} catch (ArgumentOutOfRangeException ex) {
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
+				Assert.IsNotNull (ex.Message, "#B3");
+				Assert.IsNotNull (ex.ParamName, "#B4");
+				Assert.AreEqual ("MinDate", ex.ParamName, "#B5");
+				Assert.IsNull (ex.InnerException, "#B6");
+			}
+#else
+			} catch (ArgumentException ex) {
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+				Assert.IsNotNull (ex.Message, "#B3");
+				Assert.IsNull (ex.ParamName, "#B4");
+				Assert.IsNull (ex.InnerException, "#B5");
+			}
+#endif
 		}
 
-		[Test]		
+		[Test]
 		[ExpectedException (typeof (ArgumentException))]
 		public void MonthCalSelectRangeException ()
 		{
@@ -152,14 +232,13 @@ namespace MonoTests.System.Windows.Forms
 			myMonthCal1.SelectionRange = new SelectionRange (new DateTime (1752, 01, 01), new DateTime (1752, 01, 02));
 		}
 
-		[Test]		
+		[Test]
 		[ExpectedException (typeof (ArgumentException))]
 		public void MonthCalSelectRangeException2 ()
 		{
 			MonthCalendar myMonthCal1 = new MonthCalendar ();
 			myMonthCal1.SelectionRange = new SelectionRange (new DateTime (9999, 12, 30), new DateTime (9999, 12, 31));
 		}
-		
 
 		[Test]
 		public void AddAnnuallyBoldedDateTest ()
@@ -183,7 +262,6 @@ namespace MonoTests.System.Windows.Forms
 
 			myForm.Dispose ();
 		}
-
 	
 		[Test]
 		public void RemoveAnnuallyBoldedDateTest ()
@@ -360,7 +438,6 @@ namespace MonoTests.System.Windows.Forms
 			myCalendar.DateChanged += new DateRangeEventHandler (DateChangedEventHandler);
 			myCalendar.SetDate (DateTime.Today.AddDays (72));
 			Assert.AreEqual (true, (bool) myCalendar.Tag, "#01");
-
 		}
 
 		void DateChangedEventHandler (object sender, DateRangeEventArgs e)