2 // Tests for System.Web.UI.WebControls.Adapters.MenuAdapter
5 // Dean Brettle (dean@brettle.com)
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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
;
31 using System
.Collections
;
34 using System
.Globalization
;
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
46 public class MenuAdapterTest
60 c
.RenderingMode
= MenuRenderingMode
.Table
;
61 a
= new MyMenuAdapter (c
);
63 sw
= new StringWriter ();
64 w
= new HtmlTextWriter (sw
);
72 Assert
.IsTrue (p
.RequiresControlState (c
), "OnInit #1");
73 Assert
.AreEqual (e
, c
.on_init_arg
, "OnInit #2");
77 public void OnPreRender ()
80 Assert
.AreEqual (e
, c
.on_pre_render_arg
, "OnPreRender #1");
84 public void RaisePostBackEvent ()
86 ((IPostBackEventHandler
)a
).RaisePostBackEvent ("eventArg");
87 Assert
.AreEqual ("eventArg", c
.raise_post_back_event_arg
, "RaisePostBackEvent #1");
91 public void RenderBeginTag ()
94 Assert
.AreEqual ("RenderBeginTag\n", sw
.ToString ().Replace ("\r", ""), "RenderBeginTag #1");
98 public void RenderContentsTag ()
100 a
.RenderContents (w
);
101 Assert
.AreEqual ("RenderContents\n", sw
.ToString ().Replace ("\r", ""), "RenderContents #1");
105 public void RenderEndTag ()
108 Assert
.AreEqual ("RenderEndTag\n", sw
.ToString ().Replace ("\r", ""), "RenderEndTag #1");
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");
125 public void Control ()
127 Assert
.AreEqual (c
, a
.Control
, "Control #1");
132 #region Support classes
137 internal EventArgs on_init_arg
;
138 protected internal override void OnInit (EventArgs 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
)
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
);