w32file-unix.c: In function 'mono_w32file_get_file_size':
[mono-project.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls.Adapters / MenuAdapterTest.cs
blobeb14e2b5c030b30803e2adb56d7c7baf67451e52
1 //
2 // Tests for System.Web.UI.WebControls.Adapters.MenuAdapter
3 //
4 // Author:
5 // Dean Brettle (dean@brettle.com)
6 //
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
30 using System;
31 using System.Collections;
32 using System.Drawing;
33 using System.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.Web.UI.WebControls.Adapters;
39 using System.Web.Configuration;
40 using MonoTests.SystemWeb.Framework;
43 namespace MonoTests.System.Web.UI.WebControls.Adapters
45 [TestFixture]
46 public class MenuAdapterTest
48 MyMenu c;
49 MyMenuAdapter a;
50 StringWriter sw;
51 HtmlTextWriter w;
52 Page p;
53 EventArgs e;
55 [SetUp]
56 public void SetUp ()
58 p = new Page ();
59 c = new MyMenu ();
60 c.RenderingMode = MenuRenderingMode.Table;
61 a = new MyMenuAdapter (c);
62 p.Controls.Add(c);
63 sw = new StringWriter ();
64 w = new HtmlTextWriter (sw);
65 e = new EventArgs();
68 [Test]
69 public void OnInit ()
71 a.OnInit (e);
72 Assert.IsTrue (p.RequiresControlState (c), "OnInit #1");
73 Assert.AreEqual (e, c.on_init_arg, "OnInit #2");
76 [Test]
77 public void OnPreRender ()
79 a.OnPreRender (e);
80 Assert.AreEqual (e, c.on_pre_render_arg, "OnPreRender #1");
83 [Test]
84 public void RaisePostBackEvent ()
86 ((IPostBackEventHandler)a).RaisePostBackEvent ("eventArg");
87 Assert.AreEqual ("eventArg", c.raise_post_back_event_arg, "RaisePostBackEvent #1");
90 [Test]
91 public void RenderBeginTag ()
93 a.RenderBeginTag (w);
94 Assert.AreEqual ("RenderBeginTag\n", sw.ToString ().Replace ("\r", ""), "RenderBeginTag #1");
97 [Test]
98 public void RenderContentsTag ()
100 a.RenderContents (w);
101 Assert.AreEqual ("RenderContents\n", sw.ToString ().Replace ("\r", ""), "RenderContents #1");
104 [Test]
105 public void RenderEndTag ()
107 a.RenderEndTag (w);
108 Assert.AreEqual ("RenderEndTag\n", sw.ToString ().Replace ("\r", ""), "RenderEndTag #1");
111 [Test]
112 public void RenderItem ()
114 MenuItem item = new MenuItem("menu item text");
116 // This has to stay to work around event validation errors. If it's removed,
117 // then RenderItem will eventually attempt to register for event validation,
118 // which can only be done during the Render phase.
119 item.NavigateUrl = "http://example.com/";
120 a.RenderItem (w, item, 0);
121 Assert.IsTrue (sw.ToString ().IndexOf("menu item text") != -1, "RenderItem #1");
124 [Test]
125 public void Control ()
127 Assert.AreEqual (c, a.Control, "Control #1");
132 #region Support classes
134 class MyMenu : Menu
137 internal EventArgs on_init_arg;
138 protected internal override void OnInit (EventArgs e)
140 on_init_arg = e;
141 base.OnInit (e);
144 internal EventArgs on_pre_render_arg;
145 protected internal override void OnPreRender (EventArgs e)
147 on_pre_render_arg = e;
148 base.OnPreRender (e);
151 internal string raise_post_back_event_arg;
152 protected internal override void RaisePostBackEvent (string eventArgument)
154 raise_post_back_event_arg = eventArgument;
157 public override void RenderBeginTag (HtmlTextWriter w)
159 w.WriteLine("RenderBeginTag");
162 protected internal override void RenderContents (HtmlTextWriter w)
164 w.WriteLine("RenderContents");
167 public override void RenderEndTag (HtmlTextWriter w)
169 w.WriteLine("RenderEndTag");
174 class MyMenuAdapter : SystemWebTestShim.MenuAdapter
176 internal MyMenuAdapter (Menu c) : base (c)
180 internal new void OnInit (EventArgs e)
182 base.OnInit (e);
185 internal new void OnPreRender (EventArgs e)
187 base.OnPreRender (e);
190 new internal void RenderBeginTag (HtmlTextWriter w)
192 base.RenderBeginTag (w);
195 new internal void RenderContents (HtmlTextWriter w)
197 base.RenderContents (w);
200 new internal void RenderEndTag (HtmlTextWriter w)
202 base.RenderEndTag (w);
205 new internal Menu Control {
206 get { return base.Control; }
209 internal new void RenderItem (HtmlTextWriter w, MenuItem mi, int i)
211 base.RenderItem (w, mi, i);
215 #endregion