\r\n";
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "RenderBeginTag_List");
}
[Test]
[Category ("NunitWeb")]
public void Menu_RenderEndTag ()
{
new WebTest (PageInvoker.CreateOnLoad (_EndTagRender)).Run ();
}
public static void _EndTagRender (Page p)
{
PokerMenu pm = new PokerMenu ();
pm.RenderingCompatibility = new Version (2, 0);
p.Form.Controls.Add (pm);
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
pm.RenderBeginTag (tw);
pm.RenderEndTag (tw);
string RenderedControlHtml = sw.ToString ();
string OriginControlHtml = "
";
HtmlDiff.AssertAreEqual(OriginControlHtml, RenderedControlHtml,"RenderEndTag");
}
[Test]
[Category ("NunitWeb")]
public void Menu_RenderEndTag_List ()
{
new WebTest (PageInvoker.CreateOnLoad (_EndTagRender_List)).Run ();
}
public static void _EndTagRender_List (Page p)
{
PokerMenu pm = new PokerMenu ();
pm.RenderingCompatibility = new Version (4, 0);
pm.RenderingMode = MenuRenderingMode.List;
p.Form.Controls.Add (pm);
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
pm.RenderBeginTag (tw);
pm.RenderEndTag (tw);
string RenderedControlHtml = sw.ToString ();
string OriginControlHtml = "
\r\n\r\n
";
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "RenderEndTag");
}
[Test]
public void Menu_DataBind () {
Page p = new Page ();
Menu m = CreateMenu ();
m.DataBinding += new EventHandler (m_DataBinding);
m.DataBound += new EventHandler (m_DataBound);
p.Controls.Add (m);
ResetTemplateBoundFlags ();
m.DataBind ();
}
static void m_DataBinding (object sender, EventArgs e) {
Assert.AreEqual (true, _StaticTemplateCreated, "StaticTemplateCreated");
Assert.AreEqual (true, _DynamicTemplateCreated, "DynamicTemplateCreated");
}
static void m_DataBound (object sender, EventArgs e) {
Assert.AreEqual (true, _StaticTemplateBound, "StaticTemplateBound");
Assert.AreEqual (true, _DynamicTemplateBound, "DynamicTemplateBound");
}
private static void ResetTemplateBoundFlags() {
_StaticTemplateBound = false;
_DynamicTemplateBound = false;
_StaticTemplateCreated = false;
_DynamicTemplateCreated = false;
}
static Menu CreateMenu () {
Menu m = new MenuTable ();
MenuItem rootItem = new MenuItem ("RootItem-Text", "RootItem-Value");
m.Items.Add (rootItem);
rootItem.ChildItems.Add (new MenuItem ("Node1-Text", "Node1-Value"));
rootItem.ChildItems.Add (new MenuItem ("Node2-Text", "Node2-Value"));
m.StaticItemTemplate = new CompiledTemplateBuilder (_StaticItemTemplate);
m.DynamicItemTemplate = new CompiledTemplateBuilder (_DynamicItemTemplate);
return m;
}
[Test]
[Category ("NunitWeb")]
public void Menu_DataBindByDataSourceID () {
PageDelegates pd = new PageDelegates ();
pd.Init = Menu_DataBindByDataSourceID_PageInit;
pd.PreRenderComplete = Menu_DataBindByDataSourceID_PagePreRenderComplete;
PageInvoker pi = new PageInvoker (pd);
new WebTest (pi).Run ();
}
public static void Menu_DataBindByDataSourceID_PageInit (Page p) {
XmlDataSource xmlDs = new XmlDataSource ();
xmlDs.ID = "XmlDataSource";
xmlDs.Data = "
";
p.Form.Controls.Add (xmlDs);
Menu m = CreateMenu ();
m.RenderingMode = MenuRenderingMode.Table;
m.DataSourceID = "XmlDataSource";
m.MenuItemDataBound += new MenuEventHandler (m_MenuItemDataBound);
p.Form.Controls.Add (m);
ResetTemplateBoundFlags ();
_MenuItemBoundCount = 0;
_MenuItemCreatedCount = 0;
}
public static void m_MenuItemDataBound (object sender, MenuEventArgs e) {
_MenuItemBoundCount++;
}
[Test]
[Category ("NunitWeb")]
public void Menu_Templates () {
PageDelegates pd = new PageDelegates ();
pd.Init = Menu_Templates_PageInit;
pd.PreRenderComplete = Menu_Templates_PagePreRenderComplete;
PageInvoker pi = new PageInvoker (pd);
new WebTest (pi).Run ();
}
public static void Menu_Templates_PageInit (Page p) {
Menu m = CreateMenu ();
p.Form.Controls.Add (m);
ResetTemplateBoundFlags ();
}
static bool _StaticTemplateBound;
static bool _DynamicTemplateBound;
static bool _StaticTemplateCreated;
static bool _DynamicTemplateCreated;
static int _MenuItemBoundCount;
static int _MenuItemCreatedCount;
private static void CheckTemplateBoundFlags () {
Assert.AreEqual (true, _StaticTemplateCreated, "StaticTemplateCreated");
Assert.AreEqual (true, _DynamicTemplateCreated, "DynamicTemplateCreated");
Assert.AreEqual (true, _StaticTemplateBound, "StaticTemplateBound");
Assert.AreEqual (true, _DynamicTemplateBound, "DynamicTemplateBound");
}
public static void Menu_Templates_PagePreRenderComplete (Page p) {
CheckTemplateBoundFlags ();
}
public static void Menu_DataBindByDataSourceID_PagePreRenderComplete (Page p) {
CheckTemplateBoundFlags ();
Assert.AreEqual (6, _MenuItemBoundCount, "MenuItemBoundCount");
Assert.AreEqual (6, _MenuItemCreatedCount, "MenuItemBoundCount");
}
private static void _StaticItemTemplate (Control container) {
_StaticTemplateCreated = true;
_MenuItemCreatedCount++;
Literal l = new Literal ();
container.Controls.Add (l);
container.DataBinding += new EventHandler (StaticTemplate_DataBinding);
}
static void StaticTemplate_DataBinding (object sender, EventArgs e) {
_StaticTemplateBound = true;
}
private static void _DynamicItemTemplate (Control container) {
_DynamicTemplateCreated = true;
_MenuItemCreatedCount++;
Literal l = new Literal ();
container.Controls.Add (l);
container.DataBinding += new EventHandler (DynamicTemplate_DataBinding);
}
static void DynamicTemplate_DataBinding (object sender, EventArgs e) {
_DynamicTemplateBound = true;
}
[Test]
public void Menu_ViewState()
{
PokerMenu b = new PokerMenu ();
PokerMenu copy = new PokerMenu ();
b.ToolTip = "mytest1";
b.Target = "mytest2";
b.BackColor = Color.Red;
b.BorderColor = Color.Red;
b.BorderStyle = BorderStyle.Dotted;
b.BorderWidth = 1;
b.ForeColor = Color.Red;
b.Height = 100;
b.MaximumDynamicDisplayLevels = 2;
b.Orientation = Orientation.Vertical;
b.PathSeparator = '-';
b.ScrollDownImageUrl = "test";
b.ScrollDownText = "test";
b.ScrollUpImageUrl = "test";
b.ScrollUpText = "test";
b.SkipLinkText = "test";
b.Visible = false;
b.Width = 100;
b.TabIndex = 1;
object state = b.DoSaveViewState ();
copy.DoLoadViewState (state);
Assert.AreEqual ("mytest1", copy.ToolTip, "ViewState#1");
Assert.AreEqual ("mytest2", copy.Target, "ViewState#2");
Assert.AreEqual (Color.Red, copy.BackColor, "ViewState#3");
Assert.AreEqual (Color.Red, copy.BorderColor , "ViewState#4");
Assert.AreEqual (BorderStyle.Dotted, copy.BorderStyle, "ViewState#5");
Assert.AreEqual (Unit.Pixel(1), copy.BorderWidth, "ViewState#6");
Assert.AreEqual (Color.Red, copy.ForeColor, "ViewState#8");
Assert.AreEqual (Unit.Pixel(100), copy.Height, "ViewState#9");
Assert.AreEqual (2, copy.MaximumDynamicDisplayLevels, "ViewState#10");
Assert.AreEqual (Orientation.Vertical, copy.Orientation, "ViewState#11");
Assert.AreEqual ('-', copy.PathSeparator, "ViewState#12");
Assert.AreEqual ("test", copy.ScrollDownImageUrl, "ViewState#13");
Assert.AreEqual ("test", copy.ScrollDownText, "ViewState#14");
Assert.AreEqual ("test", copy.ScrollUpImageUrl, "ViewState#15");
Assert.AreEqual ("test", copy.ScrollUpText, "ViewState#16");
Assert.AreEqual ("test", copy.SkipLinkText, "ViewState#17");
Assert.AreEqual (1, copy.TabIndex, "ViewState#18");
Assert.AreEqual (false, copy.Visible, "ViewState#19");
Assert.AreEqual (Unit.Pixel (100), copy.Width, "ViewState#20");
}
[Test]
public void Menu_ViewStateNotWorking()
{
PokerMenu b = new PokerMenu ();
PokerMenu copy = new PokerMenu ();
b.Font.Size = 10;
object state = b.DoSaveViewState ();
copy.DoLoadViewState (state);
Assert.AreEqual ("10pt", copy.Font.Size.ToString() , "ViewState#7");
}
[Test]
public void Menu_ViewStateItems () {
PokerMenu b = new PokerMenu ();
MenuItem R = new MenuItem ("root", "value-root");
MenuItem N1 = new MenuItem ("node1", "value-node1");
MenuItem N2 = new MenuItem ("node2", "value-node2");
R.ChildItems.Add (N1);
R.ChildItems.Add (N2);
b.Items.Add (R);
PokerMenu copy = new PokerMenu ();
object state = b.DoSaveViewState ();
copy.DoLoadViewState (state);
Assert.AreEqual (1, copy.Items.Count, "ViewStateItems#1");
Assert.AreEqual (2, copy.Items [0].ChildItems.Count, "ViewStateItems#2");
Assert.AreEqual (0, copy.Items [0].ChildItems [0].ChildItems.Count, "ViewStateItems#3");
Assert.AreEqual ("node1", copy.Items [0].ChildItems [0].Text, "ViewStateItems#4");
Assert.AreEqual ("value-node1", copy.Items [0].ChildItems [0].Value, "ViewStateItems#5");
Assert.AreEqual (false, copy.Items [0].ChildItems [0].DataBound, "ViewStateItems#6");
Assert.AreEqual ("", copy.Items [0].ChildItems [0].DataPath, "ViewStateItems#7");
}
[Test]
public void Menu_ViewStateDataBoundItems () {
PokerMenu b = new PokerMenu ();
SetDataBindings (b);
b.DataSource = CreateXmlDataSource ();
b.DataBind ();
PokerMenu copy = new PokerMenu ();
object state = b.DoSaveViewState ();
copy.DoLoadViewState (state);
CheckMenuItems (copy);
}
private static void CheckMenuItems (Menu m) {
Assert.AreEqual (1, m.Items.Count, "CheckMenuItems#1");
Assert.AreEqual (10, m.Items [0].ChildItems.Count, "CheckMenuItems#2");
Assert.AreEqual (0, m.Items [0].ChildItems [0].ChildItems.Count, "CheckMenuItems#3");
Assert.AreEqual (true, m.Items [0].ChildItems [0].DataBound, "CheckMenuItems#4");
Assert.AreEqual ("/*[position()=1]/*[position()=1]", m.Items [0].ChildItems [0].DataPath, "CheckMenuItems#5");
Assert.AreEqual (false, m.Items [0].Enabled, "CheckMenuItems_Enabled#1");
Assert.AreEqual (true, m.Items [0].ChildItems [0].Enabled, "CheckMenuItems_Enabled#2");
Assert.AreEqual (false, m.Items [0].ChildItems [1].Enabled, "CheckMenuItems_Enabled#3");
Assert.AreEqual (false, m.Items [0].ChildItems [2].Enabled, "CheckMenuItems_Enabled#4");
Assert.AreEqual (true, m.Items [0].ChildItems [2].ChildItems [0].Enabled, "CheckMenuItems_Enabled#5");
Assert.AreEqual ("img#root", m.Items [0].ImageUrl, "CheckMenuItems_ImageUrl#1");
Assert.AreEqual ("img#1", m.Items [0].ChildItems [0].ImageUrl, "CheckMenuItems_ImageUrl#2");
Assert.AreEqual ("img#2", m.Items [0].ChildItems [1].ImageUrl, "CheckMenuItems_ImageUrl#3");
Assert.AreEqual ("img#default", m.Items [0].ChildItems [2].ImageUrl, "CheckMenuItems_ImageUrl#4");
Assert.AreEqual ("", m.Items [0].ChildItems [2].ChildItems [0].ImageUrl, "CheckMenuItems_ImageUrl#5");
Assert.AreEqual ("url#root", m.Items [0].NavigateUrl, "CheckMenuItems_NavigateUrl#1");
Assert.AreEqual ("url#1", m.Items [0].ChildItems [0].NavigateUrl, "CheckMenuItems_NavigateUrl#2");
Assert.AreEqual ("url#2", m.Items [0].ChildItems [1].NavigateUrl, "CheckMenuItems_NavigateUrl#3");
Assert.AreEqual ("url#default", m.Items [0].ChildItems [2].NavigateUrl, "CheckMenuItems_NavigateUrl#4");
Assert.AreEqual ("", m.Items [0].ChildItems [2].ChildItems [0].NavigateUrl, "CheckMenuItems_NavigateUrl#5");
Assert.AreEqual ("popoutimg#root", m.Items [0].PopOutImageUrl, "CheckMenuItems_PopOutImageUrl#1");
Assert.AreEqual ("popoutimg#1", m.Items [0].ChildItems [0].PopOutImageUrl, "CheckMenuItems_PopOutImageUrl#2");
Assert.AreEqual ("popoutimg#2", m.Items [0].ChildItems [1].PopOutImageUrl, "CheckMenuItems_PopOutImageUrl#3");
Assert.AreEqual ("popoutimg#default", m.Items [0].ChildItems [2].PopOutImageUrl, "CheckMenuItems_PopOutImageUrl#4");
Assert.AreEqual ("", m.Items [0].ChildItems [2].ChildItems [0].PopOutImageUrl, "CheckMenuItems_PopOutImageUrl#5");
Assert.AreEqual (false, m.Items [0].Selectable, "CheckMenuItems_Selectable#1");
Assert.AreEqual (true, m.Items [0].ChildItems [0].Selectable, "CheckMenuItems_Selectable#2");
Assert.AreEqual (false, m.Items [0].ChildItems [1].Selectable, "CheckMenuItems_Selectable#3");
Assert.AreEqual (false, m.Items [0].ChildItems [2].Selectable, "CheckMenuItems_Selectable#4");
Assert.AreEqual (true, m.Items [0].ChildItems [2].ChildItems [0].Selectable, "CheckMenuItems_Selectable#5");
Assert.AreEqual ("separatorimg#root", m.Items [0].SeparatorImageUrl, "CheckMenuItems_SeparatorImageUrl#1");
Assert.AreEqual ("separatorimg#1", m.Items [0].ChildItems [0].SeparatorImageUrl, "CheckMenuItems_SeparatorImageUrl#2");
Assert.AreEqual ("separatorimg#2", m.Items [0].ChildItems [1].SeparatorImageUrl, "CheckMenuItems_SeparatorImageUrl#3");
Assert.AreEqual ("separatorimg#default", m.Items [0].ChildItems [2].SeparatorImageUrl, "CheckMenuItems_SeparatorImageUrl#4");
Assert.AreEqual ("", m.Items [0].ChildItems [2].ChildItems [0].SeparatorImageUrl, "CheckMenuItems_SeparatorImageUrl#5");
Assert.AreEqual ("target#root", m.Items [0].Target, "CheckMenuItems_Target#1");
Assert.AreEqual ("target#1", m.Items [0].ChildItems [0].Target, "CheckMenuItems_Target#2");
Assert.AreEqual ("target#2", m.Items [0].ChildItems [1].Target, "CheckMenuItems_Target#3");
Assert.AreEqual ("target#default", m.Items [0].ChildItems [2].Target, "CheckMenuItems_Target#4");
Assert.AreEqual ("", m.Items [0].ChildItems [2].ChildItems [0].Target, "CheckMenuItems_Target#5");
Assert.AreEqual ("text#root", m.Items [0].Text, "CheckMenuItems_Text#1");
Assert.AreEqual ("text#1", m.Items [0].ChildItems [0].Text, "CheckMenuItems_Text#2");
Assert.AreEqual ("text#2", m.Items [0].ChildItems [1].Text, "CheckMenuItems_Text#3");
Assert.AreEqual ("text#", m.Items [0].ChildItems [2].Text, "CheckMenuItems_Text#4");
Assert.AreEqual ("subnode", m.Items [0].ChildItems [2].ChildItems [0].Text, "CheckMenuItems_Text#5");
Assert.AreEqual ("tooltip#root", m.Items [0].ToolTip, "CheckMenuItems_ToolTip#1");
Assert.AreEqual ("tooltip#1", m.Items [0].ChildItems [0].ToolTip, "CheckMenuItems_ToolTip#2");
Assert.AreEqual ("tooltip#2", m.Items [0].ChildItems [1].ToolTip, "CheckMenuItems_ToolTip#3");
Assert.AreEqual ("tooltip#default", m.Items [0].ChildItems [2].ToolTip, "CheckMenuItems_ToolTip#4");
Assert.AreEqual ("", m.Items [0].ChildItems [2].ChildItems [0].ToolTip, "CheckMenuItems_ToolTip#5");
Assert.AreEqual ("value#root", m.Items [0].Value, "CheckMenuItems_Value#1");
Assert.AreEqual ("value#1", m.Items [0].ChildItems [0].Value, "CheckMenuItems_Value#2");
Assert.AreEqual ("value#2", m.Items [0].ChildItems [1].Value, "CheckMenuItems_Value#3");
Assert.AreEqual ("value#default", m.Items [0].ChildItems [2].Value, "CheckMenuItems_Value#4");
Assert.AreEqual ("subnode", m.Items [0].ChildItems [2].ChildItems [0].Value, "CheckMenuItems_Value#5");
Assert.AreEqual ("text#extra1", m.Items [0].ChildItems [3].Text, "CheckMenuItems_Extra1#1");
Assert.AreEqual ("text#extra1", m.Items [0].ChildItems [3].Value, "CheckMenuItems_Extra1#2");
Assert.AreEqual ("value#extra2", m.Items [0].ChildItems [4].Text, "CheckMenuItems_Extra2#1");
Assert.AreEqual ("value#extra2", m.Items [0].ChildItems [4].Value, "CheckMenuItems_Extra2#2");
Assert.AreEqual ("text#extra3", m.Items [0].ChildItems [5].Text, "CheckMenuItems_Extra3#1");
Assert.AreEqual ("", m.Items [0].ChildItems [5].Value, "CheckMenuItems_Extra3#2");
Assert.AreEqual ("", m.Items [0].ChildItems [6].Text, "CheckMenuItems_Extra3#3");
Assert.AreEqual ("value#extra3", m.Items [0].ChildItems [6].Value, "CheckMenuItems_Extra3#4");
Assert.AreEqual ("", m.Items [0].ChildItems [7].Text, "CheckMenuItems_Extra3#5");
Assert.AreEqual ("", m.Items [0].ChildItems [7].Value, "CheckMenuItems_Extra3#6");
Assert.AreEqual ("text#extra4", m.Items [0].ChildItems [8].Text, "CheckMenuItems_Extra4#1");
Assert.AreEqual ("text#default", m.Items [0].ChildItems [8].Value, "CheckMenuItems_Extra4#2");
Assert.AreEqual ("value#default", m.Items [0].ChildItems [9].Text, "CheckMenuItems_Extra5#1");
Assert.AreEqual ("value#extra5", m.Items [0].ChildItems [9].Value, "CheckMenuItems_Extra5#2");
}
void SetDataBindings (Menu menu) {
MenuItemBinding b = new MenuItemBinding ();
b.DataMember = "node";
b.EnabledField = "enabled";
b.Enabled = false;
b.ImageUrlField = "img";
b.ImageUrl = "img#default";
b.NavigateUrlField = "url";
b.NavigateUrl = "url#default";
b.PopOutImageUrlField = "popoutimg";
b.PopOutImageUrl = "popoutimg#default";
b.SelectableField = "selectable";
b.Selectable = false;
b.SeparatorImageUrlField = "separatorimg";
b.SeparatorImageUrl = "separatorimg#default";
b.TargetField = "target";
b.Target = "target#default";
b.FormatString = "text#{0}";
b.TextField = "text";
b.Text = "text#default";
b.ToolTipField = "tooltip";
b.ToolTip = "tooltip#default";
b.ValueField = "value";
b.Value = "value#default";
menu.DataBindings.Add (b);
b = new MenuItemBinding ();
b.DataMember = "root";
b.Enabled = false;
b.ImageUrl = "img#root";
b.NavigateUrl = "url#root";
b.PopOutImageUrl = "popoutimg#root";
b.Selectable = false;
b.SeparatorImageUrl = "separatorimg#root";
b.Target = "target#root";
b.Text = "text#root";
b.ToolTip = "tooltip#root";
b.Value = "value#root";
menu.DataBindings.Add (b);
b = new MenuItemBinding ();
b.DataMember = "extra1";
b.Text = "text#extra1";
menu.DataBindings.Add (b);
b = new MenuItemBinding ();
b.DataMember = "extra2";
b.Value = "value#extra2";
menu.DataBindings.Add (b);
b = new MenuItemBinding ();
b.DataMember = "extra3";
b.TextField = "text";
b.ValueField = "value";
menu.DataBindings.Add (b);
b = new MenuItemBinding ();
b.DataMember = "extra4";
b.TextField = "text";
b.Text = "text#default";
b.ValueField = "value";
menu.DataBindings.Add (b);
b = new MenuItemBinding ();
b.DataMember = "extra5";
b.TextField = "text";
b.Value = "value#default";
b.ValueField = "value";
menu.DataBindings.Add (b);
}
XmlDataSource CreateXmlDataSource () {
XmlDataSource xmlDs = new XmlDataSource ();
xmlDs.ID = "XmlDataSource";
xmlDs.Data = "
"+
"" +
"" +
"" +
"" +
""+
""+
"" +
"" +
"" +
"" +
"" +
"";
return xmlDs;
}
[Test]
public void Menu_DataBindings () {
Menu m = new MenuTable ();
SetDataBindings (m);
m.DataSource = CreateXmlDataSource ();
m.DataBind ();
CheckMenuItems (m);
}
// Rendering Menu controll with some possible options, styles and items
[Test]
[Category ("NunitWeb")]
[Ignore ("NUNIT 2.4 issue - temporarily disabled")]
public void Menu_DefaultRender ()
{
string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (_DefaultRender)).Run ();
string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
string OriginControlHtml = "";
HtmlDiff.AssertAreEqual(OriginControlHtml, RenderedControlHtml,"RenderDefault");
}
// All this methods are delegates for running tests in host assembly.
public static void _DefaultRender (Page p)
{
LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
Menu menu = new MenuTable ();
p.Form.Controls.Add (lcb);
p.Form.Controls.Add (menu);
p.Form.Controls.Add (lce);
}
[Test]
[Category ("NunitWeb")]
public void Menu_RenderStaticItems () {
string RenderedPageHtml, RenderedControlHtml, OriginControlHtml;
#region OriginControlHtml
OriginControlHtml = "
";
#endregion
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItems_Vertical)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItems_Vertical");
#if !DOT_NET
// Throws NREX on .NET 4.0, most probably because the adapter's Control is null
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItemsWithBaseAdapter_Vertical)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItemsWithDefaultAdapter_Vertical");
#endif
#region OriginControlHtml
OriginControlHtml = "
";
#endregion
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItems_Horizontal)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItems_Horizontal");
#if !DOT_NET
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItemsWithBaseAdapter_Horizontal)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItemsWithBaseAdapter_Horizontal");
#endif
}
[Test]
[Category ("NunitWeb")]
[Ignore ("Disabled temporarily")]
public void Menu_RenderStaticItems_List ()
{
string RenderedPageHtml, RenderedControlHtml, OriginControlHtml;
#region OriginControlHtml
OriginControlHtml = "
";
#endregion
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItems_Vertical_List)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItems_Vertical");
#if !DOT_NET
// Throws NREX on .NET 4.0, most probably because the adapter's Control is null
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItemsWithBaseAdapter_Vertical)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItemsWithDefaultAdapter_Vertical");
#endif
#region OriginControlHtml
OriginControlHtml = "
";
#endregion
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItems_Horizontal_List)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItems_Horizontal");
#if !DOT_NET
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItemsWithBaseAdapter_Horizontal)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItemsWithBaseAdapter_Horizontal");
#endif
}
class MyMenuAdapter : global::System.Web.UI.WebControls.Adapters.MenuAdapter
{
protected internal override void RenderItem (HtmlTextWriter writer,
MenuItem item,
int position)
{
writer.Write ("{");
base.RenderItem (writer, item, position);
writer.Write ("}");
}
}
[Test]
[Category ("NunitWeb")]
[Category ("NotDotNet")]
public void Menu_RenderStaticItemsWithAdapter ()
{
string RenderedPageHtml, RenderedControlHtml, OriginControlHtml;
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItemsWithAdapter_Vertical)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
#region OriginControlHtml
OriginControlHtml = @"
";
#endregion
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItemsWithAdapter_Vertical");
RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (Menu_RenderStaticItemsWithAdapter_Horizontal)).Run ();
RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
#region OriginControlHtml
OriginControlHtml = @"
";
#endregion
HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "Menu_RenderStaticItemsWithAdapter_Horizontal");
}
public static void Menu_RenderStaticItems_Vertical (Page p) {
Menu m = CreateMenuForRenderTests (null);
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItems_Horizontal (Page p) {
Menu m = CreateMenuForRenderTests (null);
m.Orientation = Orientation.Horizontal;
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItems_Vertical_List (Page p)
{
Menu m = CreateMenuForRenderTests (null, false);
m.RenderingCompatibility = new Version (4, 0);
m.RenderingMode = MenuRenderingMode.List;
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItems_Horizontal_List (Page p)
{
Menu m = CreateMenuForRenderTests (null, false);
m.Orientation = Orientation.Horizontal;
m.StaticDisplayLevels = 4;
m.RenderingCompatibility = new Version (4, 0);
m.RenderingMode = MenuRenderingMode.List;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItemsWithBaseAdapter_Vertical (Page p) {
Menu m = CreateMenuForRenderTests (new MyWebControl.Adapters.MenuAdapter());
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItemsWithBaseAdapter_Horizontal (Page p) {
Menu m = CreateMenuForRenderTests (new MyWebControl.Adapters.MenuAdapter());
m.Orientation = Orientation.Horizontal;
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItemsWithAdapter_Vertical (Page p) {
Menu m = CreateMenuForRenderTests (new MyMenuAdapter());
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
public static void Menu_RenderStaticItemsWithAdapter_Horizontal (Page p) {
Menu m = CreateMenuForRenderTests (new MyMenuAdapter());
m.Orientation = Orientation.Horizontal;
m.StaticDisplayLevels = 4;
AddMenuToPage (p, m);
}
private static void AddMenuToPage (Page p, Menu m) {
LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
p.Form.Controls.Add (lcb);
p.Form.Controls.Add (m);
p.Form.Controls.Add (lce);
}
class MyMenu : Menu
{
internal MyMenu (MyWebControl.Adapters.MenuAdapter adapter) : base ()
{
menu_adapter = adapter;
}
MyWebControl.Adapters.MenuAdapter menu_adapter;
protected override global::System.Web.UI.Adapters.ControlAdapter ResolveAdapter ()
{
return menu_adapter;
}
}
static Menu CreateMenuForRenderTests (MyWebControl.Adapters.MenuAdapter adapter)
{
return CreateMenuForRenderTests (adapter, true);
}
static Menu CreateMenuForRenderTests (MyWebControl.Adapters.MenuAdapter adapter, bool compatibilityRendering)
{
Menu menu = new MyMenu (adapter);
if (compatibilityRendering)
menu.RenderingCompatibility = new Version (3, 5);
menu.ID = "Menu";
MenuItem R, N1, N2, SN1, SN2, SN3, SN4;
R = new MenuItem ("one-black", "one-black-value");
N1 = new MenuItem ("two-black-1", "two-black-1-value");
N2 = new MenuItem ("two-black-2", "two-black-2-value");
SN1 = new MenuItem ("three-black-1", "three-black-1-value");
SN2 = new MenuItem ("three-black-2", "three-black-2-value");
SN3 = new MenuItem ("three-black-3", "three-black-3-value");
SN4 = new MenuItem ("three-black-4", "three-black-4-value");
SN1.ChildItems.Add (new MenuItem ("four-black-1", "four-black-1-value"));
SN1.ChildItems.Add (new MenuItem ("four-black-2", "four-black-2-value"));
SN2.ChildItems.Add (new MenuItem ("four-black-3", "four-black-3-value"));
SN2.ChildItems.Add (new MenuItem ("four-black-4", "four-black-4-value"));
SN3.ChildItems.Add (new MenuItem ("four-black-5", "four-black-5-value"));
SN3.ChildItems.Add (new MenuItem ("four-black-6", "four-black-6-value"));
SN4.ChildItems.Add (new MenuItem ("four-black-7", "four-black-7-value"));
SN4.ChildItems.Add (new MenuItem ("four-black-8", "four-black-8-value"));
N1.ChildItems.Add (SN1);
N1.ChildItems.Add (SN2);
N2.ChildItems.Add (SN3);
N2.ChildItems.Add (SN4);
R.ChildItems.Add (N1);
R.ChildItems.Add (N2);
menu.Items.Add (R);
return menu;
}
//Events Stuff
private bool OnDataBinding;
private bool OnDataBound;
private bool OnMenuItemClick;
private bool OnInit;
private bool OnMenuItemDataBound;
private bool OnPreRender;
private void OnMenuItemDataBoundHandler(object sender, MenuEventArgs e)
{
OnMenuItemDataBound = true;
}
private void OnInitHandler (object sender, EventArgs e)
{
OnInit = true;
}
private void OnDataBindingHandler (object sender, EventArgs e)
{
OnDataBinding = true;
}
private void OnDataDataBoundHandler (object sender, EventArgs e)
{
OnDataBound = true;
}
private void OnMenuItemClickHandler (object sender, MenuEventArgs e)
{
OnMenuItemClick = true;
}
private void OnPreRenderHandler (object sender, EventArgs e)
{
OnPreRender = true;
}
private void ResetEvents ()
{
OnMenuItemClick = false;
OnDataBinding = false;
OnDataBound = false;
OnInit = false;
OnPreRender = false;
}
[Test]
public void Menu_Events ()
{
Page myPage = new Page ();
PokerMenu p = new PokerMenu ();
MenuItem I = new MenuItem ();
p.Items.Add (I);
myPage.Controls.Add(p);
p.Init += new EventHandler(OnInitHandler);
p.DataBinding += new EventHandler (OnDataBindingHandler);
p.DataBound += new EventHandler(OnDataDataBoundHandler);
p.MenuItemClick += new MenuEventHandler(OnMenuItemClickHandler);
p.MenuItemDataBound += new MenuEventHandler (OnMenuItemDataBoundHandler);
Assert.AreEqual (false, OnDataBinding, "BeforeOnDataBinding");
p.DoOnDataBind (new EventArgs ());
Assert.AreEqual (true, OnDataBinding, "AfterOnDataBinding");
Assert.AreEqual (false, OnDataBound, "BeforeOnDataBound");
p.DoOnDataBound (new EventArgs ());
Assert.AreEqual (true, OnDataBound, "AfterOnDataBinding");
MenuEventArgs e = new MenuEventArgs (I);
Assert.AreEqual (false, OnMenuItemClick, "BeforeMenuItemClick");
p.DoOnMenuItemClick (e);
Assert.AreEqual (true, OnMenuItemClick, "AfterMenuItemClick");
Assert.AreEqual (false, OnInit, "BeforeOnInit");
p.DoOnInit (new EventArgs());
Assert.AreEqual (true, OnInit, "AfterOnInit");
Assert.AreEqual (false, OnMenuItemDataBound, "BeforeMenuItemDataBound");
p.DoMenuItemDataBound(e);
Assert.AreEqual (true, OnMenuItemDataBound, "AfterMenuItemDataBound");
}
[Test]
public void Menu_BubbleEvent () {
PokerMenu pm = new PokerMenu ();
MenuItem item = new MenuItem ("Root");
pm.Items.Add (item);
pm.MenuItemClick += new MenuEventHandler (pm_MenuItemClick);
_MenuItemClick = false;
MenuEventArgs clickCommandArg = new MenuEventArgs (item, null, new CommandEventArgs (Menu.MenuItemClickCommandName, null));
CommandEventArgs notClickCommandArg = new CommandEventArgs (Menu.MenuItemClickCommandName + "No", null);
Assert.AreEqual (true, pm.DoOnBubbleEvent (notClickCommandArg), "Bubble Event#1");
Assert.AreEqual (false, _MenuItemClick, "MenuItemClick Bubbled");
Assert.AreEqual (true, pm.DoOnBubbleEvent (clickCommandArg), "Bubble Event#2");
Assert.AreEqual (true, _MenuItemClick, "MenuItemClick Bubbled");
Assert.AreEqual (false, pm.DoOnBubbleEvent (new EventArgs ()), "Bubble Event#3");
}
bool _MenuItemClick;
void pm_MenuItemClick (object sender, MenuEventArgs e) {
_MenuItemClick = true;
}
[Test]
[Category ("NunitWeb")]
public void Menu_PreRenderEvent ()
{
new WebTest (PageInvoker.CreateOnLoad (PreRenderEvent)).Run ();
}
public void PreRenderEvent (Page p)
{
PokerMenu pm = new PokerMenu ();
p.Controls.Add (pm);
pm.PreRender += new EventHandler (OnPreRenderHandler);
Assert.AreEqual (false, OnPreRender, "BeforePreRender");
pm.DoOnPreRender (new EventArgs ());
Assert.AreEqual (true, OnPreRender, "AfterPreRender");
}
[TestFixtureTearDown]
public void TearDown ()
{
WebTest.Unload ();
}
// A simple Template class to wrap an image.
public class ImageTemplate : ITemplate
{
private MyWebControl.Image myImage;
public MyWebControl.Image MyImage
{
get
{
return myImage;
}
set
{
myImage = value;
}
}
public void InstantiateIn (Control container)
{
container.Controls.Add (MyImage);
}
}
[Test]
[Category ("NunitWeb")]
#if !DOT_NET
[Ignore ("Temporarily ignored on Mono until the Menu control is updated for 4.0")]
#endif
public void MenuClass ()
{
string res = new WebTest ("menuclass.aspx").Run ();
string menua_pattern="
]*class=\"[^\"]*menua[^\"]*\"[^>]*>";
Assert.IsTrue (Regex.IsMatch (res, ".*"+menua_pattern+".*",
RegexOptions.IgnoreCase|RegexOptions.Singleline),
"check that