Map

Namespace: SMBLibrary
We found 10 examples in language CSharp for this search. You will see 44 fragments of code.
//
// Tests for System.Web.UI.WebControls.ImageMap.cs
//
// Author:
//  Hagit Yidov ([email protected]
//
// (C) 2005 Mainsoft Corporation (http://www.mainsoft.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.
//

#if NET_2_0
using NUnit.Framework;
using System;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonoTests.stand_alone.WebHarness;
using MonoTests.SystemWeb.Framework;
using System.Threading;

namespace MonoTests.System.Web.UI.WebControls
{
	class PokerImageMap : ImageMap
	{
		// View state Stuff
		public PokerImageMap ()
		{
			TrackViewState ();
		}

		public object SaveState ()
		{
			return SaveViewState ();
		}

		public void LoadState (object o)
		{
			LoadViewState (o);
		}

		public StateBag StateBag
		{
			get { return base.ViewState; }
		}

		public void DoOnClick (ImageMapEventArgs e)
		{
			base.OnClick (e);
		}

		public void DoOnBubbleEven (Object source, ImageMapEventArgs e)
		{
			base.OnBubbleEvent (source, e);
		}

		// Render Method
		public string Render ()
		{
			StringWriter sw = new StringWriter ();
			HtmlTextWriter tw = new HtmlTextWriter (sw);

			Render (tw);
			return sw.ToString ();
		}
	}

	[TestFixture]
	public class ImageMapTest
	{
		[TestFixtureSetUp]
		public void SetUp ()
		{
			WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
		}



		[Test]
		public void ImageMap_DefaultProperties ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			Assert.AreEqual (0, imageMap.StateBag.Count, "ViewState.Count");
			Assert.AreEqual (true, imageMap.Enabled, "Enabled");
			Assert.AreEqual (HotSpotMode.NotSet, imageMap.HotSpotMode, "HotSpotMode");
			Assert.AreEqual (0, imageMap.HotSpots.Count, "HotSpots.Count");
			Assert.AreEqual (string.Empty, imageMap.Target, "Target");
		}

		[Test]
		public void ImageMap_AssignToDefaultProperties ()
		{
			PokerImageMap imageMap = new PokerImageMap ();

			Assert.AreEqual (0, imageMap.StateBag.Count, "ViewState.Count");

			imageMap.Enabled = true;
			Assert.AreEqual (true, imageMap.Enabled, "Enabled");
			Assert.AreEqual (0, imageMap.StateBag.Count, "ViewState.Count-1");

			imageMap.HotSpotMode = HotSpotMode.Navigate;
			Assert.AreEqual (HotSpotMode.Navigate, imageMap.HotSpotMode, "HotSpotMode");
			Assert.AreEqual (1, imageMap.StateBag.Count, "ViewState.Count-2");

			imageMap.HotSpots.Add (new CircleHotSpot ());
			Assert.AreEqual (1, imageMap.HotSpots.Count, "HotSpots.Count");
			Assert.AreEqual (1, imageMap.StateBag.Count, "ViewState.Count-3");

			imageMap.Target = "Target";
			Assert.AreEqual ("Target", imageMap.Target, "Target");
			Assert.AreEqual (2, imageMap.StateBag.Count, "ViewState.Count-4");
		}

		[Test]
		public void ImageMap_Defaults_Render ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
#if NET_4_0
			string originalHtml = "<img src=\"\" />";
#else
			string originalHtml = "<img src=\"\" style=\"border-width:0px;\" />";
#endif
			string renderedHtml = imageMap.Render ();
			HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderDefault");
		}

		[Test]
		public void ImageMap_AssignedValues_RenderNavigate ()
		{
			// HotSpotMode = Navigate using NavigateURL
			//-----------------------------------------
			PokerImageMap imageMap = new PokerImageMap ();
			imageMap.Enabled = true;
			imageMap.HotSpotMode = HotSpotMode.Navigate;
			imageMap.Target = "Target";
			CircleHotSpot circle = new CircleHotSpot ();
			circle.NavigateUrl = "NavigateURL";
			imageMap.HotSpots.Add (circle);
#if NET_4_0
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" href=\"NavigateURL\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
#else
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" href=\"NavigateURL\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
#endif
			string renderedHtml = imageMap.Render ();
			HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderNavigateTextAssigned");
		}

		[Test]
		public void ImageMap_AssignedValues_RenderNavigateCircle ()
		{
			// Circle.HotSpotMode = Navigate
			//------------------------------
			PokerImageMap imageMap = new PokerImageMap ();
			imageMap.Enabled = true;
			CircleHotSpot circle = new CircleHotSpot ();
			circle.AccessKey = "A";
			circle.AlternateText = "Circle";
			circle.HotSpotMode = HotSpotMode.Navigate;
			circle.NavigateUrl = "NavigateURL";
			circle.TabIndex = 1;
			circle.Radius = 10;
			circle.X = 30;
			circle.Y = 40;
			imageMap.HotSpots.Add (circle);
#if NET_4_0
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"30,40,10\" href=\"NavigateURL\" title=\"Circle\" alt=\"Circle\" accesskey=\"A\" tabindex=\"1\" />\r\n</map>";
#else
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"30,40,10\" href=\"NavigateURL\" title=\"Circle\" alt=\"Circle\" accesskey=\"A\" tabindex=\"1\" />\r\n</map>";
#endif
			string renderedHtml = imageMap.Render ();
			HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderNavigateCircleTextAssigned");
		}

		[Test]
		public void ImageMap_AssignedValues_RenderNavigateShapes ()
		{
			// Rectangle/Polygon.HotSpotMode = Navigate 
			//-----------------------------------------
			PokerImageMap imageMap = new PokerImageMap ();
			imageMap.Enabled = true;
			imageMap.HotSpotMode = HotSpotMode.NotSet;
			RectangleHotSpot rect = new RectangleHotSpot ();
			rect.AccessKey = "R";
			rect.AlternateText = "Rectangle";
			rect.HotSpotMode = HotSpotMode.Navigate;
			rect.NavigateUrl = "NavigateUrlRect";
			rect.TabIndex = 1;
			rect.Bottom = 10;
			rect.Top = 20;
			rect.Left = 30;
			rect.Right = 40;
			imageMap.HotSpots.Add (rect);
			imageMap.HotSpotMode = HotSpotMode.Navigate;
			PolygonHotSpot poly = new PolygonHotSpot ();
			poly.AccessKey = "P";
			poly.AlternateText = "Polygon";
			poly.NavigateUrl = "NavigateUrlPoly";
			poly.TabIndex = 2;
			poly.Coordinates = "10,20,30,40,50,60,100,200";
			imageMap.HotSpots.Add (poly);
#if NET_4_0
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"rect\" coords=\"30,20,40,10\" href=\"NavigateUrlRect\" title=\"Rectangle\" alt=\"Rectangle\" accesskey=\"R\" tabindex=\"1\" /><area shape=\"poly\" coords=\"10,20,30,40,50,60,100,200\" href=\"NavigateUrlPoly\" title=\"Polygon\" alt=\"Polygon\" accesskey=\"P\" tabindex=\"2\" />\r\n</map>";
#else
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"rect\" coords=\"30,20,40,10\" href=\"NavigateUrlRect\" title=\"Rectangle\" alt=\"Rectangle\" accesskey=\"R\" tabindex=\"1\" /><area shape=\"poly\" coords=\"10,20,30,40,50,60,100,200\" href=\"NavigateUrlPoly\" title=\"Polygon\" alt=\"Polygon\" accesskey=\"P\" tabindex=\"2\" />\r\n</map>";
#endif
			string renderedHtml = imageMap.Render ();
			HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderNavigateShapesTextAssigned");
		}

		[Test]
		public void ImageMap_AssignedValues_RenderInactive ()
		{
			// HotSpotMode = Inactive
			//-----------------------
			PokerImageMap imageMap = new PokerImageMap ();
			imageMap.Enabled = true;
			imageMap.HotSpotMode = HotSpotMode.Inactive;
			imageMap.Target = "Target";
			imageMap.HotSpots.Add (new CircleHotSpot ());
#if NET_4_0
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" nohref=\"true\" title=\"\" alt=\"\" />\r\n</map>";
#else
			string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" nohref=\"true\" title=\"\" alt=\"\" />\r\n</map>";
#endif
			string renderedHtml = imageMap.Render ();
			HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderInaciveTextAssigned");
		}

		[Test]
		public void ImageMap_AssignedValues_RenderDisabled ()
		{
			// Enabled = false
			//----------------
			PokerImageMap imageMap = new PokerImageMap ();
			imageMap.Enabled = false;
			imageMap.HotSpotMode = HotSpotMode.Navigate;
			imageMap.Target = "Target";
			CircleHotSpot circle = new CircleHotSpot ();
			circle.NavigateUrl = "NavigateURL";
			imageMap.HotSpots.Add (circle);
#if NET_4_0
			string originalHtml = "<img class=\"aspNetDisabled\" src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
#else
			string originalHtml = "<img disabled=\"disabled\" src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" href=\"NavigateURL\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
#endif
			string renderedHtml = imageMap.Render ();
			HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderDisabledTextAssigne");
		}

		[Test]
		public void ImageMap_ViewState ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			imageMap.Enabled = true;
			Assert.AreEqual (true, imageMap.Enabled, "Enabled-beforecopy");
			imageMap.HotSpotMode = HotSpotMode.Navigate;
			Assert.AreEqual (HotSpotMode.Navigate, imageMap.HotSpotMode, "HotSpotMode-beforecopy");
			imageMap.HotSpots.Add (new CircleHotSpot ());
			Assert.AreEqual (1, imageMap.HotSpots.Count, "HotSpots.Count-beforecopy");
			imageMap.Target = "Target";
			Assert.AreEqual ("Target", imageMap.Target, "Target-beforecopy");
			object state = imageMap.SaveState ();
			PokerImageMap copy = new PokerImageMap ();
			copy.LoadState (state);
			Assert.AreEqual (true, copy.Enabled, "Enabled-aftercopy");
			Assert.AreEqual (HotSpotMode.Navigate, copy.HotSpotMode, "HotSpotMode-aftercopy");
			//Assert.AreEqual(1, copy.HotSpots.Count, "HotSpots.Count-aftercopy");
			Assert.AreEqual ("Target", copy.Target, "Target-aftercopy");
		}

		// Events Stuff
		private bool clicked = false;
		private string pbValue;

		private void ImageMapClickHandler (object sender, ImageMapEventArgs e)
		{
			clicked = true;
			pbValue = e.PostBackValue;
		}

		private void ResetEvents ()
		{
			clicked = false;
			pbValue = "Init";
		}

		[Test]
		public void ImageMap_Event ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			ResetEvents ();
			imageMap.HotSpotMode = HotSpotMode.PostBack;
			imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
			Assert.AreEqual (false, clicked, "BeforeClick");
			imageMap.DoOnClick (new ImageMapEventArgs ("HotSpotName"));
			Assert.AreEqual (true, clicked, "AfterClick");
		}

		[Test]
		public void ImageMap_EventCircle ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			ResetEvents ();
			imageMap.HotSpotMode = HotSpotMode.NotSet;
			CircleHotSpot circle = new CircleHotSpot ();
			circle.HotSpotMode = HotSpotMode.PostBack;
			circle.PostBackValue = "myCircle";
			imageMap.HotSpots.Add (circle);
			imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
			Assert.AreEqual ("Init", pbValue, "BeforeClick");
			imageMap.DoOnClick (new ImageMapEventArgs (circle.PostBackValue));
			Assert.AreEqual ("myCircle", pbValue, "AfterClick");
		}

		[Test]
		public void ImageMap_EventRectangle ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			ResetEvents ();
			imageMap.HotSpotMode = HotSpotMode.PostBack;
			RectangleHotSpot rect = new RectangleHotSpot ();
			rect.PostBackValue = "myRect";
			imageMap.HotSpots.Add (rect);
			imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
			Assert.AreEqual ("Init", pbValue, "BeforeClick");
			imageMap.DoOnClick (new ImageMapEventArgs (rect.PostBackValue));
			Assert.AreEqual ("myRect", pbValue, "AfterClick");
		}

		[Test]
		public void ImageMap_EventPolygon ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			ResetEvents ();
			imageMap.HotSpotMode = HotSpotMode.NotSet;
			PolygonHotSpot poly = new PolygonHotSpot ();
			poly.HotSpotMode = HotSpotMode.PostBack;
			poly.PostBackValue = "myPoly";
			imageMap.HotSpots.Add (poly);
			imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
			Assert.AreEqual ("Init", pbValue, "BeforeClick");
			imageMap.DoOnClick (new ImageMapEventArgs (poly.PostBackValue));
			Assert.AreEqual ("myPoly", pbValue, "AfterClick");
		}

		public void ImageMap_BubbleEvent ()
		{
			PokerImageMap imageMap = new PokerImageMap ();
			ResetEvents ();
			ImageMapEventArgs args = new ImageMapEventArgs ("HotSpotName");
			imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
			Assert.AreEqual (false, clicked, "BeforeClick");
			imageMap.DoOnBubbleEven (imageMap, args);
			Assert.AreEqual (true, clicked, "AfterClick");
		}

		private static void ImageMapClickHandler2 (object sender, ImageMapEventArgs e)
		{
			WebTest.CurrentTest.UserData = e.PostBackValue;
		}

		[Test]
		[Category ("NunitWeb")]
		public void ImageMap_PostBackRectangle ()
		{
			WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
			t.Run ();
			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("__EVENTTARGET");
			fr.Controls.Add ("__EVENTARGUMENT");
			fr.Controls["__EVENTTARGET"].Value = "imgmap";
			fr.Controls["__EVENTARGUMENT"].Value = "0";
			t.Request = fr;
			t.Run ();
			Assert.AreEqual ("Rectangle", t.UserData, "AfterPostBack");
		}

		[Test]
		[Category ("NunitWeb")]
		public void ImageMap_PostBackFireEvent ()
		{
			WebTest t = new WebTest ("NoEventValidation.aspx");
			t.Invoker = PageInvoker.CreateOnLoad (PostBackFireEvent_Init);
			t.Run ();
			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("__EVENTTARGET");
			fr.Controls.Add ("__EVENTARGUMENT");
			fr.Controls["__EVENTTARGET"].Value = "imgmap";
			fr.Controls["__EVENTARGUMENT"].Value = "0";
			t.Request = fr;
			t.Run ();
			if (t.UserData == null)
				Assert.Fail ("Event not fired fail");
			Assert.AreEqual ("ImageMapClickHandler", t.UserData.ToString (), "PostBackFireEvent");
		}

		#region PostBackFireEvent
		public static void PostBackFireEvent_Init (Page p)
		{
			ImageMap imgmap = new ImageMap ();
			imgmap.ID = "imgmap";
			imgmap.HotSpotMode = HotSpotMode.NotSet;
			imgmap.Click += new ImageMapEventHandler (ImageMapClickHandler3);
			RectangleHotSpot rect = new RectangleHotSpot ();
			rect.HotSpotMode = HotSpotMode.PostBack;
			rect.PostBackValue = "Rectangle";
			imgmap.HotSpots.Add (rect);
			p.Form.Controls.Add (imgmap);
		}

		public static void ImageMapClickHandler3 (object sender, ImageMapEventArgs e)
		{
			WebTest.CurrentTest.UserData = "ImageMapClickHandler";
		}
		#endregion

		[Test]
		[Category ("NunitWeb")]
		public void ImageMap_PostBackCircle ()
		{
			WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
			t.Run ();
			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("__EVENTTARGET");
			fr.Controls.Add ("__EVENTARGUMENT");
			fr.Controls["__EVENTTARGET"].Value = "imgmap";
			fr.Controls["__EVENTARGUMENT"].Value = "2";
			t.Request = fr;
			t.Run ();
			Assert.AreEqual ("Circle", t.UserData, "AfterPostBack");
		}

		[Test]
		[Category ("NunitWeb")]
		public void ImageMap_PostBackPolygon ()
		{
			WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
			t.Run ();
			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("__EVENTTARGET");
			fr.Controls.Add ("__EVENTARGUMENT");
			fr.Controls["__EVENTTARGET"].Value = "imgmap";
			fr.Controls["__EVENTARGUMENT"].Value = "1";
			t.Request = fr;
			t.Run ();
			Assert.AreEqual ("Polygon", t.UserData, "AfterPostBack");
		}

		[Test]
		[Category ("NunitWeb")]
		public void ImageMap_PostBack_RenderBefore ()
		{
			WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
			#region orig
#if NET_4_0
			string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;0&#39;)\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;1&#39;)\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;2&#39;)\" title=\"\" alt=\"\" />\r\n</map>";
#else
			string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" style=\"border-width:0px;\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack('imgmap','0')\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack('imgmap','1')\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack('imgmap','2')\" title=\"\" alt=\"\" />\r\n</map>";
#endif
			#endregion
			string RenderedPageHtml = t.Run ();
			string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
			HtmlDiff.AssertAreEqual (strTarget, RenderedControlHtml, "BeforePostBack");
		}

		[Test]
		[Category ("NunitWeb")]
		public void ImageMap_PostBack_RenderAfter ()
		{
			WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
			t.Run ();
			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("__EVENTTARGET");
			fr.Controls.Add ("__EVENTARGUMENT");
			fr.Controls["__EVENTTARGET"].Value = "imgmap";
			fr.Controls["__EVENTARGUMENT"].Value = "0";
			t.Request = fr;
			#region orig
#if NET_4_0
			string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;0&#39;)\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;1&#39;)\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;2&#39;)\" title=\"\" alt=\"\" />\r\n</map>";
#else
			string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" style=\"border-width:0px;\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack('imgmap','0')\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack('imgmap','1')\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack('imgmap','2')\" title=\"\" alt=\"\" />\r\n</map>";
#endif
			#endregion
			string RenderedPageHtml = t.Run ();
			string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
			HtmlDiff.AssertAreEqual (strTarget, RenderedControlHtml, "AfterPostBack");
		}

		public static void myPageLoad (Page page)
		{
			WebTest.CurrentTest.UserData = "Init";
			ImageMap imgmap = new ImageMap ();
			imgmap.ID = "imgmap";
			imgmap.HotSpotMode = HotSpotMode.NotSet;
			imgmap.Click += new ImageMapEventHandler (ImageMapClickHandler2);
			RectangleHotSpot rect = new RectangleHotSpot ();
			rect.HotSpotMode = HotSpotMode.PostBack;
			rect.PostBackValue = "Rectangle";
			imgmap.HotSpots.Add (rect);
			PolygonHotSpot poly = new PolygonHotSpot ();
			poly.HotSpotMode = HotSpotMode.PostBack;
			poly.PostBackValue = "Polygon";
			imgmap.HotSpots.Add (poly);
			imgmap.HotSpotMode = HotSpotMode.PostBack;
			CircleHotSpot circle = new CircleHotSpot ();
			circle.PostBackValue = "Circle";
			imgmap.HotSpots.Add (circle);
			// Two marks for getting controls from form
			LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
			LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
			page.Form.Controls.Add (lcb);
			page.Form.Controls.Add (imgmap);
			page.Form.Controls.Add (lce);
		}

		[SetUp]
		public void SetUpTest ()
		{
			Thread.Sleep (100);
		}

		[TestFixtureTearDown]
		public void TearDown ()
		{
			WebTest.Unload ();
		}
	}
}


#endif

        [Test]
        public void Clone_ClonesMessages()
        {
            var message = new ForeignMessage { C = 20 };
            var map = new MapField<string, ForeignMessage> { { "x", message } };
            var clone = map.Clone();
            map["x"].C = 30;
            Assert.AreEqual(20, clone["x"].C);
        }

        private void TestNullValues<T>(T nonNullValue)
        {
            var map = new MapField<int, T>();
            var nullValue = (T) (object) null;
            Assert.Throws<ArgumentNullException>(() => map.Add(0, nullValue));
            Assert.Throws<ArgumentNullException>(() => map[0] = nullValue);
            map.Add(1, nonNullValue);
            map[1] = nonNullValue;
        }

        [Test]
        public void Add_ForbidsNullKeys()
        {
            var map = new MapField<string, ForeignMessage>();
            Assert.Throws<ArgumentNullException>(() => map.Add(null, new ForeignMessage()));
        }

        [Test]
        public void Indexer_ForbidsNullKeys()
        {
            var map = new MapField<string, ForeignMessage>();
            Assert.Throws<ArgumentNullException>(() => map[null] = new ForeignMessage());
        }
        
        [Test]
        public void AddPreservesInsertionOrder()
        {
            var map = new MapField<string, string>();
            map.Add("a", "v1");
            map.Add("b", "v2");
            map.Add("c", "v3");
            map.Remove("b");
            map.Add("d", "v4");
            CollectionAssert.AreEqual(new[] { "a", "c", "d" }, map.Keys);
            CollectionAssert.AreEqual(new[] { "v1", "v3", "v4" }, map.Values);
        }

        [Test]
        public void Equality_Simple()
        {
            var map = new MapField<string, string>();
            EqualityTester.AssertEquality(map, map);
            EqualityTester.AssertInequality(map, null);
            Assert.IsFalse(map.Equals(new object()));
        }

        [Test]
        public void Clone_ClonesMessages()
        {
            var message = new ForeignMessage { C = 20 };
            var map = new MapField<string, ForeignMessage> { { "x", message } };
            var clone = map.Clone();
            map["x"].C = 30;
            Assert.AreEqual(20, clone["x"].C);
        }

        private void TestNullValues<T>(T nonNullValue)
        {
            var map = new MapField<int, T>();
            var nullValue = (T) (object) null;
            Assert.Throws<ArgumentNullException>(() => map.Add(0, nullValue));
            Assert.Throws<ArgumentNullException>(() => map[0] = nullValue);
            map.Add(1, nonNullValue);
            map[1] = nonNullValue;
        }

        [Test]
        public void Add_ForbidsNullKeys()
        {
            var map = new MapField<string, ForeignMessage>();
            Assert.Throws<ArgumentNullException>(() => map.Add(null, new ForeignMessage()));
        }

        [Test]
        public void Indexer_ForbidsNullKeys()
        {
            var map = new MapField<string, ForeignMessage>();
            Assert.Throws<ArgumentNullException>(() => map[null] = new ForeignMessage());
        }
        
        [Test]
        public void AddPreservesInsertionOrder()
        {
            var map = new MapField<string, string>();
            map.Add("a", "v1");
            map.Add("b", "v2");
            map.Add("c", "v3");
            map.Remove("b");
            map.Add("d", "v4");
            CollectionAssert.AreEqual(new[] { "a", "c", "d" }, map.Keys);
            CollectionAssert.AreEqual(new[] { "v1", "v3", "v4" }, map.Values);
        }

        [Test]
        public void Equality_Simple()
        {
            var map = new MapField<string, string>();
            EqualityTester.AssertEquality(map, map);
            EqualityTester.AssertInequality(map, null);
            Assert.IsFalse(map.Equals(new object()));
        }

//
// System.Web.SiteMapProviderTest.cs - Unit tests for System.Web.SiteMapProvider
//
// Author:
//	Marek Habersack <[email protected]>
//
// Copyright (C) 2009 Novell, Inc (http://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.
//

#if NET_2_0

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Configuration.Provider;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Hosting;
using NUnit.Framework;

using MonoTests.stand_alone.WebHarness;
using MonoTests.SystemWeb.Framework;

using Tests;

namespace MonoTests.System.Web
{
	[TestFixture]
	public class XmlSiteMapProviderTest
	{

		[TestFixtureSetUp]
		public void SetUp ()
		{
			Type myType = GetType ();
			WebTest.CopyResource (myType, "test_map_01.sitemap", "test_map_01.sitemap");
			WebTest.CopyResource (myType, "test_map_02.sitemap", "test_map_02.sitemap");
			WebTest.CopyResource (myType, "test_map_03.sitemap", "test_map_03.sitemap");
			WebTest.CopyResource (myType, "test_map_04.sitemap", "test_map_04.sitemap");
			WebTest.CopyResource (myType, "test_map_05.sitemap", "test_map_05.sitemap");
			WebTest.CopyResource (myType, "test_map_06.sitemap", "test_map_06.sitemap");
			WebTest.CopyResource (myType, "test_map_07.sitemap", "test_map_07.sitemap");
			WebTest.CopyResource (myType, "test_map_08.sitemap", "test_map_08.sitemap");
			WebTest.CopyResource (myType, "test_map_09.sitemap", "test_map_09.sitemap");
			WebTest.CopyResource (myType, "sub_map_01.sitemap", "sub_map_01.sitemap");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void AddNode_Null_1 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var node = new SiteMapNode (provider, "/test.aspx");

			provider.DoAddNode (null, node);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void AddNode_Null_2 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var node = new SiteMapNode (provider, "/test.aspx");

			provider.DoAddNode (node, null);
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void AddNode_DifferentProviders_01 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var node = new SiteMapNode (new TestSiteMapProvider (), "/test.aspx");
			var parentNode = new SiteMapNode (provider, "/test2.aspx");

			// SiteMapNode  cannot be found in current provider, only nodes in the same provider can be added.
			provider.DoAddNode (node, parentNode);
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void AddNode_DifferentProviders_02 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var node = new SiteMapNode (provider, "/test.aspx");
			var parentNode = new SiteMapNode (new TestSiteMapProvider (), "/test2.aspx");

			// SiteMapNode  cannot be found in current provider, only nodes in the same provider can be added.
			provider.DoAddNode (node, parentNode);
		}

		[Test]
		[ExpectedException (typeof (HttpException))]
		public void AddNode_01 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var node = new SiteMapNode (provider, "/test.aspx");
			var parentNode = new SiteMapNode (provider, "/test2.aspx");

			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/test_map_01.sitemap");
			provider.Initialize ("TestMap", nvc);

			// The application relative virtual path '~/test_map_01.sitemap' cannot be made absolute, because the path to the application is not known.
			provider.DoAddNode (node, parentNode);
		}

		[Test]
		public void AddNode_02 ()
		{
			new WebTest (PageInvoker.CreateOnLoad (AddNode_02_OnLoad)).Run ();
		}

		public static void AddNode_02_OnLoad (Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			provider.CallTrace = null;
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/test_map_01.sitemap");
			provider.Initialize ("TestMap", nvc);

			SiteMapNode rootNode = provider.RootNode;
			provider.CallTrace = null;

			var node = new SiteMapNode (provider, "test3.aspx", "~/test3.aspx");
			provider.DoAddNode (node, rootNode);

			Assert.IsNotNull (provider.CallTrace, "#A1");
			Assert.Greater (provider.CallTrace.Length, 1, "#A1-1");
			Assert.AreEqual (provider.CallTrace[0].Name, "BuildSiteMap", "#A1-2");
		}

		[Test]
		public void Initialize_1 ()
		{
			var provider = new XmlSiteMapProviderPoker ();

			provider.Initialize ("TestMap", null);
			Assert.AreEqual ("TestMap", provider.Name, "#A1");
		}

		[Test]
		public void Initialize_2 ()
		{
			var provider = new XmlSiteMapProviderPoker ();

			provider.Initialize ("TestMap", new NameValueCollection ());
			Assert.AreEqual ("TestMap", provider.Name, "#A1");
		}

		[Test]
		public void Initialize_3 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "test.sitemap");
			provider.Initialize ("TestMap", nvc);
			Assert.AreEqual ("TestMap", provider.Name, "#A1");
		}

		[Test]
		public void Initialize_4 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "test.sitemap");
			nvc.Add ("description", "Test XML provider");
			provider.Initialize ("TestMap", nvc);
			Assert.AreEqual ("TestMap", provider.Name, "#A1");
			Assert.AreEqual ("Test XML provider", provider.Description, "#A2");
		}

		[Test]
		[ExpectedException (typeof (ConfigurationErrorsException))]
		public void Initialize_5 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "test.sitemap");
			nvc.Add ("description", "Test XML provider");

			// The attribute 'acme' is unexpected in the configuration of the 'TestMap' provider.
			nvc.Add ("acme", "test provider");
			provider.Initialize ("TestMap", nvc);
		}

		[Test]
		[ExpectedException (typeof (InvalidOperationException))]
		public void Initialize_6 ()
		{
			var provider = new XmlSiteMapProviderPoker ();

			provider.Initialize ("TestMap", null);

			// XmlSiteMapProvider cannot be initialized twice
			provider.Initialize ("TestMap2", null);
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void RootNode_1 ()
		{
			var provider = new XmlSiteMapProviderPoker ();

			// Thrown from internal GetConfigDocument ():
			// The siteMapFile attribute must be specified on the XmlSiteMapProvider
			provider.Initialize ("TestMap", null);
			var rn = provider.RootNode;
		}

		[Test]
		public void RootNode_2 ()
		{
			new WebTest (PageInvoker.CreateOnLoad (RootNode_2_OnLoad)).Run ();
		}

		public static void RootNode_2_OnLoad (Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			provider.CallTrace = null;
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/test_map_01.sitemap");
			provider.CallTrace = null;
			provider.Initialize ("TestMap", nvc);
			Assert.IsNotNull (provider.RootNode, "#A1");
			Assert.AreEqual (provider.RootNode.Provider, provider, "#A2");
			Assert.IsNotNull (provider.CallTrace, "#A3");
			Assert.Greater (provider.CallTrace.Length, 1, "#A3-1");
			Assert.AreEqual ("BuildSiteMap", provider.CallTrace[0].Name, "#A3-2");
			Assert.AreEqual ("get_RootNode", provider.CallTrace[1].Name, "#A3-3");
		}

		[Test]
		[ExpectedException (typeof (InvalidOperationException))]
		public void InvalidFileExtension ()
		{
			// The file /NunitWeb/test_map_01.extension has an invalid extension, only .sitemap files are allowed in XmlSiteMapProvider.
			new WebTest (PageInvoker.CreateOnLoad (InvalidFileExtension_OnLoad)).Run ();
		}

		public static void InvalidFileExtension_OnLoad (Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/test_map_01.extension");

			provider.Initialize ("TestMap", nvc);
			var rn = provider.RootNode;
		}

		[Test]
		[ExpectedException (typeof (InvalidOperationException))]
		public void MissingMapFile ()
		{
			new WebTest (PageInvoker.CreateOnLoad (MissingMapFile_OnLoad)).Run ();
		}

		public static void MissingMapFile_OnLoad (Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/missing_map_file.sitemap");

			provider.Initialize ("TestMap", nvc);
			var rn = provider.RootNode;
		}

		[Test]
		public void NodeWithSiteMapFile_01 ()
		{
			var test = new WebTest (PageInvoker.CreateOnLoad (NodeWithSiteMapFile_01_OnLoad)).Run ();
		}

		public static void NodeWithSiteMapFile_01_OnLoad (Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/test_map_02.sitemap");

			provider.Initialize ("TestMap", nvc);
			var rn = provider.RootNode;

			string expectedTreeString = "UNTITLED_0[0]; Test 1[1]; Sub 1 [/NunitWeb/sub_map_01.sitemap][1]; Sub Sub 1 [/NunitWeb/sub_map_01.sitemap][2]";
			string treeString = provider.GetTreeString ();

			Assert.AreEqual (expectedTreeString, treeString, "#A1");
		}

		[Test]
		public void NodeWithProvider_01 ()
		{
			var test = new WebTest (PageInvoker.CreateOnLoad ((Page p) => {
				NodeWithProvider_OnLoad ("~/test_map_07.sitemap", p);
			})).Run ();
		}

		[Test]
		[ExpectedException (typeof (ProviderException))]
		public void NodeWithProvider_02 ()
		{
			new WebTest (PageInvoker.CreateOnLoad ((Page p) => {
				NodeWithProvider_OnLoad ("~/test_map_08.sitemap", p);
			})).Run ();
		}

		public static void NodeWithProvider_OnLoad (string filePath, Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", filePath);

			provider.Initialize ("TestMap", nvc);
			var rn = provider.RootNode;

			string expectedTreeString = "UNTITLED_0[0]; Test 1[1]; Test [TestSiteMapProvider][1]";
			string treeString = provider.GetTreeString ();
			Assert.AreEqual (expectedTreeString, treeString, "#A1");

			SiteMapNode node = provider.FindSiteMapNode ("default.aspx");
			Assert.IsNotNull (node, "#B1");
			Assert.AreEqual ("Test", node.Title, "#B1-1");
		}

		[Test]
		[ExpectedException (typeof (ConfigurationErrorsException))]
		public void InvalidMapFile_01 ()
		{
			// Top element must be siteMap.
			new WebTest (PageInvoker.CreateOnLoad ((Page p) => {
				InvalidMapFile_OnLoad ("~/test_map_03.sitemap", p);
			})).Run ();
		}

		[Test]
		[ExpectedException (typeof (ConfigurationErrorsException))]
		public void InvalidMapFile_02 ()
		{
			// Only <siteMapNode> elements are allowed at this location.
			var test = new WebTest (PageInvoker.CreateOnLoad ((Page p) => {
				InvalidMapFile_OnLoad ("~/test_map_04.sitemap", p);
			})).Run ();
		}

		[Test]
		[ExpectedException (typeof (ConfigurationErrorsException))]
		public void InvalidMapFile_03 ()
		{
			// Only <siteMapNode> elements are allowed at this location.
			var test = new WebTest (PageInvoker.CreateOnLoad ((Page p) => {
				InvalidMapFile_OnLoad ("~/test_map_05.sitemap", p);
			})).Run ();
		}

		[Test]
		[ExpectedException (typeof (ConfigurationErrorsException))]
		public void InvalidMapFile_04 ()
		{
			// Only <siteMapNode> elements are allowed at this location.
			var test = new WebTest (PageInvoker.CreateOnLoad ((Page p) => {
				InvalidMapFile_OnLoad ("~/test_map_06.sitemap", p);
			})).Run ();
		}

		public static void InvalidMapFile_OnLoad (string filePath, Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", filePath);

			provider.Initialize ("TestMap", nvc);
			var rn = provider.RootNode;
		}

		[Test]
		public void MapFileWithNonStandardAttributes ()
		{
			// Only <siteMapNode> elements are allowed at this location.
			new WebTest (PageInvoker.CreateOnLoad (MapFileWithNonStandardAttributes_OnLoad)).Run ();
		}

		public static void MapFileWithNonStandardAttributes_OnLoad (Page p)
		{
			var provider = new XmlSiteMapProviderPoker ();
			var nvc = new NameValueCollection ();
			nvc.Add ("siteMapFile", "~/test_map_09.sitemap");

			provider.Initialize ("TestMap", nvc);
			var rn = provider.RootNode;

			//TODO: find out what happens to non-standard attributes
			//SiteMapNode node = rn.ChildNodes[0];
			//Assert.IsNotNull (node, "#A1");
			//Assert.AreEqual ("some, keyword, another, one", node["keywords"], "#A1-1");

			//node = rn.ChildNodes[1];
			//Assert.IsNotNull (node, "#B1");
			//Assert.AreEqual("value", node["someattribute"], "#B1-1");
		}
	}

	class XmlSiteMapProviderPoker : XmlSiteMapProvider
	{
		public MethodBase[] CallTrace { get; set; }

		public void DoAddNode (SiteMapNode node, SiteMapNode parentNode)
		{
			AddNode (node, parentNode);
		}

		public override SiteMapNode BuildSiteMap ()
		{
			StoreCallTrace ();
			return base.BuildSiteMap ();
		}

		public string GetTreeString ()
		{
			var sb = new StringBuilder ();
			int untitled_counter = 0;
			BuildTreeString (RootNode, sb, 0, ref untitled_counter);
			return sb.ToString ();
		}

		void BuildTreeString (SiteMapNode top, StringBuilder sb, int level, ref int untitled_counter)
		{
			string title = top.Title;

			if (String.IsNullOrEmpty (title))
				title = "UNTITLED_" + untitled_counter++;

			SiteMapProvider provider = top.Provider;
			if (provider != this) {
				if (provider == null)
					title += " [NULL_PROVIDER]";
				else {
					string name = provider.Name;
					if (String.IsNullOrEmpty (name))
						title += " [" + provider.GetType () + "]";
					else
						title += " [" + name + "]";
				}
			}

			if (sb.Length > 0)
				sb.Append ("; ");
			sb.Append (title + "[" + level + "]");
			SiteMapNodeCollection childNodes = top.ChildNodes;
			if (childNodes != null && childNodes.Count > 0) {
				foreach (SiteMapNode child in childNodes)
					BuildTreeString (child, sb, level + 1, ref untitled_counter);
			}
		}

		void StoreCallTrace ()
		{
			CallTrace = null;
			StackFrame[] frames = new StackTrace (1).GetFrames ();
			var frameMethods = new List<MethodBase> ();

			int i = 0;
			foreach (StackFrame sf in frames)
				frameMethods.Add (sf.GetMethod ());
			CallTrace = frameMethods.ToArray ();
		}
	}
}
#endif

//
// System.Web.SiteMapProviderTest.cs - Unit tests for System.Web.SiteMapProvider
//
// Author:
//	Chris Toshok <[email protected]>
//
// Copyright (C) 2006 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.
//

#if NET_2_0

using System;
using System.Text;
using System.Web;
using System.Collections.Specialized;
using NUnit.Framework;
using System.Diagnostics;

namespace MonoTests.System.Web {
	
	class SiteMapProviderPoker : SiteMapProvider
	{
		public void DoAddNode (SiteMapNode node)
		{
			base.AddNode (node);
		}

		public void DoAddNode (SiteMapNode node, SiteMapNode parentNode)
		{
			base.AddNode (node, parentNode);
		}

		public void DoRemoveNode (SiteMapNode node)
		{
			base.RemoveNode (node);
		}

		public override SiteMapNode FindSiteMapNode (string rawUrl)
		{
			return new SiteMapNode (this, rawUrl, rawUrl);
		}

		public override SiteMapNodeCollection GetChildNodes (SiteMapNode node)
		{
			throw new NotImplementedException ();
		}

		public override SiteMapNode GetParentNode (SiteMapNode node)
		{
			throw new NotImplementedException ();
		}

		protected internal override SiteMapNode GetRootNodeCore ()
		{
			return new SiteMapNode (this, "rootKey", "rootUrl");
		}
	}

	[TestFixture]
	public class SiteMapProviderTest {

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void AddNode_null ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoAddNode (null);
		}

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void AddNode ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoAddNode (new SiteMapNode (poker, "key", "url"));
		}

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void AddNode2_nullNode ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoAddNode (null, new SiteMapNode (poker, "parentKey", "parentUrl"));
		}

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void AddNode2_nullParent ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoAddNode (new SiteMapNode (poker, "childKey", "childUrl"), null);
		}

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void AddNode2 ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoAddNode (new SiteMapNode (poker, "childKey", "childUrl"),
					 new SiteMapNode (poker, "parentKey", "parentUrl"));
		}

		[Test]
		public void FindSiteMapNode_nullContext ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			SiteMapNode n = poker.FindSiteMapNode ((HttpContext)null);
			Assert.IsNull (n, "A1");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void FindSiteMapNodeFromKey_nullKey ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			SiteMapNode n = poker.FindSiteMapNodeFromKey (null);
		}

		[Test]
		public void FindSiteMapNodeFromKey ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			SiteMapNode n = poker.FindSiteMapNodeFromKey ("key");
			Assert.AreEqual ("key", n.Key, "A1");
			Assert.AreEqual ("key", n.Url, "A2");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void GetCurrentNodeAndHintAncestorNodes_negativeUplevel ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			SiteMapNode n = poker.GetCurrentNodeAndHintAncestorNodes (-2);
			Assert.IsNull (n, "A1");
		}

		[Test]
		public void GetCurrentNodeAndHintAncestorNodes_negativeUplevel2 ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			SiteMapNode n = poker.GetCurrentNodeAndHintAncestorNodes (-1);
			Assert.IsNull (n, "A1");
		}

		[Test]
		public void GetCurrentNodeAndHintAncestorNodes ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			SiteMapNode n = poker.GetCurrentNodeAndHintAncestorNodes (5);
			Assert.IsNull (n, "A1");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void HintAncestorNodes_nullNode ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.HintAncestorNodes (null, 0);
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void HintAncestorNodes_negativeUplevel ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.HintAncestorNodes (new SiteMapNode (poker, "key"), -2);
		}

		[Test]
		public void HintAncestorNodes_negativeUplevel2 ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.HintAncestorNodes (new SiteMapNode (poker, "key"), -1);
		}

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void RemoveNode_nullNode ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoRemoveNode (null);
		}

		[Test]
		[ExpectedException (typeof (NotImplementedException))]
		public void RemoveNode_nonexistantNode ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			poker.DoRemoveNode (new SiteMapNode (poker, "foo"));
		}

		[Test]
		public void DefaultProperties ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();

			Assert.IsFalse (poker.EnableLocalization, "A1");
			Assert.IsFalse (poker.SecurityTrimmingEnabled, "A2");
			Assert.IsNull (poker.ResourceKey, "A3");
		}

		[Test]
		public void Initialize ()
		{
			SiteMapProviderPoker poker = new SiteMapProviderPoker ();
			NameValueCollection attrs = new NameValueCollection ();

			attrs.Add ("securityTrimmingEnabled", "true");
			attrs.Add ("enableLocalization", "true");
			attrs.Add ("resourceKey", "hithere");

			poker.Initialize ("namehere", attrs);

			Assert.IsFalse (poker.EnableLocalization, "A1");
			Assert.IsTrue (poker.SecurityTrimmingEnabled, "A2");
			Assert.IsNull (poker.ResourceKey, "A3");
		}

	}
	
}

#endif


		protected override void InitCallbacks ()
		{
			ArrayList maps = _typeMap.RelatedMaps;
			if (maps != null)
			{
				foreach (XmlTypeMapping map in maps)  
				{
					if (map.TypeData.SchemaType == SchemaTypes.Class || map.TypeData.SchemaType == SchemaTypes.Enum)
					{
						ReaderCallbackInfo info = new ReaderCallbackInfo (this, map);
						AddReadCallback (map.XmlType, map.Namespace, map.TypeData.Type, new XmlSerializationReadCallback (info.ReadObject));
					}
				}
			}
		}

		protected XmlTypeMapping GetTypeMap (Type type)
		{
			ArrayList maps = _typeMap.RelatedMaps;
			if (maps != null)
			{
				foreach (XmlTypeMapping map in maps)
					if (map.TypeData.Type == type) return map;
			}
			throw new InvalidOperationException ("Type " + type + " not mapped");
		}
		
		void SetListMembersDefaults (ClassMap map, object ob, bool isValueList)
		{
			if (map.ListMembers != null)
			{
				ArrayList members = map.ListMembers;
				for (int n=0; n<members.Count; n++) {
					XmlTypeMapMember mem = (XmlTypeMapMember) members[n];
					if (IsReadOnly (mem, mem.TypeData, ob, isValueList))
						continue;
					if (GetMemberValue (mem, ob, isValueList) == null)
						SetMemberValue (mem, ob, InitializeList (mem.TypeData), isValueList);
				}
			}
		}

		internal void FixupMembers (ClassMap map, object obfixup, bool isValueList)
		{
			Fixup fixup = (Fixup)obfixup;
			ICollection members = map.ElementMembers;
			string[] ids = fixup.Ids;
			foreach (XmlTypeMapMember member in members)
			{
				if (ids[member.Index] != null)
					SetMemberValue (member, fixup.Source, GetTarget(ids[member.Index]), isValueList);
			}
		}

		object GetEnumValue (XmlTypeMapping typeMap, string val)
		{
			if (val == null)
				return null;
			EnumMap map = (EnumMap) typeMap.ObjectMap;
			string ev = map.GetEnumName (typeMap.TypeFullName, val);
			if (ev == null) throw CreateUnknownConstantException (val, typeMap.TypeData.Type);
			return Enum.Parse (typeMap.TypeData.Type, ev, false);
		}

		
		bool BaseHasMixedContent (XmlTypeMapping map)
		{
			ClassMap cmap = (ClassMap)map.ObjectMap;
			return (cmap.XmlTextCollector != null && (map.BaseMap != null && DefinedInBaseMap (map.BaseMap, cmap.XmlTextCollector)));
		}

		bool HasMixedContent (XmlTypeMapping map)
		{
			ClassMap cmap = (ClassMap)map.ObjectMap;
			return (cmap.XmlTextCollector != null && (map.BaseMap == null || !DefinedInBaseMap (map.BaseMap, cmap.XmlTextCollector)));
		}

		bool DefinedInBaseMap (XmlTypeMapping map, XmlTypeMapMember member)
		{
			if (((ClassMap)map.ObjectMap).FindMember (member.Name) != null)
				return true;
			else if (map.BaseMap != null)
				return DefinedInBaseMap (map.BaseMap, member);
			else
				return false;
		}

		string ExportDefaultValue (TypeData typeData, XmlTypeMapping map, object defaultValue)
		{
			if (typeData.SchemaType == SchemaTypes.Enum) {
				EnumMap enumMap = (EnumMap) map.ObjectMap;
				// get corresponding xml name
				return enumMap.GetXmlName (map.TypeFullName, defaultValue);
		}
			return XmlCustomFormatter.ToXmlString (typeData, defaultValue);
		}

		bool IsMapExported (XmlTypeMapping map)
		{
			if (exportedMaps.ContainsKey (GetMapKey(map))) return true;
			return false;
		}

		void SetMapExported (XmlTypeMapping map)
		{
			exportedMaps [GetMapKey(map)] = map;
		}


		public DoubleImmutableMap<A, B, C> Add (A key1, B key2, C value)
		{
			IImmutableMap<B, C> immutableMap = this.map [key1] ?? ImmutableMap<B, C>.Empty;
			return new DoubleImmutableMap<A, B, C> (this.map.Add (key1, immutableMap.Add (key2, value)));
		}

		public DoubleImmutableMap<A, B, C> RemoveAll (A key1)
		{
			return new DoubleImmutableMap<A, B, C> (this.map.Remove (key1));
		}

		public DoubleImmutableMap<A, B, C> Remove (A key1, B key2)
		{
			IImmutableMap<B, C> inner = this.map [key1];
			if (inner == null)
				return this;
			IImmutableMap<B, C> newInner = inner.Remove (key2);
			if (newInner == inner)
				return this;
			return new DoubleImmutableMap<A, B, C> (this.map.Add (key1, newInner));
		}

		public static DoubleImmutableMap<A, B, C> Empty (Func<A, int> uniqueIdGenerator)
		{
			return new DoubleImmutableMap<A, B, C> (ImmutableIntKeyMap<A, IImmutableMap<B, C>>.Empty (uniqueIdGenerator));
		}

		public bool Contains (A key1, B key2)
		{
			IImmutableMap<B, C> inner = this.map [key1];
			if (inner == null)
				return false;
			return inner.ContainsKey (key2);
		}

		public bool ContainsKey1 (A key1)
		{
			return this.map.ContainsKey (key1);
		}

		
		[SetUp]
		public void GetReady()
		{
			cols=new DataColumnMapping[5];
			cols[0]=new DataColumnMapping("sourceName", "dataSetName");
			cols[1]=new DataColumnMapping("sourceID", "dataSetID");
			cols[2]=new DataColumnMapping("sourceAddress", "dataSetAddress");
			cols[3]=new DataColumnMapping("sourcePhone", "dataSetPhone");
			cols[4]=new DataColumnMapping("sourcePIN", "dataSetPIN");
			columnMapCollection=new DataColumnMappingCollection();			
		}
		
		[TearDown]
		public void Clean()
		{
			columnMapCollection.Clear();
		}
		
		[Test]
		public void Add()
		{
			DataColumnMapping col1=new DataColumnMapping("sourceName", "dataSetName");
			int t=columnMapCollection.Add((Object)col1);
			Assert.AreEqual (0, t, "test1");
			bool eq1=col1.Equals(columnMapCollection[0]);
			Assert.AreEqual (true, eq1, "test2");
			Assert.AreEqual (1, columnMapCollection.Count, "test3");
			DataColumnMapping col2;
			col2=columnMapCollection.Add("sourceID", "dataSetID");
			bool eq2=col2.Equals(columnMapCollection[1]);
			Assert.AreEqual (true, eq2, "test4");
			Assert.AreEqual (2, columnMapCollection.Count, "test5");
		}
		
		[Test]
		[ExpectedException(typeof(InvalidCastException))]
		public void AddException1()
		{
			DataColumnMappingCollection c=new DataColumnMappingCollection();
			columnMapCollection.Add((Object)c);
		}
		
		[Test]
		public void AddRange()
		{
			columnMapCollection.Add(new DataColumnMapping("sourceAge", "dataSetAge"));
			Assert.AreEqual (1, columnMapCollection.Count, "test1");
			columnMapCollection.AddRange(cols);
			Assert.AreEqual (6, columnMapCollection.Count, "test2");
			bool eq;
			eq=cols[0].Equals(columnMapCollection[1]);
			Assert.AreEqual (true, eq, "test3");
			eq=cols[1].Equals(columnMapCollection[2]);
			Assert.AreEqual (true, eq, "test4");
			
			eq=cols[0].Equals(columnMapCollection[0]);
			Assert.AreEqual (false, eq, "test5");
			eq=cols[1].Equals(columnMapCollection[0]);
			Assert.AreEqual (false, eq, "test6");
		}
		
		[Test]
		public void Clear()
		{
			DataColumnMapping col1=new DataColumnMapping("sourceName", "dataSetName");
			columnMapCollection.Add((Object)col1);
			Assert.AreEqual (1, columnMapCollection.Count, "test1");
			columnMapCollection.Clear();
			Assert.AreEqual (0, columnMapCollection.Count, "test2");
			columnMapCollection.AddRange(cols);
			Assert.AreEqual (5, columnMapCollection.Count, "test3");
			columnMapCollection.Clear();
			Assert.AreEqual (0, columnMapCollection.Count, "test4");
		}


		protected override void InitCallbacks ()
		{
			ArrayList maps = _typeMap.RelatedMaps;
			if (maps != null)
			{
				foreach (XmlTypeMapping map in maps)  {
					CallbackInfo info = new CallbackInfo (this, map);
					if (map.TypeData.SchemaType == SchemaTypes.Enum) AddWriteCallback(map.TypeData.Type, map.XmlType, map.Namespace, new XmlSerializationWriteCallback (info.WriteEnum));
					else AddWriteCallback(map.TypeData.Type, map.XmlType, map.Namespace, new XmlSerializationWriteCallback (info.WriteObject));
				}
			}
		}

		public void WriteRoot (object ob)
		{
			WriteStartDocument ();

			if (_typeMap is XmlTypeMapping)
			{
				XmlTypeMapping mp = (XmlTypeMapping) _typeMap;
				if (mp.TypeData.SchemaType == SchemaTypes.Class || mp.TypeData.SchemaType == SchemaTypes.Array) 
					TopLevelElement ();

				if (_format == SerializationFormat.Literal)
					WriteObject (mp, ob, mp.ElementName, mp.Namespace, true, false, true);
				else
					WritePotentiallyReferencingElement (mp.ElementName, mp.Namespace, ob, mp.TypeData.Type, true, false);
			}
			else if (ob is object[])
				WriteMessage ((XmlMembersMapping)_typeMap, (object[]) ob);
			else
				throw CreateUnknownTypeException (ob);

			WriteReferencedElements ();
		}
		
		protected XmlTypeMapping GetTypeMap (Type type)
		{
			ArrayList maps = _typeMap.RelatedMaps;
			if (maps != null)
			{
				foreach (XmlTypeMapping map in maps)
					if (map.TypeData.Type == type) return map;
			}
			throw new InvalidOperationException ("Type " + type + " not mapped");
		}

		protected virtual void WriteObject (XmlTypeMapping typeMap, object ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
		{
			if (ob == null)
			{
				if (isNullable) 
				{
					if (_format == SerializationFormat.Literal) WriteNullTagLiteral(element, namesp);
					else WriteNullTagEncoded (element, namesp);
				}
				return;
			}

			if (ob is XmlNode)
			{
				if (_format == SerializationFormat.Literal) WriteElementLiteral((XmlNode)ob, "", "", true, typeMap.IsAny);
				else WriteElementEncoded((XmlNode)ob, "", "", true, typeMap.IsAny);
				return;
			}

			if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
			{
				WriteSerializable ((IXmlSerializable)ob, element, namesp, isNullable, !typeMap.IsAny);
				return;
			}

			XmlTypeMapping map = typeMap.GetRealTypeMap (ob.GetType());

			if (map == null) 
			{
				// bug #81539
				if (ob.GetType ().IsArray && typeof (XmlNode).IsAssignableFrom (ob.GetType ().GetElementType ())) {
					Writer.WriteStartElement (element, namesp);
					foreach (XmlNode node in (IEnumerable) ob)
						node.WriteTo (Writer);
					Writer.WriteEndElement ();
				}
				else
					WriteTypedPrimitive (element, namesp, ob, true);
				return;
			}

			if (writeWrappingElem)
			{
				if (map != typeMap || _format == SerializationFormat.Encoded) needType = true;
				WriteStartElement (element, namesp, ob);
			}

			if (needType) 
				WriteXsiType(map.XmlType, map.XmlTypeNamespace);

			switch (map.TypeData.SchemaType)
			{
				case SchemaTypes.Class: WriteObjectElement (map, ob, element, namesp); break;
				case SchemaTypes.Array: WriteListElement (map, ob, element, namesp); break;
				case SchemaTypes.Primitive: WritePrimitiveElement (map, ob, element, namesp); break;
				case SchemaTypes.Enum: WriteEnumElement (map, ob, element, namesp); break;
			}

			if (writeWrappingElem)
				WriteEndElement (ob);
		}

		protected virtual void WriteMessage (XmlMembersMapping membersMap, object[] parameters)
		{
			if (membersMap.HasWrapperElement) {
				TopLevelElement ();
				WriteStartElement(membersMap.ElementName, membersMap.Namespace, (_format == SerializationFormat.Encoded));

				if (Writer.LookupPrefix (XmlSchema.Namespace) == null)
					WriteAttribute ("xmlns","xsd",XmlSchema.Namespace,XmlSchema.Namespace);
	
				if (Writer.LookupPrefix (XmlSchema.InstanceNamespace) == null)
					WriteAttribute ("xmlns","xsi",XmlSchema.InstanceNamespace,XmlSchema.InstanceNamespace);
			}
			
			WriteMembers ((ClassMap)membersMap.ObjectMap, parameters, true);

			if (membersMap.HasWrapperElement)
				WriteEndElement();
		}

		protected virtual void WriteObjectElement (XmlTypeMapping typeMap, object ob, string element, string namesp)
		{
			ClassMap map = (ClassMap)typeMap.ObjectMap;
			if (map.NamespaceDeclarations != null)
				WriteNamespaceDeclarations ((XmlSerializerNamespaces) map.NamespaceDeclarations.GetValue (ob));
			
			WriteObjectElementAttributes (typeMap, ob);
			WriteObjectElementElements (typeMap, ob);
		}

Utilities.Map<T1, T2> : Object

Constructors :

public Map()

Methods :

public Void Add(T1 key = , T2 value = )
public Boolean ContainsKey(T1 key = )
public Boolean ContainsValue(T2 value = )
public Boolean TryGetKey(T2 value = , T1& key = )
public Boolean TryGetValue(T1 key = , T2& value = )
public Void RemoveKey(T1 key = )
public Void RemoveValue(T2 value = )
public T2 get_Item(T1 key = )
public T1 GetKey(T2 value = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()