1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
|
//
// Tests for System.Web.UI.WebControls.TemplateControlTest.cs
//
// Author:
// Yoni Klein (yonik@mainsoft.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using MyWebControl = System.Web.UI.WebControls;
using System.Collections;
using MonoTests.SystemWeb.Framework;
using NUnit.Framework;
using MonoTests.stand_alone.WebHarness;
using System.Threading;
namespace MonoTests.System.Web.UI.WebControls
{
class PokerTemplateControl:TemplateControl
{
public PokerTemplateControl ()
{
TrackViewState ();
}
public bool DoSupportAutoEvents
{
get { return base.SupportAutoEvents; }
}
protected override void Construct ()
{
TemplateControlTest.eventchecker = true;
base.Construct ();
}
public void DoOnAbortTransaction (EventArgs e)
{
base.OnAbortTransaction (e);
}
public void DoOnCommitTransaction (EventArgs e)
{
base.OnCommitTransaction (e);
}
public void DoOnError (EventArgs e)
{
base.OnError (e);
}
public object DoEval (string str)
{
return base.Eval (str);
}
}
[TestFixture]
public class TemplateControlTest
{
public static bool eventchecker;
public string message = "My message text";
[TestFixtureSetUp]
public void GridViewInit ()
{
WebTest.CopyResource (GetType (), "TemplateUserControl.ascx", "TemplateUserControl.ascx");
}
[SetUp]
public void SetupTestCase ()
{
Thread.Sleep (100);
}
[Test]
public void TemplateControl_DefaultProperty ()
{
PokerTemplateControl t = new PokerTemplateControl ();
Assert.AreEqual (true, t.EnableTheming, "EnableTheming");
Assert.AreEqual (true, t.DoSupportAutoEvents, "SupportAutoEvents");
}
[Test]
[Category ("NunitWeb")]
public void TemplateControl_LoadControl ()
{
WebTest t = new WebTest (PageInvoker.CreateOnLoad (LoadControlTest));
string html = t.Run ();
if (html.IndexOf ("TemplateUserControl") < 0)
Assert.Fail ("LoadControl failed");
}
public static void LoadControlTest (Page p)
{
PokerTemplateControl t = new PokerTemplateControl ();
p.Form.Controls.Add (t.LoadControl ("TemplateUserControl.ascx"));
}
[Test]
[Category ("NunitWeb")]
public void TemplateControl_LoadTemplate ()
{
WebTest t = new WebTest (PageInvoker.CreateOnLoad (LoadTemplateTest));
string html = t.Run ();
if (html.IndexOf ("TemplateUserControl") < 0)
Assert.Fail ("LoadTemplate failed");
}
public static void LoadTemplateTest (Page p)
{
PokerTemplateControl t = new PokerTemplateControl ();
ITemplate tmp = t.LoadTemplate ("TemplateUserControl.ascx");
tmp.InstantiateIn (p.Form);
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")] // Must be removed after adding AppRelativeVirtualPath property
[Category ("NunitWeb")]
public void TemplateControl_ParseControl ()
{
WebTest t = new WebTest (PageInvoker.CreateOnLoad (ParseControlTest));
string html = t.Run ();
if (html.IndexOf ("<span id=\"lb\">test</span>") < 0)
Assert.Fail ("ParseControl failed");
}
public static void ParseControlTest (Page p)
{
PokerTemplateControl t = new PokerTemplateControl ();
//Does not have definition , must be uncommented
//t.AppRelativeVirtualPath = "~\\";
Control c = t.ParseControl ("<asp:label id='lb' runat='server' text='test' />");
p.Controls.Add(c);
}
[Test]
public void TemplateControl_ReadStringResource ()
{
// p.s. MSDN
// The ReadStringResource method is not intended for use from within your code
}
[Test]
[Category ("NotWorking")]
[Category ("NunitWeb")]
public void TemplateControl_TestDeviceFilter ()
{
//Have no definition to TestDeviceFilter
WebTest t = new WebTest (PageInvoker.CreateOnLoad (DoTestDeviceFilter));
string html = t.Run ();
}
public static void DoTestDeviceFilter (Page p)
{
//Have no definition to TestDeviceFilter
// bool res = p.TestDeviceFilter("test");
// Assert.AreEqual (false, res, "TestDeviceFilter#1");
//Have no definition to TestDeviceFilter
// res = p.TestDeviceFilter ("IE");
// Assert.AreEqual (true, res, "TestDeviceFilter#2");
}
[Test]
public void TemplateControl_Construct ()
{
eventchecker = false;
PokerTemplateControl t = new PokerTemplateControl ();
Assert.AreEqual (true, eventchecker, "Construct Failed");
}
[Test]
[Category ("NunitWeb")]
public void TemplateControl_Eval ()
{
// In this test aspx page used as template control
WebTest.CopyResource (GetType (), "EvalTest.aspx", "EvalTest.aspx");
WebTest t = new WebTest ("EvalTest.aspx");
PageDelegates pd = new PageDelegates ();
pd.PreRender = _templatePreRender;
t.Invoker = new PageInvoker (pd);
t.Run ();
string html = t.Run ();
if (html.IndexOf ("My databind test") < 0)
Assert.Fail ("Eval not done fail");
}
public static void _templatePreRender (Page p)
{
Repeater rep = p.FindControl ("Repeater1") as Repeater;
if (rep == null)
Assert.Fail ("Aspx page not creation failed");
Assert.AreEqual (1, rep.Items.Count, "Data items bounding failed");
}
[Test]
public void TemplateControl_XPath_XPathSelect ()
{
//These two method are tested on XmlDataSourceTest.cs
}
[Test]
public void TemplateControl_CreateResourceBasedLiteralControl ()
{
// The CreateResourceBasedLiteralControl method is not intended
// for use from within your code.
}
[Test]
public void TemplateControl_SetStringResourcePointer ()
{
// The SetStringResourcePointer method is not intended
// for use from within your code.
}
[Test]
public void TemplateControl_TemplateControl ()
{
Assert.IsNull (new Control ().TemplateControl);
PokerTemplateControl t = new PokerTemplateControl ();
Assert.AreEqual (t, t.TemplateControl);
}
[Test]
public void TemplateControl_WriteUTF8ResourceString ()
{
//This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.
//Writes a resource string to an HtmlTextWriter control.
//The WriteUTF8ResourceString method is used by generated classes and is not intended for use from within your code.
}
// Events
bool abortTransaction;
bool commitTransaction;
bool error;
[Test]
public void TemplateControl_AbortTransaction ()
{
PokerTemplateControl t = new PokerTemplateControl ();
t.AbortTransaction += new EventHandler (t_AbortTransaction);
Assert.AreEqual (false, abortTransaction, "Before transaction aborted");
t.DoOnAbortTransaction (new EventArgs ());
Assert.AreEqual (true, abortTransaction, "After transaction aborted");
}
void t_AbortTransaction (object sender, EventArgs e)
{
abortTransaction = true;
}
[Test]
public void TemplateControl_CommitTransaction ()
{
PokerTemplateControl t = new PokerTemplateControl ();
t.CommitTransaction += new EventHandler (t_CommitTransaction);
Assert.AreEqual (false, commitTransaction, "Before transaction Commited");
t.DoOnCommitTransaction (new EventArgs ());
Assert.AreEqual (true, commitTransaction, "After transaction Commited");
}
void t_CommitTransaction (object sender, EventArgs e)
{
commitTransaction = true;
}
[Test]
public void TemplateControl_Error ()
{
PokerTemplateControl t = new PokerTemplateControl ();
t.Error += new EventHandler (t_Error);
Assert.AreEqual (false, error, "Before error");
t.DoOnError (new EventArgs ());
Assert.AreEqual (true, error, "After error");
}
void t_Error (object sender, EventArgs e)
{
error = true;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TemplateControl_EvalException ()
{
PokerTemplateControl t = new PokerTemplateControl ();
t.Page = new Page ();
t.DoEval (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TemplateControl_LoadControlException()
{
PokerTemplateControl t = new PokerTemplateControl ();
t.LoadControl (null);
}
[TestFixtureTearDown]
public void TearDown ()
{
WebTest.Unload ();
}
}
}
|