PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/System.Web/Test/System.Web.UI.WebControls/LoginTest.cs

https://bitbucket.org/danipen/mono
C# | 1143 lines | 970 code | 137 blank | 36 comment | 28 complexity | 2bef73d57cd06a0d10fa0ac4a5bc1c5a MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // LoginTest.cs - Unit tests for System.Web.UI.WebControls.Login
  3. //
  4. // Author:
  5. // Sebastien Pouliot <sebastien@ximian.com>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Collections;
  31. using System.IO;
  32. using System.Web;
  33. using System.Web.UI;
  34. using System.Web.UI.WebControls;
  35. using System.Text.RegularExpressions;
  36. using NUnit.Framework;
  37. using MonoTests.SystemWeb.Framework;
  38. using MonoTests.stand_alone.WebHarness;
  39. namespace MonoTests.System.Web.UI.WebControls {
  40. public class LoginTemplate :WebControl, ITemplate {
  41. public LoginTemplate() {
  42. ID = "kuku";
  43. }
  44. void ITemplate.InstantiateIn(Control container) {
  45. container.Controls.Add(this);
  46. }
  47. }
  48. public class LayoutTemplate :WebControl, ITemplate
  49. {
  50. TextBox user;
  51. TextBox pass;
  52. CheckBox remme;
  53. Button login;
  54. Literal failure;
  55. public LayoutTemplate(){
  56. Buildcontrols();
  57. Addtocontainer();
  58. }
  59. #region build
  60. public void Buildcontrols()
  61. {
  62. user = new TextBox();
  63. pass = new TextBox();
  64. remme = new CheckBox();
  65. login = new Button();
  66. failure = new Literal();
  67. ID = "Template";
  68. user.ID = "UserName";
  69. pass.ID = "Password";
  70. remme.ID = "RememberMe";
  71. login.ID = "Login";
  72. failure.ID = "FailureText";
  73. }
  74. public void Addtocontainer()
  75. {
  76. this.Controls.Add(user);
  77. this.Controls.Add(pass);
  78. this.Controls.Add(remme);
  79. this.Controls.Add(login);
  80. this.Controls.Add(failure);
  81. }
  82. #endregion
  83. void ITemplate.InstantiateIn(Control container)
  84. {
  85. container.Controls.Add(this);
  86. }
  87. }
  88. public class TestLogin : Login {
  89. public string Tag {
  90. get { return base.TagName; }
  91. }
  92. public StateBag StateBag {
  93. get { return base.ViewState; }
  94. }
  95. public string Render ()
  96. {
  97. StringWriter sw = new StringWriter ();
  98. sw.NewLine = "\n";
  99. HtmlTextWriter writer = new HtmlTextWriter (sw);
  100. base.Render (writer);
  101. return writer.InnerWriter.ToString ();
  102. }
  103. public Style GetStyle ()
  104. {
  105. return base.CreateControlStyle ();
  106. }
  107. public void TrackState ()
  108. {
  109. TrackViewState ();
  110. }
  111. public void LoadState (object state)
  112. {
  113. LoadViewState (state);
  114. }
  115. public object SaveState ()
  116. {
  117. return SaveViewState ();
  118. }
  119. public void SetDesignMode (IDictionary dic)
  120. {
  121. base.SetDesignModeState (dic);
  122. }
  123. private bool authenticated;
  124. private bool cancel;
  125. private bool onAuthenticate;
  126. private bool onBubble;
  127. private bool onLoggedIn;
  128. private bool onLoggingIn;
  129. private bool onLoginError;
  130. public bool Authenticated {
  131. get { return authenticated; }
  132. set { authenticated = value; }
  133. }
  134. public bool Cancel {
  135. get { return cancel; }
  136. set { cancel = value; }
  137. }
  138. public bool OnAuthenticateCalled {
  139. get { return onAuthenticate; }
  140. set { onAuthenticate = value; }
  141. }
  142. protected override void OnAuthenticate (AuthenticateEventArgs e)
  143. {
  144. onAuthenticate = true;
  145. e.Authenticated = authenticated;
  146. base.OnAuthenticate (e);
  147. e.Authenticated = authenticated;
  148. }
  149. public void DoAuthenticate (AuthenticateEventArgs e)
  150. {
  151. base.OnAuthenticate (e);
  152. }
  153. public bool OnBubbleEventCalled {
  154. get { return onBubble; }
  155. set { onBubble = value; }
  156. }
  157. protected override bool OnBubbleEvent (object source, EventArgs e)
  158. {
  159. onBubble = true;
  160. return base.OnBubbleEvent (source, e);
  161. }
  162. public bool DoBubbleEvent (object source, EventArgs e)
  163. {
  164. return base.OnBubbleEvent (source, e);
  165. }
  166. public bool OnLoggedInCalled {
  167. get { return onLoggedIn; }
  168. set { onLoggedIn = value; }
  169. }
  170. protected override void OnLoggedIn (EventArgs e)
  171. {
  172. onLoggedIn = true;
  173. base.OnLoggedIn (e);
  174. }
  175. public void DoLoggedIn (EventArgs e)
  176. {
  177. base.OnLoggedIn (e);
  178. }
  179. public bool OnLoggingInCalled {
  180. get { return onLoggingIn; }
  181. set { onLoggingIn = value; }
  182. }
  183. protected override void OnLoggingIn (LoginCancelEventArgs e)
  184. {
  185. onLoggingIn = true;
  186. e.Cancel = cancel;
  187. base.OnLoggingIn (e);
  188. }
  189. public void DoLoggingIn (LoginCancelEventArgs e)
  190. {
  191. base.OnLoggingIn (e);
  192. }
  193. public bool OnLoginErrorCalled {
  194. get { return onLoginError; }
  195. set { onLoginError = value; }
  196. }
  197. protected override void OnLoginError (EventArgs e)
  198. {
  199. onLoginError = true;
  200. base.OnLoginError (e);
  201. }
  202. public void DoLoginError (EventArgs e)
  203. {
  204. base.OnLoginError (e);
  205. }
  206. public void DoEnsureChildControls() {
  207. base.EnsureChildControls ();
  208. }
  209. }
  210. [TestFixture]
  211. public class LoginTest {
  212. private HtmlTextWriter GetWriter ()
  213. {
  214. StringWriter sw = new StringWriter ();
  215. sw.NewLine = "\n";
  216. return new HtmlTextWriter (sw);
  217. }
  218. #if NET_2_0
  219. [TestFixtureSetUp]
  220. public void SetUp ()
  221. {
  222. WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
  223. WebTest.CopyResource (GetType (), "LoginDisplayRememberMe.aspx", "LoginDisplayRememberMe.aspx");
  224. }
  225. #endif
  226. [Test]
  227. public void ReadOnlyFields ()
  228. {
  229. Assert.AreEqual ("Login", Login.LoginButtonCommandName, "LoginButtonCommandName");
  230. }
  231. [Test]
  232. public void DefaultProperties ()
  233. {
  234. TestLogin l = new TestLogin ();
  235. Assert.AreEqual (0, l.Attributes.Count, "Attributes.Count");
  236. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count");
  237. Assert.AreEqual (1, l.BorderPadding, "BorderPadding");
  238. Assert.AreEqual (String.Empty, l.CreateUserIconUrl, "CreateUserIconUrl");
  239. Assert.AreEqual (String.Empty, l.CreateUserText, "CreateUserText");
  240. Assert.AreEqual (String.Empty, l.DestinationPageUrl, "DestinationPageUrl");
  241. Assert.IsTrue (l.DisplayRememberMe, "DisplayRememberMe");
  242. Assert.AreEqual (LoginFailureAction.Refresh, l.FailureAction, "FailureAction");
  243. Assert.AreEqual ("Your login attempt was not successful. Please try again.", l.FailureText, "FailureText");
  244. Assert.AreEqual (String.Empty, l.HelpPageIconUrl, "HelpPageIconUrl");
  245. Assert.AreEqual (String.Empty, l.HelpPageText, "HelpPageText");
  246. Assert.AreEqual (String.Empty, l.HelpPageUrl, "HelpPageUrl");
  247. Assert.AreEqual (String.Empty, l.InstructionText, "InstructionText");
  248. Assert.AreEqual (String.Empty, l.LoginButtonImageUrl, "LoginButtonImageUrl");
  249. Assert.AreEqual ("Log In", l.LoginButtonText, "LoginButtonText");
  250. Assert.AreEqual (ButtonType.Button, l.LoginButtonType, "LoginButtonType");
  251. Assert.AreEqual (String.Empty, l.MembershipProvider, "MembershipProvider");
  252. Assert.AreEqual (Orientation.Vertical, l.Orientation, "Orientation");
  253. Assert.AreEqual (String.Empty, l.Password, "Password");
  254. Assert.AreEqual ("Password:", l.PasswordLabelText, "PasswordLabelText");
  255. Assert.AreEqual (String.Empty, l.PasswordRecoveryIconUrl, "PasswordRecoveryIconUrl");
  256. Assert.AreEqual (String.Empty, l.PasswordRecoveryText, "PasswordRecoveryText");
  257. Assert.AreEqual (String.Empty, l.PasswordRecoveryUrl, "PasswordRecoveryUrl");
  258. Assert.AreEqual ("Password is required.", l.PasswordRequiredErrorMessage, "PasswordRequiredErrorMessage");
  259. Assert.IsFalse (l.RememberMeSet, "RememberMeSet");
  260. Assert.AreEqual ("Remember me next time.", l.RememberMeText, "RememberMeText");
  261. Assert.AreEqual (LoginTextLayout.TextOnLeft, l.TextLayout, "TextLayout");
  262. Assert.AreEqual ("Log In", l.TitleText, "TitleText");
  263. Assert.AreEqual (String.Empty, l.UserName, "UserName");
  264. Assert.AreEqual ("User Name:", l.UserNameLabelText, "UserNameLabelText");
  265. Assert.AreEqual ("User Name is required.", l.UserNameRequiredErrorMessage, "UserNameRequiredErrorMessage");
  266. Assert.IsTrue (l.VisibleWhenLoggedIn, "VisibleWhenLoggedIn");
  267. // Styles
  268. Assert.IsNotNull (l.CheckBoxStyle, "CheckBoxStyle");
  269. Assert.IsNotNull (l.FailureTextStyle, "FailureTextStyle");
  270. Assert.IsNotNull (l.HyperLinkStyle, "HyperLinkStyle");
  271. Assert.IsNotNull (l.InstructionTextStyle, "InstructionTextStyle");
  272. Assert.IsNotNull (l.LabelStyle, "LabelStyle");
  273. Assert.IsNotNull (l.LoginButtonStyle, "LoginButtonStyle");
  274. Assert.IsNotNull (l.TextBoxStyle, "TextBoxStyle");
  275. Assert.IsNotNull (l.TitleTextStyle, "TitleTextStyle");
  276. Assert.IsNotNull (l.ValidatorTextStyle, "ValidatorTextStyle");
  277. // Templates
  278. Assert.IsNull (l.LayoutTemplate, "LayoutTemplate");
  279. Assert.AreEqual ("table", l.Tag, "TagName");
  280. Assert.AreEqual (0, l.Attributes.Count, "Attributes.Count-2");
  281. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-2");
  282. }
  283. [Test]
  284. public void AssignToDefaultProperties ()
  285. {
  286. TestLogin l = new TestLogin ();
  287. Assert.AreEqual (0, l.Attributes.Count, "Attributes.Count");
  288. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count");
  289. l.BorderPadding = 1;
  290. Assert.AreEqual (1, l.BorderPadding, "BorderPadding");
  291. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-1");
  292. l.CreateUserIconUrl = String.Empty;
  293. Assert.AreEqual (String.Empty, l.CreateUserIconUrl, "CreateUserIconUrl");
  294. Assert.AreEqual (2, l.StateBag.Count, "ViewState.Count-2");
  295. l.CreateUserText = String.Empty;
  296. Assert.AreEqual (String.Empty, l.CreateUserText, "CreateUserText");
  297. Assert.AreEqual (3, l.StateBag.Count, "ViewState.Count-3");
  298. l.DestinationPageUrl = String.Empty;
  299. Assert.AreEqual (String.Empty, l.DestinationPageUrl, "DestinationPageUrl");
  300. Assert.AreEqual (4, l.StateBag.Count, "ViewState.Count-4");
  301. l.DisplayRememberMe = true;
  302. Assert.IsTrue (l.DisplayRememberMe, "DisplayRememberMe");
  303. Assert.AreEqual (5, l.StateBag.Count, "ViewState.Count-5");
  304. l.FailureAction = LoginFailureAction.Refresh;
  305. Assert.AreEqual (LoginFailureAction.Refresh, l.FailureAction, "FailureAction");
  306. Assert.AreEqual (6, l.StateBag.Count, "ViewState.Count-6");
  307. l.FailureText = "Your login attempt was not successful. Please try again.";
  308. Assert.AreEqual ("Your login attempt was not successful. Please try again.", l.FailureText, "FailureText");
  309. Assert.AreEqual (7, l.StateBag.Count, "ViewState.Count-7");
  310. l.HelpPageIconUrl = String.Empty;
  311. Assert.AreEqual (String.Empty, l.HelpPageIconUrl, "HelpPageIconUrl");
  312. Assert.AreEqual (8, l.StateBag.Count, "ViewState.Count-8");
  313. l.HelpPageText = String.Empty;
  314. Assert.AreEqual (String.Empty, l.HelpPageText, "HelpPageText");
  315. Assert.AreEqual (9, l.StateBag.Count, "ViewState.Count-9");
  316. l.HelpPageUrl = String.Empty;
  317. Assert.AreEqual (String.Empty, l.HelpPageUrl, "HelpPageUrl");
  318. Assert.AreEqual (10, l.StateBag.Count, "ViewState.Count-10");
  319. l.InstructionText = String.Empty;
  320. Assert.AreEqual (String.Empty, l.InstructionText, "InstructionText");
  321. Assert.AreEqual (11, l.StateBag.Count, "ViewState.Count-11");
  322. l.LayoutTemplate = null;
  323. Assert.IsNull (l.LayoutTemplate, "LayoutTemplate");
  324. l.LoginButtonImageUrl = String.Empty;
  325. Assert.AreEqual (String.Empty, l.LoginButtonImageUrl, "LoginButtonImageUrl");
  326. Assert.AreEqual (12, l.StateBag.Count, "ViewState.Count-12");
  327. l.LoginButtonText = "Log In";
  328. Assert.AreEqual ("Log In", l.LoginButtonText, "LoginButtonText");
  329. Assert.AreEqual (13, l.StateBag.Count, "ViewState.Count-13");
  330. l.LoginButtonType = ButtonType.Button;
  331. Assert.AreEqual (ButtonType.Button, l.LoginButtonType, "LoginButtonType");
  332. Assert.AreEqual (14, l.StateBag.Count, "ViewState.Count-14");
  333. l.MembershipProvider = String.Empty;
  334. Assert.AreEqual (String.Empty, l.MembershipProvider, "MembershipProvider");
  335. Assert.AreEqual (15, l.StateBag.Count, "ViewState.Count-15");
  336. l.Orientation = Orientation.Vertical;
  337. Assert.AreEqual (Orientation.Vertical, l.Orientation, "Orientation");
  338. Assert.AreEqual (16, l.StateBag.Count, "ViewState.Count-16");
  339. // note: Password is read-only
  340. Assert.AreEqual (String.Empty, l.Password, "Password");
  341. l.PasswordLabelText = "Password:";
  342. Assert.AreEqual ("Password:", l.PasswordLabelText, "PasswordLabelText");
  343. Assert.AreEqual (17, l.StateBag.Count, "ViewState.Count-17");
  344. l.PasswordRecoveryIconUrl = String.Empty;
  345. Assert.AreEqual (String.Empty, l.PasswordRecoveryIconUrl, "PasswordRecoveryIconUrl");
  346. Assert.AreEqual (18, l.StateBag.Count, "ViewState.Count-18");
  347. l.PasswordRecoveryText = String.Empty;
  348. Assert.AreEqual (String.Empty, l.PasswordRecoveryText, "PasswordRecoveryText");
  349. Assert.AreEqual (19, l.StateBag.Count, "ViewState.Count-19");
  350. l.PasswordRecoveryUrl = String.Empty;
  351. Assert.AreEqual (String.Empty, l.PasswordRecoveryUrl, "PasswordRecoveryUrl");
  352. Assert.AreEqual (20, l.StateBag.Count, "ViewState.Count-20");
  353. l.PasswordRequiredErrorMessage = "Password is required.";
  354. Assert.AreEqual ("Password is required.", l.PasswordRequiredErrorMessage, "PasswordRequiredErrorMessage");
  355. Assert.AreEqual (21, l.StateBag.Count, "ViewState.Count-21");
  356. l.RememberMeSet = false;
  357. Assert.IsFalse (l.RememberMeSet, "RememberMeSet");
  358. Assert.AreEqual (22, l.StateBag.Count, "ViewState.Count-22");
  359. l.RememberMeText = "Remember me next time.";
  360. Assert.AreEqual ("Remember me next time.", l.RememberMeText, "RememberMeText");
  361. Assert.AreEqual (23, l.StateBag.Count, "ViewState.Count-23");
  362. l.TextLayout = LoginTextLayout.TextOnLeft;
  363. Assert.AreEqual (LoginTextLayout.TextOnLeft, l.TextLayout, "TextLayout");
  364. Assert.AreEqual (24, l.StateBag.Count, "ViewState.Count-24");
  365. l.TitleText = "Log In";
  366. Assert.AreEqual ("Log In", l.TitleText, "TitleText");
  367. Assert.AreEqual (25, l.StateBag.Count, "ViewState.Count-25");
  368. l.UserName = String.Empty;
  369. Assert.AreEqual (String.Empty, l.UserName, "UserName");
  370. Assert.AreEqual (26, l.StateBag.Count, "ViewState.Count-26");
  371. l.UserNameLabelText = "User Name:";
  372. Assert.AreEqual ("User Name:", l.UserNameLabelText, "UserNameLabelText");
  373. Assert.AreEqual (27, l.StateBag.Count, "ViewState.Count-27");
  374. l.UserNameRequiredErrorMessage = "User Name is required.";
  375. Assert.AreEqual ("User Name is required.", l.UserNameRequiredErrorMessage, "UserNameRequiredErrorMessage");
  376. Assert.AreEqual (28, l.StateBag.Count, "ViewState.Count-28");
  377. l.VisibleWhenLoggedIn = true;
  378. Assert.IsTrue (l.VisibleWhenLoggedIn, "VisibleWhenLoggedIn");
  379. Assert.AreEqual (29, l.StateBag.Count, "ViewState.Count-29");
  380. Assert.AreEqual (0, l.Attributes.Count, "Attributes.Count-2");
  381. }
  382. [Test]
  383. public void NullProperties ()
  384. {
  385. TestLogin l = new TestLogin ();
  386. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count");
  387. // unlike 1.1 controls it seems that null (and not the default value)
  388. // must be used to remove values from the ViewState
  389. l.CreateUserIconUrl = "*";
  390. Assert.AreEqual ("*", l.CreateUserIconUrl, "CreateUserIconUrl*");
  391. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-1*");
  392. l.CreateUserIconUrl = null;
  393. Assert.AreEqual (String.Empty, l.CreateUserIconUrl, "CreateUserIconUrl");
  394. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-1");
  395. l.CreateUserText = "*";
  396. Assert.AreEqual ("*", l.CreateUserText, "CreateUserText*");
  397. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-2*");
  398. l.CreateUserText = null;
  399. Assert.AreEqual (String.Empty, l.CreateUserText, "CreateUserText");
  400. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-2");
  401. l.DestinationPageUrl = "*";
  402. Assert.AreEqual ("*", l.DestinationPageUrl, "DestinationPageUrl*");
  403. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-3*");
  404. l.DestinationPageUrl = null;
  405. Assert.AreEqual (String.Empty, l.DestinationPageUrl, "DestinationPageUrl");
  406. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-3");
  407. l.FailureText = "*";
  408. Assert.AreEqual ("*", l.FailureText, "FailureTex*");
  409. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-4*");
  410. l.FailureText = null;
  411. Assert.AreEqual ("Your login attempt was not successful. Please try again.", l.FailureText, "FailureText");
  412. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-4");
  413. l.HelpPageIconUrl = "*";
  414. Assert.AreEqual ("*", l.HelpPageIconUrl, "HelpPageIconUrl*");
  415. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-5*");
  416. l.HelpPageIconUrl = null;
  417. Assert.AreEqual (String.Empty, l.HelpPageIconUrl, "HelpPageIconUrl");
  418. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-5");
  419. l.HelpPageText = "*";
  420. Assert.AreEqual ("*", l.HelpPageText, "HelpPageText*");
  421. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-6*");
  422. l.HelpPageText = null;
  423. Assert.AreEqual (String.Empty, l.HelpPageText, "HelpPageText");
  424. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-6");
  425. l.HelpPageUrl = "*";
  426. Assert.AreEqual ("*", l.HelpPageUrl, "HelpPageUrl*");
  427. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-7*");
  428. l.HelpPageUrl = null;
  429. Assert.AreEqual (String.Empty, l.HelpPageUrl, "HelpPageUrl");
  430. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-7");
  431. l.InstructionText = "*";
  432. Assert.AreEqual ("*", l.InstructionText, "InstructionText*");
  433. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-8*");
  434. l.InstructionText = null;
  435. Assert.AreEqual (String.Empty, l.InstructionText, "InstructionText");
  436. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-8");
  437. l.LoginButtonImageUrl = "*";
  438. Assert.AreEqual ("*", l.LoginButtonImageUrl, "LoginButtonImageUrl*");
  439. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-9*");
  440. l.LoginButtonImageUrl = null;
  441. Assert.AreEqual (String.Empty, l.LoginButtonImageUrl, "LoginButtonImageUrl");
  442. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-9");
  443. l.LoginButtonText = "*";
  444. Assert.AreEqual ("*", l.LoginButtonText, "LoginButtonText*");
  445. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-10*");
  446. l.LoginButtonText = null;
  447. Assert.AreEqual ("Log In", l.LoginButtonText, "LoginButtonText");
  448. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-10");
  449. l.MembershipProvider = "*";
  450. Assert.AreEqual ("*", l.MembershipProvider, "MembershipProvider*");
  451. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-11*");
  452. l.MembershipProvider = null;
  453. Assert.AreEqual (String.Empty, l.MembershipProvider, "MembershipProvider");
  454. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-11");
  455. l.PasswordLabelText = "*";
  456. Assert.AreEqual ("*", l.PasswordLabelText, "PasswordLabelText*");
  457. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-12*");
  458. l.PasswordLabelText = null;
  459. Assert.AreEqual ("Password:", l.PasswordLabelText, "PasswordLabelText");
  460. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-12");
  461. l.PasswordRecoveryIconUrl = "*";
  462. Assert.AreEqual ("*", l.PasswordRecoveryIconUrl, "PasswordRecoveryIconUrl*");
  463. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-13*");
  464. l.PasswordRecoveryIconUrl = null;
  465. Assert.AreEqual (String.Empty, l.PasswordRecoveryIconUrl, "PasswordRecoveryIconUrl");
  466. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-13");
  467. l.PasswordRecoveryText = "*";
  468. Assert.AreEqual ("*", l.PasswordRecoveryText, "PasswordRecoveryText*");
  469. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-14*");
  470. l.PasswordRecoveryText = null;
  471. Assert.AreEqual (String.Empty, l.PasswordRecoveryText, "PasswordRecoveryText");
  472. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-14");
  473. l.PasswordRecoveryUrl = "*";
  474. Assert.AreEqual ("*", l.PasswordRecoveryUrl, "PasswordRecoveryUrl*");
  475. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-15*");
  476. l.PasswordRecoveryUrl = null;
  477. Assert.AreEqual (String.Empty, l.PasswordRecoveryUrl, "PasswordRecoveryUrl");
  478. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-15");
  479. l.PasswordRequiredErrorMessage = "*";
  480. Assert.AreEqual ("*", l.PasswordRequiredErrorMessage, "PasswordRequiredErrorMessage*");
  481. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-16*");
  482. l.PasswordRequiredErrorMessage = null;
  483. Assert.AreEqual ("Password is required.", l.PasswordRequiredErrorMessage, "PasswordRequiredErrorMessage");
  484. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-16");
  485. l.RememberMeText = "*";
  486. Assert.AreEqual ("*", l.RememberMeText, "RememberMeText*");
  487. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-17*");
  488. l.RememberMeText = null;
  489. Assert.AreEqual ("Remember me next time.", l.RememberMeText, "RememberMeText");
  490. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-17");
  491. l.TitleText = "*";
  492. Assert.AreEqual ("*", l.TitleText, "TitleText*");
  493. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-18*");
  494. l.TitleText = null;
  495. Assert.AreEqual ("Log In", l.TitleText, "TitleText");
  496. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-18");
  497. l.UserName = "*";
  498. Assert.AreEqual ("*", l.UserName, "UserName*");
  499. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-19*");
  500. l.UserName = null;
  501. Assert.AreEqual (String.Empty, l.UserName, "UserName");
  502. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-19");
  503. l.UserNameLabelText = "*";
  504. Assert.AreEqual ("*", l.UserNameLabelText, "UserNameLabelText*");
  505. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-20*");
  506. l.UserNameLabelText = null;
  507. Assert.AreEqual ("User Name:", l.UserNameLabelText, "UserNameLabelText");
  508. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-20");
  509. l.UserNameRequiredErrorMessage = "*";
  510. Assert.AreEqual ("*", l.UserNameRequiredErrorMessage, "UserNameRequiredErrorMessage*");
  511. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count-21*");
  512. l.UserNameRequiredErrorMessage = null;
  513. Assert.AreEqual ("User Name is required.", l.UserNameRequiredErrorMessage, "UserNameRequiredErrorMessage");
  514. Assert.AreEqual (0, l.StateBag.Count, "ViewState.Count-21");
  515. }
  516. [Test]
  517. public void BorderPadding ()
  518. {
  519. TestLogin l = new TestLogin ();
  520. l.BorderPadding = Int32.MaxValue;
  521. Assert.AreEqual (Int32.MaxValue, l.BorderPadding, "BorderPadding");
  522. l.BorderPadding = 1;
  523. Assert.AreEqual (1, l.BorderPadding, "BorderPadding");
  524. l.BorderPadding = 0;
  525. Assert.AreEqual (0, l.BorderPadding, "BorderPadding");
  526. l.BorderPadding = -1;
  527. Assert.AreEqual (-1, l.BorderPadding, "BorderPadding");
  528. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count");
  529. }
  530. [Test]
  531. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  532. public void BorderPadding_Negative ()
  533. {
  534. TestLogin l = new TestLogin ();
  535. l.BorderPadding = Int32.MinValue;
  536. Assert.AreEqual (1, l.BorderPadding, "BorderPadding");
  537. }
  538. [Test]
  539. public void FailureAction_All ()
  540. {
  541. TestLogin l = new TestLogin ();
  542. foreach (LoginFailureAction lfa in Enum.GetValues (typeof (LoginFailureAction))) {
  543. l.FailureAction = lfa;
  544. }
  545. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count");
  546. }
  547. [Test]
  548. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  549. public void FailureAction_Invalid ()
  550. {
  551. TestLogin l = new TestLogin ();
  552. l.FailureAction = (LoginFailureAction) Int32.MinValue;
  553. }
  554. [Test]
  555. public void LayoutTemplate()
  556. {
  557. TestLogin l = new TestLogin();
  558. l.LayoutTemplate = new LayoutTemplate();
  559. l.DoEnsureChildControls();
  560. Assert.IsNotNull(l.FindControl("Template"), "LoginTemplate");
  561. Assert.IsNotNull(l.FindControl("UserName"), "UserName");
  562. }
  563. [Test]
  564. [ExpectedException(typeof(HttpException))]
  565. public void LayoutTemplateException ()
  566. {
  567. TestLogin l = new TestLogin ();
  568. l.LayoutTemplate = new LoginTemplate();
  569. l.DoEnsureChildControls();
  570. }
  571. [Test]
  572. public void LoginButtonType_All ()
  573. {
  574. TestLogin l = new TestLogin ();
  575. foreach (ButtonType bt in Enum.GetValues (typeof (ButtonType))) {
  576. l.LoginButtonType = bt;
  577. }
  578. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count");
  579. }
  580. [Test]
  581. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  582. public void LoginButtonType_Invalid ()
  583. {
  584. TestLogin l = new TestLogin ();
  585. l.LoginButtonType = (ButtonType)Int32.MinValue;
  586. }
  587. [Test]
  588. public void Orientation_All ()
  589. {
  590. TestLogin l = new TestLogin ();
  591. foreach (Orientation o in Enum.GetValues (typeof (Orientation))) {
  592. l.Orientation = o;
  593. }
  594. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count");
  595. }
  596. [Test]
  597. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  598. public void Orientation_Invalid ()
  599. {
  600. TestLogin l = new TestLogin ();
  601. l.Orientation = (Orientation)Int32.MinValue;
  602. }
  603. [Test]
  604. public void TextLayout_All ()
  605. {
  606. TestLogin l = new TestLogin ();
  607. foreach (LoginTextLayout ltl in Enum.GetValues (typeof (LoginTextLayout))) {
  608. l.TextLayout = ltl;
  609. }
  610. Assert.AreEqual (1, l.StateBag.Count, "ViewState.Count");
  611. }
  612. [Test]
  613. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  614. public void TextLayout_Invalid ()
  615. {
  616. TestLogin l = new TestLogin ();
  617. l.TextLayout = (LoginTextLayout)Int32.MinValue;
  618. }
  619. [Test]
  620. public void SaveViewState ()
  621. {
  622. TestLogin l = new TestLogin ();
  623. l.TrackState ();
  624. Assert.IsNull (l.SaveState (), "Empty");
  625. l.BorderPadding = 2;
  626. object[] vs = (object[])l.SaveState ();
  627. Assert.AreEqual (10, vs.Length, "Size");
  628. l.CreateUserIconUrl = String.Empty;
  629. l.CreateUserText = String.Empty;
  630. l.DestinationPageUrl = String.Empty;
  631. l.DisplayRememberMe = true;
  632. l.FailureAction = LoginFailureAction.Refresh;
  633. l.FailureText = "Your login attempt was not successful. Please try again.";
  634. l.HelpPageIconUrl = String.Empty;
  635. l.HelpPageText = String.Empty;
  636. l.HelpPageUrl = String.Empty;
  637. l.InstructionText = String.Empty;
  638. l.LayoutTemplate = null;
  639. l.LoginButtonImageUrl = String.Empty;
  640. l.LoginButtonText = "Log In";
  641. l.LoginButtonType = ButtonType.Button;
  642. l.MembershipProvider = String.Empty;
  643. l.Orientation = Orientation.Vertical;
  644. // note: Password is read-only
  645. l.PasswordLabelText = "Password:";
  646. l.PasswordRecoveryIconUrl = String.Empty;
  647. l.PasswordRecoveryText = String.Empty;
  648. l.PasswordRecoveryUrl = String.Empty;
  649. l.PasswordRequiredErrorMessage = "Password is required.";
  650. l.RememberMeSet = false;
  651. l.RememberMeText = "Remember me next time.";
  652. l.TextLayout = LoginTextLayout.TextOnLeft;
  653. l.TitleText = "Log In";
  654. l.UserName = String.Empty;
  655. l.UserNameLabelText = "User Name:";
  656. l.UserNameRequiredErrorMessage = "User Name is required.";
  657. l.VisibleWhenLoggedIn = true;
  658. vs = (object[])l.SaveState ();
  659. // the viewstate is all null except the first element
  660. Assert.IsNotNull (vs[0], "NotEmpty-0");
  661. for (int i = 1; i < vs.Length; i++)
  662. Assert.IsNull (vs[i], "Empty-" + i);
  663. l.CheckBoxStyle.HorizontalAlign = HorizontalAlign.Justify;
  664. vs = (object[])l.SaveState ();
  665. Assert.IsNotNull (vs[7], "NotEmpty-7");
  666. l.FailureTextStyle.HorizontalAlign = HorizontalAlign.Justify;
  667. vs = (object[])l.SaveState ();
  668. Assert.IsNotNull (vs[8], "NotEmpty-8");
  669. l.HyperLinkStyle.HorizontalAlign = HorizontalAlign.Justify;
  670. vs = (object[])l.SaveState ();
  671. Assert.IsNotNull (vs[4], "NotEmpty-4");
  672. l.InstructionTextStyle.HorizontalAlign = HorizontalAlign.Justify;
  673. vs = (object[])l.SaveState ();
  674. Assert.IsNotNull (vs[5], "NotEmpty-5");
  675. l.LabelStyle.HorizontalAlign = HorizontalAlign.Justify;
  676. vs = (object[])l.SaveState ();
  677. Assert.IsNotNull (vs[2], "NotEmpty-2");
  678. l.LoginButtonStyle.BorderStyle = BorderStyle.Double;
  679. vs = (object[])l.SaveState ();
  680. Assert.IsNotNull (vs[1], "NotEmpty-1");
  681. l.TextBoxStyle.BorderStyle = BorderStyle.Double;
  682. vs = (object[])l.SaveState ();
  683. Assert.IsNotNull (vs[3], "NotEmpty-3");
  684. l.TitleTextStyle.HorizontalAlign = HorizontalAlign.Justify;
  685. vs = (object[])l.SaveState ();
  686. Assert.IsNotNull (vs[6], "NotEmpty-6");
  687. l.ValidatorTextStyle.BorderStyle = BorderStyle.Double;
  688. vs = (object[])l.SaveState ();
  689. Assert.IsNotNull (vs[9], "NotEmpty-9");
  690. }
  691. [Test]
  692. [Category ("NunitWeb")]
  693. public void OnBubbleEvent ()
  694. {
  695. WebTest t = new WebTest (PageInvoker.CreateOnPreInit (_OnBubbleEvent));
  696. string html = t.Run ();
  697. }
  698. public static void DoOnBubbleEvent(Page p, string cmdname)
  699. {
  700. TestLogin l = new TestLogin ();
  701. l.Page = p;
  702. l.Page.Validate ();
  703. l.MembershipProvider = "FakeProvider";
  704. Button b = (Button)l.FindControl ("LoginButton");
  705. Assert.IsNotNull (b, "LoginButton");
  706. CommandEventArgs cea = new CommandEventArgs (cmdname, null);
  707. l.DoBubbleEvent (b, cea);
  708. Assert.IsTrue (l.OnLoggingInCalled, "OnLoggingIn");
  709. Assert.IsFalse (l.Cancel, "Cancel");
  710. Assert.IsTrue (l.OnAuthenticateCalled, "OnAuthenticate");
  711. Assert.IsFalse (l.Authenticated, "Authenticated");
  712. Assert.IsTrue (l.OnLoginErrorCalled, "OnLoginError");
  713. Assert.IsFalse (l.OnLoggedInCalled, "OnLoggedIn");
  714. }
  715. public static void _OnBubbleEvent(Page p)
  716. {
  717. DoOnBubbleEvent(p, "Login");
  718. }
  719. [Test]
  720. [Category ("NunitWeb")]
  721. public void OnBubbleEventCaseSensitivity ()
  722. {
  723. WebTest t = new WebTest (PageInvoker.CreateOnPreInit (_OnBubbleEventCaseSensitivity));
  724. string html = t.Run ();
  725. }
  726. public static void _OnBubbleEventCaseSensitivity(Page p)
  727. {
  728. DoOnBubbleEvent(p, "login");
  729. }
  730. [Test]
  731. public void OnBubbleEvent_Cancel_OnLoggingIn ()
  732. {
  733. TestLogin l = new TestLogin ();
  734. l.Page = new Page ();
  735. l.Page.Validate ();
  736. Button b = (Button)l.FindControl ("LoginButton");
  737. Assert.IsNotNull (b, "LoginButton");
  738. CommandEventArgs cea = new CommandEventArgs ("Login", null);
  739. l.Cancel = true;
  740. l.DoBubbleEvent (b, cea);
  741. Assert.IsTrue (l.OnLoggingInCalled, "OnLoggingIn");
  742. Assert.IsFalse (l.OnAuthenticateCalled, "OnAuthenticate");
  743. Assert.IsFalse (l.OnLoginErrorCalled, "OnLoginError");
  744. Assert.IsFalse (l.OnLoggedInCalled, "OnLoggedIn");
  745. }
  746. [Test]
  747. public void OnBubbleEvent_Authenticated_OnAuthenticate ()
  748. {
  749. WebTest t = new WebTest (PageInvoker.CreateOnPreInit (_OnBubbleEvent_Authenticated_OnAuthenticate));
  750. string html = t.Run ();
  751. }
  752. public static void _OnBubbleEvent_Authenticated_OnAuthenticate (Page p)
  753. {
  754. TestLogin l = new TestLogin ();
  755. l.Page = p;
  756. l.Page.Validate ();
  757. Button b = (Button) l.FindControl ("LoginButton");
  758. Assert.IsNotNull (b, "LoginButton");
  759. CommandEventArgs cea = new CommandEventArgs ("Login", null);
  760. l.UserName = "me";
  761. l.Authenticated = true;
  762. l.MembershipProvider = "FakeProvider";
  763. l.Authenticate += new AuthenticateEventHandler(l_Authenticate);
  764. try {
  765. l.DoBubbleEvent (b, cea);
  766. }
  767. catch (NullReferenceException) {
  768. // ms
  769. }
  770. catch (HttpException) {
  771. // no context is available
  772. }
  773. }
  774. public static void l_Authenticate (object sender, AuthenticateEventArgs e)
  775. {
  776. if (e.Authenticated == true) {
  777. TestLogin l = (TestLogin) sender;
  778. l.Authenticated = false;
  779. }
  780. else
  781. Assert.Fail ("Login failed: l_Authenticate");
  782. }
  783. private void OnLoggingIn (bool cancel)
  784. {
  785. TestLogin l = new TestLogin ();
  786. LoginCancelEventArgs lcea = new LoginCancelEventArgs (cancel);
  787. l.DoLoggingIn (lcea);
  788. Assert.IsFalse (l.OnBubbleEventCalled, "OnBubbleEvent");
  789. Assert.IsFalse (l.OnLoggingInCalled, "OnLoggingIn");
  790. Assert.IsFalse (l.OnAuthenticateCalled, "OnAuthenticate");
  791. Assert.IsFalse (l.OnLoginErrorCalled, "OnLoginError");
  792. Assert.IsFalse (l.OnLoggedInCalled, "OnLoggedIn");
  793. }
  794. [Test]
  795. public void OnLoggingIn_False ()
  796. {
  797. OnLoggingIn (false);
  798. }
  799. [Test]
  800. public void OnLoggingIn_True ()
  801. {
  802. OnLoggingIn (true);
  803. }
  804. private void OnAuthenticate (bool authenticate)
  805. {
  806. TestLogin l = new TestLogin ();
  807. AuthenticateEventArgs aea = new AuthenticateEventArgs (authenticate);
  808. l.DoAuthenticate (aea);
  809. Assert.IsFalse (l.OnBubbleEventCalled, "OnBubbleEvent");
  810. Assert.IsFalse (l.OnLoggingInCalled, "OnLoggingIn");
  811. Assert.IsFalse (l.OnAuthenticateCalled, "OnAuthenticate");
  812. Assert.IsFalse (l.OnLoginErrorCalled, "OnLoginError");
  813. Assert.IsFalse (l.OnLoggedInCalled, "OnLoggedIn");
  814. }
  815. [Test]
  816. public void OnAuthenticate_False ()
  817. {
  818. OnAuthenticate (false);
  819. }
  820. [Test]
  821. public void OnAuthenticate_True ()
  822. {
  823. OnAuthenticate (true);
  824. }
  825. [Test]
  826. public void OnLoginError ()
  827. {
  828. TestLogin l = new TestLogin ();
  829. l.DoLoginError (EventArgs.Empty);
  830. Assert.IsFalse (l.OnBubbleEventCalled, "OnBubbleEvent");
  831. Assert.IsFalse (l.OnLoggingInCalled, "OnLoggingIn");
  832. Assert.IsFalse (l.OnAuthenticateCalled, "OnAuthenticate");
  833. Assert.IsFalse (l.OnLoginErrorCalled, "OnLoginError");
  834. Assert.IsFalse (l.OnLoggedInCalled, "OnLoggedIn");
  835. }
  836. [Test]
  837. public void OnLoggedIn ()
  838. {
  839. TestLogin l = new TestLogin ();
  840. l.DoLoggedIn (EventArgs.Empty);
  841. Assert.IsFalse (l.OnBubbleEventCalled, "OnBubbleEvent");
  842. Assert.IsFalse (l.OnLoggingInCalled, "OnLoggingIn");
  843. Assert.IsFalse (l.OnAuthenticateCalled, "OnAuthenticate");
  844. Assert.IsFalse (l.OnLoginErrorCalled, "OnLoginError");
  845. Assert.IsFalse (l.OnLoggedInCalled, "OnLoggedIn");
  846. }
  847. [Test]
  848. [Category ("NunitWeb")]
  849. public void PostBackFireEvent_1 ()
  850. {
  851. WebTest t = new WebTest ("NoEventValidation.aspx");
  852. t.Invoker = PageInvoker.CreateOnInit (PostBackFireEvent_Init);
  853. string html = t.Run ();
  854. FormRequest fr = new FormRequest (t.Response, "form1");
  855. fr.Controls.Add ("__EVENTTARGET");
  856. fr.Controls.Add ("__EVENTARGUMENT");
  857. fr.Controls.Add (GetDecoratedId (html, "UserName")); //%24
  858. fr.Controls.Add (GetDecoratedId (html, "Password"));
  859. fr.Controls.Add (GetDecoratedId (html, "LoginButton"));
  860. fr.Controls ["__EVENTTARGET"].Value = "";
  861. fr.Controls ["__EVENTARGUMENT"].Value = "";
  862. fr.Controls ["Login1$UserName"].Value = "yonik";
  863. fr.Controls ["Login1$Password"].Value = "123456";
  864. fr.Controls ["Login1$LoginButton"].Value = "Log In";
  865. t.Request = fr;
  866. t.Run ();
  867. ArrayList eventlist = t.UserData as ArrayList;
  868. if (eventlist == null)
  869. Assert.Fail ("User data does not been created fail");
  870. Assert.AreEqual ("LoggingIn", eventlist [0], "#1");
  871. Assert.AreEqual ("Authenticate", eventlist [1], "#2");
  872. Assert.AreEqual ("LoginError", eventlist [2], "#3");
  873. }
  874. [Test]
  875. [Category ("NunitWeb")]
  876. public void PostBackFireEvent_2 ()
  877. {
  878. WebTest t = new WebTest ("NoEventValidation.aspx");
  879. t.Invoker = PageInvoker.CreateOnInit (PostBackFireEvent_Init_2);
  880. string html = t.Run ();
  881. FormRequest fr = new FormRequest (t.Response, "form1");
  882. fr.Controls.Add ("__EVENTTARGET");
  883. fr.Controls.Add ("__EVENTARGUMENT");
  884. fr.Controls.Add (GetDecoratedId (html, "UserName")); //%24
  885. fr.Controls.Add (GetDecoratedId (html, "Password"));
  886. fr.Controls.Add (GetDecoratedId (html, "LoginButton"));
  887. fr.Controls ["__EVENTTARGET"].Value = "";
  888. fr.Controls ["__EVENTARGUMENT"].Value = "";
  889. fr.Controls ["Login1$UserName"].Value = "yonik";
  890. fr.Controls ["Login1$Password"].Value = "123456";
  891. fr.Controls ["Login1$LoginButton"].Value = "Log In";
  892. t.Request = fr;
  893. t.Run ();
  894. ArrayList eventlist = t.UserData as ArrayList;
  895. if (eventlist == null)
  896. Assert.Fail ("User data does not been created fail");
  897. Assert.AreEqual ("LoggingIn", eventlist [0], "#1");
  898. Assert.AreEqual ("LoggedIn", eventlist [1], "#2");
  899. }
  900. public static void PostBackFireEvent_Init_2 (Page p)
  901. {
  902. Login l = new Login ();
  903. l.LoggedIn += new EventHandler (l_LoggedIn);
  904. l.LoggingIn += new LoginCancelEventHandler (l_LoggingIn);
  905. l.ID = "Login1";
  906. l.MembershipProvider = "FakeProvider";
  907. p.Controls.Add (l);
  908. p.Validate ();
  909. }
  910. public static void PostBackFireEvent_Init (Page p)
  911. {
  912. Login l = new Login ();
  913. l.Authenticate += new AuthenticateEventHandler (Authenticate_Event);
  914. l.LoggedIn += new EventHandler (l_LoggedIn);
  915. l.LoggingIn += new LoginCancelEventHandler (l_LoggingIn);
  916. l.LoginError += new EventHandler (l_LoginError);
  917. l.ID = "Login1";
  918. l.MembershipProvider = "FakeProvider";
  919. p.Controls.Add (l);
  920. p.Validate ();
  921. }
  922. static void l_LoginError (object sender, EventArgs e)
  923. {
  924. if (WebTest.CurrentTest.UserData == null) {
  925. ArrayList list = new ArrayList ();
  926. list.Add ("LoginError");
  927. WebTest.CurrentTest.UserData = list;
  928. }
  929. else {
  930. ArrayList list = WebTest.CurrentTest.UserData as ArrayList;
  931. if (list == null)
  932. throw new NullReferenceException ();
  933. list.Add ("LoginError");
  934. WebTest.CurrentTest.UserData = list;
  935. }
  936. }
  937. static void l_LoggingIn (object sender, LoginCancelEventArgs e)
  938. {
  939. if (WebTest.CurrentTest.UserData == null) {
  940. ArrayList list = new ArrayList ();
  941. list.Add ("LoggingIn");
  942. WebTest.CurrentTest.UserData = list;
  943. }
  944. else {
  945. ArrayList list = WebTest.CurrentTest.UserData as ArrayList;
  946. if (list == null)
  947. throw new NullReferenceException ();
  948. list.Add ("LoggingIn");
  949. WebTest.CurrentTest.UserData = list;
  950. }
  951. }
  952. static void l_LoggedIn (object sender, EventArgs e)
  953. {
  954. if (WebTest.CurrentTest.UserData == null) {
  955. ArrayList list = new ArrayList ();
  956. list.Add ("LoggedIn");
  957. WebTest.CurrentTest.UserData = list;
  958. }
  959. else {
  960. ArrayList list = WebTest.CurrentTest.UserData as ArrayList;
  961. if (list == null)
  962. throw new NullReferenceException ();
  963. list.Add ("LoggedIn");
  964. WebTest.CurrentTest.UserData = list;
  965. }
  966. }
  967. public static void Authenticate_Event (object sender, AuthenticateEventArgs e)
  968. {
  969. if (WebTest.CurrentTest.UserData == null) {
  970. ArrayList list = new ArrayList ();
  971. list.Add ("Authenticate");
  972. WebTest.CurrentTest.UserData = list;
  973. }
  974. else {
  975. ArrayList list = WebTest.CurrentTest.UserData as ArrayList;
  976. if (list == null)
  977. throw new NullReferenceException ();
  978. list.Add ("Authenticate");
  979. WebTest.CurrentTest.UserData = list;
  980. }
  981. }
  982. [Test] // Bug #468359
  983. [Category ("NunitWeb")]
  984. public void DisplayRememberMe ()
  985. {
  986. WebTest t = new WebTest ("LoginDisplayRememberMe.aspx");
  987. string html = t.Run ();
  988. Assert.AreEqual (-1, html.IndexOf ("Login1_RememberMe"), "#A1");
  989. }
  990. [TestFixtureTearDown]
  991. public void Teardown ()
  992. {
  993. WebTest.Unload ();
  994. }
  995. private string GetDecoratedId (string html, string id)
  996. {
  997. Regex reg = new Regex ("name=\".*[\\$\\:]" + id + "\"");
  998. Match match = reg.Match (html);
  999. string fixedId = match.Value;
  1000. if (fixedId.Length > 0)
  1001. fixedId = fixedId.Substring (fixedId.IndexOf ("\""), fixedId.Length - fixedId.IndexOf ("\"")).Trim ('\"');
  1002. return fixedId;
  1003. }
  1004. }
  1005. }
  1006. #endif