Author: jordi Date: 2005-08-26 18:54:16 -0400 (Fri, 26 Aug 2005) New Revision: 48938
Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarDayTest.cs trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarTest.cs trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ImageButtonTest.cs trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/RadioButtonListTest.cs trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SelectedDatesCollectionTest.cs Log: Tests Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs =================================================================== --- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs 2005-08-26 22:53:47 UTC (rev 48937) +++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs 2005-08-26 22:54:16 UTC (rev 48938) @@ -0,0 +1,116 @@ +// +// Tests for System.Web.UI.WebControls.Button.cs +// +// Author: +// Jordi Mas i Hernandez ([EMAIL PROTECTED]) +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using NUnit.Framework; +using System; +using System.IO; +using System.Globalization; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace MonoTests.System.Web.UI.WebControls +{ + class PokerButton : Button { + public PokerButton () + { + TrackViewState (); + } + + public object SaveState () + { + return SaveViewState (); + } + + public void LoadState (object o) + { + LoadViewState (o); + } + } + + + [TestFixture] + public class ButtonTest { + + [Test] + public void Button_DefaultValues () + { + Button b = new Button (); + Assert.AreEqual (true, b.CausesValidation, "CausesValidation"); + Assert.AreEqual (string.Empty, b.CommandArgument, "CommandArgument"); + Assert.AreEqual (string.Empty, b.CommandName, "CommandName"); +#if NET_2_0 + Assert.AreEqual (string.Empty, b.ValidationGroup, "ValidationGroup"); +#endif + } + + [Test] + public void Button_ViewState () + { + PokerButton p = new PokerButton (); + + Assert.AreEqual (p.Text, "", "A1"); + p.Text = "Hello"; + Assert.AreEqual (p.Text, "Hello", "A2"); + +#if NET_2_0 + p.ValidationGroup = "VG1"; + Assert.AreEqual (p.ValidationGroup, "VG1", "A3"); +#endif + + object state = p.SaveState (); + + PokerButton copy = new PokerButton (); + copy.LoadState (state); + Assert.AreEqual (copy.Text, "Hello", "A4"); + +#if NET_2_0 + Assert.AreEqual (copy.ValidationGroup, "VG1", "A5"); +#endif + } + + [Test] + public void Button_Render () + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + + Button b = new Button (); + b.Text = "Hello"; + b.RenderControl (tw); + + Assert.AreEqual (true, sw.ToString().IndexOf ("value=\"Hello\"") != -1, "A4"); + Assert.AreEqual (true, sw.ToString().IndexOf ("<input") != -1, "A5"); + Assert.AreEqual (true, sw.ToString().IndexOf ("type=\"submit\"") != -1, "A6"); + } + } +} + + Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarDayTest.cs =================================================================== --- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarDayTest.cs 2005-08-26 22:53:47 UTC (rev 48937) +++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarDayTest.cs 2005-08-26 22:54:16 UTC (rev 48938) @@ -0,0 +1,72 @@ +// +// Tests for System.Web.UI.WebControls.CalendarDay.cs +// +// Author: +// Jordi Mas i Hernandez ([EMAIL PROTECTED]) +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Web.UI.WebControls; +using NUnit.Framework; +using System; +using System.Drawing; +using System.IO; +using System.Web; +using System.Web.UI; +using System.Globalization; + + +namespace MonoTests.System.Web.UI.WebControls +{ + + [TestFixture] + public class CalendarDayTest { + + CalendarDay calDay = new CalendarDay (DateTime.Today, true, false, true, false, "10"); + + [Test] + public void CalendarDay_Constructor () + { + Assert.AreEqual (DateTime.Today, calDay.Date, "A1"); + Assert.AreEqual ("10", calDay.DayNumberText, "A2"); + Assert.AreEqual (false, calDay.IsOtherMonth, "A3"); + Assert.AreEqual (false, calDay.IsSelectable, "A4"); // Default value + Assert.AreEqual (true, calDay.IsSelected, "A5"); + Assert.AreEqual (false, calDay.IsToday, "A6"); + Assert.AreEqual (true, calDay.IsWeekend, "A7"); + } + + [Test] + public void IsSelectableProperty () + { + calDay.IsSelectable = true; + Assert.AreEqual (true, calDay.IsSelectable, "A1"); + } + + + } +} + + Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarTest.cs =================================================================== --- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarTest.cs 2005-08-26 22:53:47 UTC (rev 48937) +++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/CalendarTest.cs 2005-08-26 22:54:16 UTC (rev 48938) @@ -0,0 +1,607 @@ +// +// Tests for System.Web.UI.WebControls.Calendar.cs +// +// Author: +// Jordi Mas i Hernandez ([EMAIL PROTECTED]) +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Web.UI.WebControls; +using NUnit.Framework; +using System; +using System.Drawing; +using System.IO; +using System.Web; +using System.Web.UI; +using System.Globalization; +using System.Drawing; + +class PokerCalendar : System.Web.UI.WebControls.Calendar { + public PokerCalendar () + { + TrackViewState (); + } + + public object SaveState () + { + return SaveViewState (); + } + + public void LoadState (object o) + { + LoadViewState (o); + } + + public string Render () + { + StringWriter sw = new StringWriter (); + sw.NewLine = "\n"; + HtmlTextWriter writer = new HtmlTextWriter (sw); + base.Render (writer); + return writer.InnerWriter.ToString (); + } +} + + +namespace MonoTests.System.Web.UI.WebControls +{ + + [TestFixture] + public class CalendarTest { + + [Test] + public void Calendar_DefaultValues () + { + PokerCalendar c = new PokerCalendar (); + + Assert.AreEqual (2, c.CellPadding, "CellPadding"); + Assert.AreEqual (0, c.CellSpacing, "CellSpacing"); + Assert.AreEqual (DayNameFormat.Short, c.DayNameFormat, "DayNameFormat"); + Assert.AreEqual (FirstDayOfWeek.Default, c.FirstDayOfWeek, "FirstDayOfWeek"); + Assert.AreEqual (">",c.NextMonthText, "NextMonthText"); + Assert.AreEqual (NextPrevFormat.CustomText, c.NextPrevFormat, "NextPrevFormat"); + Assert.AreEqual ("<", c.PrevMonthText, "PrevMonthText"); + Assert.AreEqual (CalendarSelectionMode.Day, c.SelectionMode, "SelectionMode"); + Assert.AreEqual (">>", c.SelectMonthText, "SelectMonthText"); + Assert.AreEqual (">", c.SelectWeekText, "SelectWeekText"); + Assert.AreEqual (true, c.ShowDayHeader, "ShowDayHeader"); + Assert.AreEqual (false, c.ShowGridLines, "ShowGridLines"); + Assert.AreEqual (true, c.ShowNextPrevMonth , "ShowNextPrevMonth"); + Assert.AreEqual (true, c.ShowTitle, "ShowTitle"); + Assert.AreEqual (TitleFormat.MonthYear, c.TitleFormat, "TitleFormat"); + Assert.AreEqual (DateTime.Today, c.TodaysDate , "TodaysDate"); + Assert.AreEqual (DateTime.MinValue, c.VisibleDate, "VisibleDate"); + } + + // + // Properties + // + [Test] + public void NextMonthTextProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.NextMonthText = "NextMonthText"; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "NextMonthText"); + } + + [Test] + public void NextPrevFormatProperty () + { + DateTimeFormatInfo dateInfo = new DateTimeFormatInfo (); + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + DateTime prevMonth = DateTimeFormatInfo.CurrentInfo.Calendar.AddMonths (DateTime.Today, - 1); + DateTime nextMonth = DateTimeFormatInfo.CurrentInfo.Calendar.AddMonths (DateTime.Today, 1); + + c.NextMonthText = "NextMonthText"; // CustomText + c.PrevMonthText = "PrevMonthText"; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "NextPrevFormat1"); + Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "NextPrevFormat2"); + + sw = new StringWriter (); + tw = new HtmlTextWriter (sw); + c.NextPrevFormat = NextPrevFormat.FullMonth; // FullMonth + c.RenderControl (tw); + + //Assert.AreEqual (true, sw.ToString().IndexOf (dateInfo.GetMonthName (DateTimeFormatInfo.CurrentInfo.Calendar.GetMonth (prevMonth))) != -1, "NextPrevFormat3"); + //Assert.AreEqual (true, sw.ToString().IndexOf (dateInfo.GetMonthName (DateTimeFormatInfo.CurrentInfo.Calendar.GetMonth (nextMonth))) != -1, "NextPrevFormat4"); + + sw = new StringWriter (); + tw = new HtmlTextWriter (sw); + c.NextPrevFormat = NextPrevFormat.ShortMonth; // ShortMonth + c.RenderControl (tw); + + //Assert.AreEqual (true, sw.ToString().IndexOf (dateInfo.GetAbbreviatedMonthName (DateTimeFormatInfo.CurrentInfo.Calendar.GetMonth (prevMonth))) != -1, "NextPrevFormat5"); + //Assert.AreEqual (true, sw.ToString().IndexOf (dateInfo.GetAbbreviatedMonthName (DateTimeFormatInfo.CurrentInfo.Calendar.GetMonth (nextMonth))) != -1, "NextPrevFormat6"); + } + + [Test] + public void DayHeaderStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.DayHeaderStyle.BackColor = Color.Green; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "DayHeaderStyleProperty"); + } + + [Test] + public void NextPrevStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.NextPrevStyle.BackColor = Color.Green; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "NextPrevStyleProperty"); + } + + [Test] + public void SelectorStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.SelectorStyle.BackColor = Color.Green; + c.SelectionMode = CalendarSelectionMode.DayWeek; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "SelectorStyleProperty"); + } + + //[Test] + public void TitleStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.SelectorStyle.BackColor = Color.Green; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "TitleStyleProperty"); + } + + [Test] + public void OtherMonthDayStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.OtherMonthDayStyle.BackColor = Color.Green; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "OtherMonthDayStyle"); + } + + [Test] + public void SelectedDayStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.SelectedDayStyle.BackColor = Color.Green; + c.TodaysDate = new DateTime (2000, 1,1); + ((IPostBackEventHandler)c).RaisePostBackEvent ("0001"); + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "SelectedDayStyle"); + } + + [Test] + public void TodayDayStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.TodayDayStyle.BackColor = Color.Green; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "TodayDayStyle"); + } + + [Test] + public void WeekendDayStyleProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.WeekendDayStyle.BackColor = Color.Green; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "WeekendDayStyle"); + } + + [Test] + public void SelectDateProperty () + { + PokerCalendar c = new PokerCalendar (); + c.SelectedDate = DateTime.Today; + Assert.AreEqual (DateTime.Today, c.SelectedDate, "SelectDateProperty"); + } + + [Test] + public void PrevMonthTextProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.PrevMonthText = "PrevMonthText"; + c.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "PrevMonthText"); + } + + [Test] + public void ShowNextPrevMonthProperty () + { + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.NextMonthText = "NextMonthText"; + c.PrevMonthText = "PrevMonthText"; + c.RenderControl (tw); + + Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "ShowNextPrevMonth1"); + Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "ShowNextPrevMonth2"); + + c.ShowNextPrevMonth = false; + sw = new StringWriter (); + tw = new HtmlTextWriter (sw); + c.RenderControl (tw); + + Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) == -1, "ShowNextPrevMonth3"); + Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) == -1, "ShowNextPrevMonth4"); + } + + [Test] + public void ShowTitleProperty () + { + String monthName; + DateTimeFormatInfo dateInfo = new DateTimeFormatInfo (); + PokerCalendar c = new PokerCalendar (); + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.NextMonthText = "NextMonthText"; + c.PrevMonthText = "PrevMonthText"; + c.RenderControl (tw); + monthName = dateInfo.GetMonthName (DateTimeFormatInfo.CurrentInfo.Calendar.GetMonth (DateTime.Today)); + + Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "ShowTitle1"); + Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "ShowTitle2"); + //Assert.AreEqual (true, sw.ToString().IndexOf (monthName) != -1, "ShowTitle3"); + + c.ShowTitle = false; + sw = new StringWriter (); + tw = new HtmlTextWriter (sw); + c.RenderControl (tw); + + Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) == -1, "ShowTitle4"); + Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) == -1, "ShowTitle5"); + //Assert.AreEqual (true, sw.ToString().IndexOf (monthName) == -1, "ShowTitle6"); + } + + // + // Properties exceptions + // + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void CellPaddingException () + { + PokerCalendar p = new PokerCalendar (); + p.CellPadding = -2; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void CellSpacingException () + { + PokerCalendar c = new PokerCalendar (); + c.CellSpacing = -2; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void DayNameFormatException () + { + PokerCalendar c = new PokerCalendar (); + c.DayNameFormat = (DayNameFormat) 10; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void FirstDayOfWeekException () + { + PokerCalendar c = new PokerCalendar (); + c.FirstDayOfWeek = (FirstDayOfWeek) 15; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void NextPrevFormatException () + { + PokerCalendar c = new PokerCalendar (); + c.NextPrevFormat = (NextPrevFormat) 15; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void SelectionModeException () + { + PokerCalendar c = new PokerCalendar (); + c.SelectionMode = (CalendarSelectionMode) 15; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void TitleFormatException () + { + PokerCalendar c = new PokerCalendar (); + c.TitleFormat = (TitleFormat) 15; + } + + // + // Events + // + private bool eventFired; + private void SelectionChangedHandler (object sender, EventArgs e) + { + eventFired = true; + } + + private void VisibleMonthChangedHandler (object sender, MonthChangedEventArgs e) + { + eventFired = true; + } + + int days; + private void DayRenderEventHandler (object sender, DayRenderEventArgs e) + { + days++; + e.Cell.BackColor = Color.Yellow; + } + + [Test] + public void SelectionChanged () + { + PokerCalendar c = new PokerCalendar (); + c.SelectionChanged += new EventHandler (SelectionChangedHandler); + eventFired = false; + ((IPostBackEventHandler)c).RaisePostBackEvent ("0001"); + Assert.AreEqual (true, eventFired, "SelectionChanged event"); + } + + [Test] + public void VisibleMonthChanged () + { + PokerCalendar c = new PokerCalendar (); + c.VisibleMonthChanged += new MonthChangedEventHandler (VisibleMonthChangedHandler); + eventFired = false; + ((IPostBackEventHandler)c).RaisePostBackEvent ("V0001"); + Assert.AreEqual (true, eventFired, "VisibleMonthChanged event"); + } + + [Test] + public void DayRender () + { + PokerCalendar c = new PokerCalendar (); + c.DayRender += new DayRenderEventHandler (DayRenderEventHandler); + days = 0; + + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + c.RenderControl (tw); + Assert.AreEqual (6 * 7, days, "DayRender event"); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("yellow") != -1, "DayRender event change"); + } + + // ViewState + [Test] + public void Calendar_ViewState () + { + PokerCalendar p = new PokerCalendar (); + p.CellPadding = 10; + p.CellSpacing = 20; + p.DayNameFormat = DayNameFormat.Short; + p.FirstDayOfWeek = FirstDayOfWeek.Friday; + p.NextMonthText = "NextMonth"; + p.NextPrevFormat = NextPrevFormat.ShortMonth; + p.PrevMonthText = "PrevMonth"; + p.SelectionMode = CalendarSelectionMode.DayWeek; + p.SelectMonthText = "SelectMonth"; + p.SelectWeekText = "SelectWeek"; + p.ShowDayHeader = false; + p.ShowGridLines = true; + p.ShowNextPrevMonth = false; + p.ShowTitle = false; + p.TitleFormat = TitleFormat.Month; + p.TodaysDate = new DateTime (1999,1,1); + p.VisibleDate = new DateTime (1998,1,1); +#if NET_2_0 + p.Caption = "This is a Caption"; + p.CaptionAlign = TableCaptionAlign.Right; +#endif + + p.DayHeaderStyle.BackColor = Color.Blue; + p.DayStyle.BackColor = Color.Yellow; + p.NextPrevStyle.BackColor = Color.Red; + p.OtherMonthDayStyle.BackColor = Color.Green; + p.SelectedDayStyle.BackColor = Color.Silver; + p.SelectorStyle.BackColor = Color.Pink; + p.TodayDayStyle.BackColor = Color.White; + p.WeekendDayStyle.BackColor = Color.Brown; + + object state = p.SaveState (); + + PokerCalendar copy = new PokerCalendar (); + copy.LoadState (state); + + Assert.AreEqual (10, copy.CellPadding, "CellPadding"); + Assert.AreEqual (20, copy.CellSpacing, "CellSpacing"); + Assert.AreEqual (DayNameFormat.Short, copy.DayNameFormat, "DayNameFormat"); + Assert.AreEqual (FirstDayOfWeek.Friday, copy.FirstDayOfWeek, "FirstDayOfWeek"); + Assert.AreEqual ("NextMonth", copy.NextMonthText, "NextMonthText"); + Assert.AreEqual (NextPrevFormat.ShortMonth, copy.NextPrevFormat, "NextPrevFormat"); + Assert.AreEqual ("PrevMonth", copy.PrevMonthText, "PrevMonthText"); + Assert.AreEqual (CalendarSelectionMode.DayWeek, copy.SelectionMode, "SelectionMode"); + Assert.AreEqual ("SelectMonth", copy.SelectMonthText, "SelectMonthText"); + Assert.AreEqual ("SelectWeek", copy.SelectWeekText, "SelectWeekText"); + Assert.AreEqual (false, copy.ShowDayHeader, "ShowDayHeader"); + Assert.AreEqual (true, copy.ShowGridLines, "ShowGridLines"); + Assert.AreEqual (false, copy.ShowNextPrevMonth, "ShowNextPrevMonth"); + Assert.AreEqual (false, copy.ShowTitle, "ShowTitle"); + Assert.AreEqual (TitleFormat.Month, copy.TitleFormat, "TitleFormat"); + Assert.AreEqual (new DateTime (1999,1,1), copy.TodaysDate, "TodaysDate"); + Assert.AreEqual (new DateTime (1998,1,1), copy.VisibleDate, "VisibleDate"); + +#if NET_2_0 + Assert.AreEqual ("This is a Caption", copy.Caption, "Caption"); + Assert.AreEqual (TableCaptionAlign.Right, copy.CaptionAlign, "CaptionAlign"); +#endif + + copy.ShowDayHeader = true; + copy.ShowNextPrevMonth = true; + copy.ShowTitle = true; + copy.TodaysDate = copy.VisibleDate; + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("blue") != -1, "DayHeaderStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("yellow") != -1, "BackColor"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("red") != -1, "NextPrevStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "OtherMonthDayStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("silver") != -1, "SelectedDayStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "OtherMonthDayStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("pink") != -1, "SelectorStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("white") != -1, "TodayDayStyle"); + } + + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + copy.RenderControl (tw); + Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("brown") != -1, "WeekendDayStyle"); + } + + } + + [Test] + public void TestDayRenderCellAdd () + { + PokerCalendar p = new PokerCalendar (); + string tofind = Guid.NewGuid ().ToString (); + + p.DayRender += delegate (object soruce, DayRenderEventArgs e) { + if (e.Day.Date.Day == 1) + e.Cell.Controls.Add (new LiteralControl (tofind)); + }; + + Assert.IsTrue (p.Render ().IndexOf (tofind) != -1, "control added"); + } + + // + // Here we test rendering May 2005 + // April 2005 May 2005 June 2005 + // Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa + // 1 2 1 2 3 4 5 6 7 1 2 3 4 + // 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11 + // 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18 + // 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25 + // 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30 + // + // Microsoft renders months like this (where Blah 1st falls on Sunday) by rendering + // the last week of the other month. + // + [Test] + public void TestRenderMonthStartsOnSunday () + { + PokerCalendar p = new PokerCalendar (); + p.TodaysDate = new DateTime (2005, 5, 14); + + bool first = true; + p.DayRender += delegate (object soruce, DayRenderEventArgs e) { + if (first) { + Assert.IsTrue (e.Day.IsOtherMonth); + Assert.AreEqual (new DateTime (2005, 4, 24), e.Day.Date); + first = false; + } + }; + + p.Render (); + } + + [Test] + public void TestSelectedColorDefault () + { + PokerCalendar p = new PokerCalendar (); + p.TodaysDate = new DateTime (2005, 8, 4); + p.SelectedDate = p.TodaysDate; + Assert.IsTrue (p.Render ().IndexOf ("color:White;background-color:Silver;") != -1); + } + } +} Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ImageButtonTest.cs =================================================================== --- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ImageButtonTest.cs 2005-08-26 22:53:47 UTC (rev 48937) +++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ImageButtonTest.cs 2005-08-26 22:54:16 UTC (rev 48938) @@ -0,0 +1,116 @@ +// +// Tests for System.Web.UI.WebControls.ImageButton.cs +// +// Author: +// Jordi Mas i Hernandez ([EMAIL PROTECTED]) +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using NUnit.Framework; +using System; +using System.IO; +using System.Globalization; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace MonoTests.System.Web.UI.WebControls +{ + class PokerImageButton : ImageButton { + public PokerImageButton () + { + TrackViewState (); + } + + public object SaveState () + { + return SaveViewState (); + } + + public void LoadState (object o) + { + LoadViewState (o); + } + } + + [TestFixture] + public class ImageButtonTest { + + [Test] + public void ImageButton_DefaultValues () + { + ImageButton b = new ImageButton (); + Assert.AreEqual (true, b.CausesValidation, "CausesValidation"); + Assert.AreEqual (string.Empty, b.CommandArgument, "CommandArgument"); + Assert.AreEqual (string.Empty, b.CommandName, "CommandName"); +#if NET_2_0 + Assert.AreEqual (string.Empty, b.ValidationGroup, "ValidationGroup"); +#endif + } + + + [Test] + public void ImageButton_Render () + { + StringWriter sw = new StringWriter (); + HtmlTextWriter tw = new HtmlTextWriter (sw); + + ImageButton b = new ImageButton (); + b.RenderControl (tw); + + Assert.AreEqual (true, sw.ToString().IndexOf ("<input") != -1, "A1"); + Assert.AreEqual (true, sw.ToString().IndexOf ("type=\"image\"") != -1, "A2"); + } + + [Test] + public void ImageButton_ViewState () + { + PokerImageButton p = new PokerImageButton (); + + p.CommandArgument = "arg"; + Assert.AreEqual (p.CommandArgument, "arg", "A1"); + p.CommandName = "cmd"; + Assert.AreEqual (p.CommandName, "cmd", "A2"); +#if NET_2_0 + p.ValidationGroup = "VG1"; + Assert.AreEqual (p.ValidationGroup, "VG1", "A3"); +#endif + + object state = p.SaveState (); + + PokerImageButton copy = new PokerImageButton (); + copy.LoadState (state); + + Assert.AreEqual (copy.CommandArgument, "arg", "A4"); + Assert.AreEqual (copy.CommandName, "cmd", "A5"); +#if NET_2_0 + Assert.AreEqual (copy.ValidationGroup, "VG1", "A6"); +#endif + + } + } +} + + Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/RadioButtonListTest.cs =================================================================== --- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/RadioButtonListTest.cs 2005-08-26 22:53:47 UTC (rev 48937) +++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/RadioButtonListTest.cs 2005-08-26 22:54:16 UTC (rev 48938) @@ -0,0 +1,140 @@ +// +// Tests for System.Web.UI.WebControls.RadioButtonListTest.cs +// +// Author: +// Jordi Mas i Hernandez ([EMAIL PROTECTED]) +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Web.UI.WebControls; +using NUnit.Framework; +using System; +using System.Drawing; +using System.IO; +using System.Web; +using System.Web.UI; +using System.Globalization; + + +namespace MonoTests.System.Web.UI.WebControls { + + [TestFixture] + public class RadioButtonListTest { + + public class TestRadioButtonList : RadioButtonList { + public StateBag StateBag { + get { return base.ViewState; } + } + + public string Render () + { + HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ()); + base.Render (writer); + return writer.InnerWriter.ToString (); + } + } + + [Test] + public void RadioButtonList_Constructor () + { + TestRadioButtonList r = new TestRadioButtonList (); + Assert.AreEqual (-1, r.CellPadding, "A1"); + Assert.AreEqual (-1, r.CellSpacing, "A2"); + Assert.AreEqual (0, r.RepeatColumns, "A3"); + Assert.AreEqual (RepeatDirection.Vertical, r.RepeatDirection, "A4"); + Assert.AreEqual (RepeatLayout.Table, r.RepeatLayout, "A5"); + Assert.AreEqual (TextAlign.Right, r.TextAlign, "A6"); + Assert.AreEqual (false, ((IRepeatInfoUser)r).HasFooter, "A7"); + Assert.AreEqual (false, ((IRepeatInfoUser)r).HasHeader, "A8"); + Assert.AreEqual (false, ((IRepeatInfoUser)r).HasSeparators, "A9"); + Assert.AreEqual (0, ((IRepeatInfoUser)r).RepeatedItemCount, "A10"); + } + + [Test] + public void CellPaddingProperties () + { + TestRadioButtonList r = new TestRadioButtonList (); + r.CellPadding = 5; + Assert.AreEqual (5, r.CellPadding, "setting"); + + string s = r.Render (); + Assert.IsTrue (s.ToLower ().IndexOf ("cellpadding=\"5\"") != -1, "htmloutput"); + } + + [Test] + public void CellSpacingProperties () + { + TestRadioButtonList r = new TestRadioButtonList (); + r.CellSpacing = 5; + Assert.AreEqual (5, r.CellSpacing, "setting"); + + string s = r.Render (); + Assert.IsTrue (s.ToLower ().IndexOf ("cellspacing=\"5\"") != -1, "htmloutput"); + } + + [Test] + public void Render () + { + TestRadioButtonList c = new TestRadioButtonList (); + + c.Items.Add (new ListItem ("text2", "value1")); + + string s = c.Render (); + + Assert.IsTrue (s.ToLower ().IndexOf (" type=\"radio\"") != -1, "type"); + Assert.IsTrue (s.ToLower ().IndexOf ("value1") != -1, "value"); + Assert.IsTrue (s.ToLower ().IndexOf ("text2") != -1, "text"); + } + + // Exceptions + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void RepeatColumnsException () + { + TestRadioButtonList r = new TestRadioButtonList (); + r.RepeatColumns = -1; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void RepeatDirectionException () + { + TestRadioButtonList r = new TestRadioButtonList (); + r.RepeatDirection = (RepeatDirection) 4; + } + + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void RepeatLayoutException () + { + TestRadioButtonList r = new TestRadioButtonList (); + r.RepeatLayout = (RepeatLayout) 3; + } + + + } + +} Added: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SelectedDatesCollectionTest.cs =================================================================== --- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SelectedDatesCollectionTest.cs 2005-08-26 22:53:47 UTC (rev 48937) +++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SelectedDatesCollectionTest.cs 2005-08-26 22:54:16 UTC (rev 48938) @@ -0,0 +1,120 @@ +// +// Tests for System.Web.UI.WebControls.SelectedDatesCollection.cs +// +// Author: +// Jordi Mas i Hernandez ([EMAIL PROTECTED]) +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Web.UI.WebControls; +using NUnit.Framework; +using System; +using System.Collections; +using System.Web; +using System.Web.UI; +using System.Globalization; + + +namespace MonoTests.System.Web.UI.WebControls +{ + [TestFixture] + public class SelectedDatesCollectionTest { + + + [Test] + public void SelectedDatesCollectionTest_DefaultValues () + { + ArrayList list = new ArrayList (); + SelectedDatesCollection s = new SelectedDatesCollection (list); + + Assert.AreEqual (0, s.Count, "A1"); + Assert.AreEqual (false, s.IsReadOnly, "A2"); + Assert.AreEqual (false, s.IsSynchronized, "A3"); + Assert.AreEqual (s, s.SyncRoot, "A4"); + } + + + // + // Methods + // + [Test] + public void AddMethod () + { + ArrayList list = new ArrayList (); + SelectedDatesCollection s = new SelectedDatesCollection (list); + + s.Add (DateTime.Today); + Assert.AreEqual (true, s.Contains (DateTime.Today), "A1"); + Assert.AreEqual (1, s.Count, "A2"); + + s.Add (DateTime.Today); // Duplicates are not inserted + Assert.AreEqual (1, s.Count, "A2"); + } + + // + // Methods + // + [Test] + public void ClearMethod () + { + ArrayList list = new ArrayList (); + SelectedDatesCollection s = new SelectedDatesCollection (list); + + s.Add (DateTime.Today); + s.Clear (); + Assert.AreEqual (0, s.Count, "A1"); + } + + + [Test] + public void SelectRangeMethod () + { + ArrayList list = new ArrayList (); + SelectedDatesCollection s = new SelectedDatesCollection (list); + + s.Add (DateTime.Today); + s.Add (DateTime.Today); + // Internally clears the list + s.SelectRange (new DateTime (2000, 1, 1), new DateTime (2001, 1, 1)); + + Assert.AreEqual (367, s.Count, "A1"); + } + + [Test] + public void RemoveMethod () + { + ArrayList list = new ArrayList (); + SelectedDatesCollection s = new SelectedDatesCollection (list); + + s.Add (DateTime.Today); + s.Remove (DateTime.Today); + Assert.AreEqual (0, s.Count, "A1"); + } + + } +} + + + _______________________________________________ Mono-patches maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-patches
