2 // ChangePasswordTest.cs - Unit tests for System.Web.UI.WebControls.ChangePassword
5 // Vladimir Krasnov <vladimirk@mainsoft.com>
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Threading;
33 using System.Collections;
34 using System.Globalization;
38 using System.Web.UI.WebControls;
39 using System.Web.Security;
40 using System.Text.RegularExpressions;
41 using MonoTests.SystemWeb.Framework;
42 using MonoTests.stand_alone.WebHarness;
43 using MonoTests.Common;
45 using NUnit.Framework;
46 using System.Collections.Specialized;
47 using System.Web.Configuration;
49 namespace MonoTests.System.Web.UI.WebControls
52 public class TestChangePassword : ChangePassword
57 get { return base.TagName; }
60 public StateBag StateBag
62 get { return base.ViewState; }
65 public string Render ()
67 StringWriter sw = new StringWriter ();
69 HtmlTextWriter writer = new HtmlTextWriter (sw);
71 return writer.InnerWriter.ToString ();
74 public Style GetStyle ()
76 return base.CreateControlStyle ();
79 public void TrackState ()
84 public void LoadState (object state)
86 LoadViewState (state);
89 public object SaveState ()
91 return SaveViewState ();
94 public void SetDesignMode (IDictionary dic)
96 base.SetDesignModeState (dic);
99 private bool onBubble;
101 public bool OnBubbleEventCalled
103 get { return onBubble; }
104 set { onBubble = value; }
107 protected override bool OnBubbleEvent (object source, EventArgs e)
110 return base.OnBubbleEvent (source, e);
113 public bool DoBubbleEvent (object source, EventArgs e)
115 return base.OnBubbleEvent (source, e);
118 public void DoEnsureChildControls ()
120 base.EnsureChildControls ();
123 public bool DoOnBubbleEvent (EventArgs e)
125 return base.OnBubbleEvent (this, e);
131 public class ChangePasswordTest
134 public void CopyTestResources ()
136 WebTest.CopyResource (GetType (), "ChangePasswordContainer_FindControl.aspx", "ChangePasswordContainer_FindControl.aspx");
140 public void DefaultProperties ()
142 CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
143 CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
146 CultureInfo ci = CultureInfo.GetCultureInfo ("en-US");
147 Thread.CurrentThread.CurrentCulture = ci;
148 Thread.CurrentThread.CurrentUICulture = ci;
149 RunDefaultPropertiesTests ();
151 Thread.CurrentThread.CurrentCulture = currentCulture;
152 Thread.CurrentThread.CurrentUICulture = currentUICulture;
156 void RunDefaultPropertiesTests ()
158 TestChangePassword w = new TestChangePassword ();
159 Assert.AreEqual (0, w.Attributes.Count, "Attributes.Count");
160 Assert.AreEqual (0, w.StateBag.Count, "ViewState.Count");
161 Assert.AreEqual (string.Empty, w.CancelButtonImageUrl, "CancelButtonImageUrl");
162 Assert.AreEqual ("Cancel", w.CancelButtonText, "CancelButtonText");
163 Assert.AreEqual (ButtonType.Button, w.CancelButtonType, "CancelButtonType");
164 Assert.AreEqual (string.Empty, w.CancelDestinationPageUrl, "CancelDestinationPageUrl");
165 Assert.AreEqual (string.Empty, w.ChangePasswordButtonImageUrl, "ChangePasswordButtonImageUrl");
166 Assert.AreEqual ("Change Password", w.ChangePasswordButtonText, "ChangePasswordButtonText");
167 Assert.AreEqual (ButtonType.Button, w.ChangePasswordButtonType, "ChangePasswordButtonType");
168 Assert.AreEqual ("Change Your Password", w.ChangePasswordTitleText, "ChangePasswordTitleText");
169 Assert.AreEqual (string.Empty, w.ConfirmNewPassword, "CompleteSuccessText");
170 Assert.AreEqual (string.Empty, w.HelpPageIconUrl, "HelpPageIconUrl");
171 Assert.AreEqual (string.Empty, w.HelpPageText, "HelpPageText");
172 Assert.AreEqual (string.Empty, w.HelpPageUrl, "HelpPageUrl");
173 Assert.AreEqual (string.Empty, w.CreateUserIconUrl, "CreateUserIconUrl");
174 Assert.AreEqual (string.Empty, w.CreateUserText, "CreateUserText");
175 Assert.AreEqual (string.Empty, w.CreateUserUrl, "CreateUserUrl");
176 Assert.AreEqual (string.Empty, w.EditProfileIconUrl, "EditProfileIconUrl");
177 Assert.AreEqual (string.Empty, w.EditProfileText, "EditProfileText");
178 Assert.AreEqual (string.Empty, w.EditProfileUrl, "EditProfileUrl");
179 Assert.AreEqual (string.Empty, w.PasswordRecoveryIconUrl, "PasswordRecoveryIconUrl");
180 Assert.AreEqual (string.Empty, w.PasswordRecoveryText, "PasswordRecoveryText");
181 Assert.AreEqual (string.Empty, w.PasswordRecoveryUrl, "PasswordRecoveryUrl");
182 Assert.AreEqual ("Confirm New Password:", w.ConfirmNewPasswordLabelText, "ConfirmNewPasswordLabelText");
183 Assert.AreEqual ("The Confirm New Password must match the New Password entry.", w.ConfirmPasswordCompareErrorMessage, "ConfirmPasswordCompareErrorMessage");
184 Assert.AreEqual ("Confirm New Password is required.", w.ConfirmPasswordRequiredErrorMessage, "ConfirmPasswordRequiredErrorMessage");
185 Assert.AreEqual (string.Empty, w.ContinueButtonImageUrl, "ContinueButtonImageUrl");
186 Assert.AreEqual ("Continue", w.ContinueButtonText, "ContinueButtonText");
187 Assert.AreEqual (ButtonType.Button, w.ContinueButtonType, "ContinueButtonType");
188 Assert.AreEqual (string.Empty, w.ContinueDestinationPageUrl, "ContinueDestinationPageUrl");
189 Assert.AreEqual (false, w.DisplayUserName, "DisplayUserName");
190 Assert.AreEqual (string.Empty, w.InstructionText, "InstructionText");
191 Assert.AreEqual ("New Password:", w.NewPasswordLabelText, "NewPasswordLabelText");
192 Assert.AreEqual (string.Empty, w.PasswordHintText, "PasswordHintText");
193 Assert.AreEqual ("Password:", w.PasswordLabelText, "PasswordLabelText");
194 Assert.AreEqual (string.Empty, w.SuccessPageUrl, "SuccessPageUrl");
195 Assert.AreEqual ("Your password has been changed!", w.SuccessText, "SuccessText");
196 Assert.AreEqual ("Change Password Complete", w.SuccessTitleText, "SuccessTitleText");
197 Assert.AreEqual ("User Name:", w.UserNameLabelText, "UserNameLabelText");
201 public void AssignToDefaultProperties ()
203 TestChangePassword w = new TestChangePassword ();
204 Assert.AreEqual (0, w.Attributes.Count, "Attributes.Count");
205 Assert.AreEqual (0, w.StateBag.Count, "ViewState.Count");
209 w.CancelButtonImageUrl = "text";
210 Assert.AreEqual ("text", w.CancelButtonImageUrl, "Assign CancelButtonImageUrl,");
211 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelButtonImageUrl,");
213 w.CancelButtonText = "text";
214 Assert.AreEqual ("text", w.CancelButtonText, "Assign CancelButtonText");
215 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelButtonText");
217 w.CancelDestinationPageUrl = "text";
218 Assert.AreEqual ("text", w.CancelDestinationPageUrl, "Assign CancelDestinationPageUrl");
219 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelDestinationPageUrl");
221 w.ChangePasswordButtonImageUrl = "text";
222 Assert.AreEqual ("text", w.ChangePasswordButtonImageUrl, "Assign ChangePasswordButtonImageUrl");
223 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordButtonImageUrl");
225 w.HelpPageText = "text";
226 Assert.AreEqual ("text", w.HelpPageText, "Assign HelpPageText");
227 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageText");
229 w.ChangePasswordButtonText = "text";
230 Assert.AreEqual ("text", w.ChangePasswordButtonText, "Assign ChangePasswordButtonText");
231 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordButtonText");
233 w.ChangePasswordFailureText = "text";
234 Assert.AreEqual ("text", w.ChangePasswordFailureText, "Assign ChangePasswordFailureText");
235 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordFailureText");
237 w.ChangePasswordTitleText = "msg";
238 Assert.AreEqual ("msg", w.ChangePasswordTitleText, "Assign ChangePasswordTitleText");
239 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordTitleText");
241 w.ConfirmNewPasswordLabelText = "msg";
242 Assert.AreEqual ("msg", w.ConfirmNewPasswordLabelText, "Assign ConfirmNewPasswordLabelText");
243 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ConfirmNewPasswordLabelText");
245 w.ContinueButtonImageUrl = "msg";
246 Assert.AreEqual ("msg", w.ContinueButtonImageUrl, "Assign ContinueButtonImageUrl");
247 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueButtonImageUrl");
249 w.ContinueButtonText = "msg";
250 Assert.AreEqual ("msg", w.ContinueButtonText, "Assign ContinueButtonText");
251 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueButtonText");
253 w.ContinueDestinationPageUrl = "msg";
254 Assert.AreEqual ("msg", w.ContinueDestinationPageUrl, "Assign ContinueDestinationPageUrl");
255 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueDestinationPageUrl");
257 w.CreateUserIconUrl = "msg";
258 Assert.AreEqual ("msg", w.CreateUserIconUrl, "Assign CreateUserIconUrl");
259 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserIconUrl");
261 w.CreateUserText = "msg";
262 Assert.AreEqual ("msg", w.CreateUserText, "Assign CreateUserText");
263 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserText");
265 w.CreateUserUrl = "msg";
266 Assert.AreEqual ("msg", w.CreateUserUrl, "Assign CreateUserUrl");
267 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserUrl");
269 w.DisplayUserName = true;
270 Assert.AreEqual (true, w.DisplayUserName, "Assign DisplayUserName");
271 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate DisplayUserName");
273 w.EditProfileIconUrl = "msg";
274 Assert.AreEqual ("msg", w.EditProfileIconUrl, "Assign EditProfileIconUrl");
275 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate EditProfileIconUrl");
277 w.EditProfileText = "msg";
278 Assert.AreEqual ("msg", w.EditProfileText, "Assign EditProfileText");
279 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate EditProfileText");
281 w.HelpPageIconUrl = "msg";
282 Assert.AreEqual ("msg", w.HelpPageIconUrl, "Assign HelpPageIconUrl");
283 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageIconUrl");
285 w.HelpPageUrl = "msg";
286 Assert.AreEqual ("msg", w.HelpPageUrl, "Assign HelpPageUrl");
287 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageUrl");
289 w.InstructionText = "msg";
290 Assert.AreEqual ("msg", w.InstructionText, "Assign InstructionText");
291 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate InstructionText");
293 w.MembershipProvider = "msg";
294 Assert.AreEqual ("msg", w.MembershipProvider, "Assign MembershipProvider");
295 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate MembershipProvider");
297 w.NewPasswordLabelText = "msg";
298 Assert.AreEqual ("msg", w.NewPasswordLabelText, "Assign NewPasswordLabelText");
299 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate NewPasswordLabelText");
301 w.PasswordHintText = "msg";
302 Assert.AreEqual ("msg", w.PasswordHintText, "Assign PasswordHintText");
303 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordHintText");
305 w.PasswordLabelText = "msg";
306 Assert.AreEqual ("msg", w.PasswordLabelText, "Assign PasswordLabelText");
307 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordLabelText");
309 w.PasswordRecoveryIconUrl = "msg";
310 Assert.AreEqual ("msg", w.PasswordRecoveryIconUrl, "Assign PasswordRecoveryIconUrl");
311 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryIconUrl");
313 w.PasswordRecoveryText = "msg";
314 Assert.AreEqual ("msg", w.PasswordRecoveryText, "Assign PasswordRecoveryText");
315 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryText");
317 w.PasswordRecoveryUrl = "msg";
318 Assert.AreEqual ("msg", w.PasswordRecoveryUrl, "Assign PasswordRecoveryUrl");
319 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryUrl");
321 w.PasswordRequiredErrorMessage = "msg";
322 Assert.AreEqual ("msg", w.PasswordRequiredErrorMessage, "Assign PasswordRequiredErrorMessage");
323 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRequiredErrorMessage");
325 w.SuccessPageUrl = "msg";
326 Assert.AreEqual ("msg", w.SuccessPageUrl, "Assign SuccessPageUrl");
327 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessPageUrl");
329 w.SuccessText = "msg";
330 Assert.AreEqual ("msg", w.SuccessText, "Assign SuccessText");
331 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessText");
333 w.SuccessTitleText = "msg";
334 Assert.AreEqual ("msg", w.SuccessTitleText, "Assign SuccessTitleText");
335 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessTitleText");
337 w.UserNameLabelText = "msg";
338 Assert.AreEqual ("msg", w.UserNameLabelText, "Assign UserNameLabelText");
339 Assert.AreEqual (++count, w.StateBag.Count, "Viewstate UserNameLabelText");
342 public static void BasicRenderTestInit (Page p)
344 CreateTestControl (p);
347 public static ChangePassword CreateTestControl (Page p)
349 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
350 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
352 ChangePassword w = new ChangePassword ();
353 w.ID = "ChangePassword1";
354 w.DisplayUserName = true;
355 w.MembershipProvider = "FakeProvider";
356 p.Form.Controls.Add (lcb);
357 p.Form.Controls.Add (w);
358 p.Form.Controls.Add (lce);
364 [Category ("NunitWeb")]
365 public void BasicRenderTest ()
367 string html = new WebTest (PageInvoker.CreateOnLoad (
368 new PageDelegate (BasicRenderTestInit))).Run ();
371 Assert.IsTrue ((st = html.IndexOf ("<table", st)) > 0, "base render test 1");
372 Assert.IsTrue ((st = html.IndexOf ("ChangePassword1", st)) > 0, "base render test 2");
373 Assert.IsTrue ((st = html.IndexOf ("border-collapse:collapse", st)) > 0, "base render test 3");
374 Assert.IsTrue ((st = html.IndexOf ("<table", st)) > 0, "base render test 4");
375 Assert.IsTrue ((st = html.IndexOf ("Change Your Password", st)) > 0, "base render test 5");
376 Assert.IsTrue ((st = html.IndexOf ("User Name:", st)) > 0, "base render test 6");
377 Assert.IsTrue ((st = html.IndexOf ("Password:", st)) > 0, "base render test 7");
378 Assert.IsTrue ((st = html.IndexOf ("New Password:", st)) > 0, "base render test 8");
379 Assert.IsTrue ((st = html.IndexOf ("Change Password", st)) > 0, "base render test 9");
383 [Category ("NunitWeb")]
384 public void TitlesRenderTest ()
386 string html = new WebTest (PageInvoker.CreateOnLoad (
387 new PageDelegate (TitlesRenderTestInit))).Run ();
389 Assert.IsTrue (html.IndexOf ("userid") > 0, "UserNameLabelText");
390 Assert.IsTrue (html.IndexOf ("PasswordLabelText") > 0, "PasswordLabelText");
391 Assert.IsTrue (html.IndexOf ("NewPasswordLabelText") > 0, "NewPasswordLabelText");
392 Assert.IsTrue (html.IndexOf ("ConfirmNewPasswordLabelText") > 0, "ConfirmNewPasswordLabelText");
393 Assert.IsTrue (html.IndexOf ("InstructionText") > 0, "InstructionText");
394 Assert.IsTrue (html.IndexOf ("PasswordHintText") > 0, "PasswordHintText");
395 Assert.IsTrue (html.IndexOf ("zzxcmnmncx") > 0, "zzxcmnmncx");
398 public static void TitlesRenderTestInit (Page p)
400 ChangePassword w = CreateTestControl (p);
401 w.UserNameLabelText = "userid";
402 w.PasswordLabelText = "PasswordLabelText";
403 w.NewPasswordLabelText = "NewPasswordLabelText";
404 w.ConfirmNewPasswordLabelText = "ConfirmNewPasswordLabelText";
405 w.InstructionText = "InstructionText";
406 w.PasswordHintText = "PasswordHintText";
407 w.ChangePasswordButtonText = "zzxcmnmncx";
411 [Category ("NunitWeb")]
412 public void ExtraTitlesRenderTest ()
414 string html = new WebTest (PageInvoker.CreateOnLoad (
415 new PageDelegate (ExtraTitlesRenderTestInit))).Run ();
417 Assert.IsTrue (html.IndexOf ("PasswordHintText") > 0, "PasswordHintText");
418 Assert.IsTrue (html.IndexOf ("http://www.HelpPageUrl.com") > 0, "HelpPageUrl");
419 Assert.IsTrue (html.IndexOf ("HelpPageText") > 0, "HelpPageText");
420 Assert.IsTrue (html.IndexOf ("http://www.HelpPageIconUrl.com") > 0, "HelpPageIconUrl");
421 Assert.IsTrue (html.IndexOf ("CreateUserIconUrl") > 0, "CreateUserIconUrl");
422 Assert.IsTrue (html.IndexOf ("CreateUserText") > 0, "CreateUserText");
423 Assert.IsTrue (html.IndexOf ("CreateUserUrl") > 0, "CreateUserUrl");
426 public static void ExtraTitlesRenderTestInit (Page p)
428 ChangePassword w = CreateTestControl (p);
429 w.HelpPageUrl = "http://www.HelpPageUrl.com";
430 w.HelpPageText = "HelpPageText";
431 w.HelpPageIconUrl = "http://www.HelpPageIconUrl.com";
432 w.CreateUserIconUrl = "CreateUserIconUrl";
433 w.CreateUserText = "CreateUserText";
434 w.CreateUserUrl = "CreateUserUrl";
435 w.PasswordHintText = "PasswordHintText";
439 [Category ("NunitWeb")]
440 public void StylesRenderTest ()
442 string html = new WebTest (PageInvoker.CreateOnLoad (
443 new PageDelegate (StylesRenderTestInit))).Run ();
445 Assert.IsTrue (html.IndexOf ("LightGoldenrodYellow;") > 0, "TextBoxStyle");
446 Assert.IsTrue (html.IndexOf ("732px") > 0, "TitleTextStyle");
447 Assert.IsTrue (html.IndexOf ("LightSkyBlue;") > 0, "HyperLinkStyle");
448 Assert.IsTrue (html.IndexOf ("MediumSeaGreen;") > 0, "InstructionTextStyle");
449 Assert.IsTrue (html.IndexOf ("MediumSpringGreen;") > 0, "LabelStyle");
452 private string GetDecoratedId (string html, string id)
454 Regex reg = new Regex ("name=\".*[\\$\\:]" + id + "\"");
455 Match match = reg.Match (html);
457 string fixedId = match.Value;
458 if (fixedId.Length > 0)
459 fixedId = fixedId.Substring (fixedId.IndexOf ("\""), fixedId.Length - fixedId.IndexOf ("\"")).Trim ('\"');
464 private static string GetEventTarget (string html, string id)
466 Regex reg = new Regex ("__doPostBack.*\\(.*'.*" + id + "'");
467 Match match = reg.Match (html);
469 string fixedId = match.Value;
470 if (fixedId.Length > 0)
471 fixedId = fixedId.Substring (fixedId.IndexOf ("'"), fixedId.Length - fixedId.IndexOf ("'")).Trim ('\'');
477 [Category ("NunitWeb")]
478 public void BasicPostbackTest ()
480 PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (StylesRenderTestInit));
481 WebTest test = new WebTest (pi);
483 string html = test.Run ();
486 FormRequest fr = new FormRequest (test.Response, "form1");
488 fr.Controls.Add (new BaseControl (GetDecoratedId (html, "UserName"), "username"));
490 PageDelegates pd = new PageDelegates ();
491 pd.PreRender = new PageDelegate (BasicPostTestPreRender);
492 pd.Load = new PageDelegate (StylesRenderTestInit);
498 Assert.IsTrue (html.IndexOf ("username") > 0, "rendered user name");
500 Assert.IsTrue (html.IndexOf ("LightGoldenrodYellow;") > 0, "TextBoxStyle");
501 Assert.IsTrue (html.IndexOf ("732px") > 0, "TitleTextStyle");
502 Assert.IsTrue (html.IndexOf ("LightSkyBlue;") > 0, "HyperLinkStyle");
503 Assert.IsTrue (html.IndexOf ("MediumSeaGreen;") > 0, "InstructionTextStyle");
504 Assert.IsTrue (html.IndexOf ("MediumSpringGreen;") > 0, "LabelStyle");
505 Assert.IsTrue (html.IndexOf ("PeachPuff;") > 0, "LabelStyle");
508 public static void BasicPostTestPreRender (Page p)
510 ChangePassword w = (ChangePassword) p.FindControl ("ChangePassword1");
512 Assert.Fail ("postback1");
514 Assert.AreEqual ("username", w.UserName, "posted user name");
517 public static void StylesRenderTestInit (Page p)
519 ChangePassword w = CreateTestControl (p);
520 w.MembershipProvider = "FakeProvider";
521 w.SendingMail += new MailMessageEventHandler(w_SendingMail);
522 w.SendMailError += new SendMailErrorEventHandler(w_SendMailError);
523 w.DisplayUserName = true;
526 w.TextBoxStyle.BackColor = Color.LightGoldenrodYellow;
527 w.TitleTextStyle.Height = Unit.Pixel (732);
528 w.LabelStyle.BackColor = Color.MediumSpringGreen;
530 w.HelpPageUrl = "http://www.HelpPageUrl.com";
531 w.HelpPageText = "hhh";
532 w.HyperLinkStyle.BackColor = Color.LightSkyBlue;
534 w.InstructionText = "text";
535 w.InstructionTextStyle.BackColor = Color.MediumSeaGreen;
537 w.PasswordHintText = "PasswordHintText";
538 w.PasswordHintStyle.BackColor = Color.PeachPuff;
542 public static void w_SendingMail (object sender, MailMessageEventArgs e)
544 if (e.Message.Body.IndexOf ("123") > 0)
545 WebTest.CurrentTest.UserData = "w_SendingMail";
548 public static void w_SendMailError (object sender, SendMailErrorEventArgs e)
554 // ValidatorTextStyle
557 [Category ("NotDotNet")]
558 [Category ("NunitWeb")]
559 public void ChngPasswordTest ()
561 PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (StylesRenderTestInit));
562 WebTest test = new WebTest (pi);
564 string html = test.Run ();
567 FormRequest fr = new FormRequest (test.Response, "form1");
569 fr.Controls.Add (new BaseControl (GetDecoratedId (html, "UserName"), "heh"));
570 fr.Controls.Add (new BaseControl (GetDecoratedId (html, "CurrentPassword"), "heh"));
571 fr.Controls.Add (new BaseControl (GetDecoratedId (html, "NewPassword"), "hehe"));
572 fr.Controls.Add (new BaseControl (GetDecoratedId (html, "ConfirmNewPassword"), "hehe"));
573 string button = GetDecoratedId (html, "ChangePasswordPushButton");
574 if (button.Length > 0)
575 fr.Controls.Add (new BaseControl (GetDecoratedId (html, "ChangePasswordPushButton"), "ChangePasswordPushButton"));
577 fr.Controls.Add (new BaseControl ("__EVENTTARGET", GetEventTarget (html, "ChangePassword")));
581 Assert.IsTrue (html.IndexOf ("has been changed") > 0, "GetPassword");
585 [Category ("NunitWeb")]
586 public void PostBackEventCancel ()
588 WebTest t = new WebTest ();
589 t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventCancel));
590 string html = t.Run ();
591 if (html.IndexOf ("Change Your Password") < 0)
592 Assert.Fail ("ChangePassword not created");
593 FormRequest fr = new FormRequest (t.Response, "form1");
594 fr.Controls.Add ("__EVENTTARGET");
595 fr.Controls.Add ("__EVENTARGUMENT");
596 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
597 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
598 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
599 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CancelPushButton");
600 fr.Controls["ChangePassword1$ChangePasswordContainerID$CancelPushButton"].Value = "Cancel";
603 if (t.UserData == null || t.UserData.ToString () != "CancelButtonClick")
604 Assert.Fail ("CancelButtonClick event not fired");
607 public static void _PostBackEventCancel (Page p)
609 ChangePassword w = CreateTestControl (p);
610 w.CancelButtonClick += new EventHandler (w_CancelButtonClick);
613 static void w_CancelButtonClick (object sender, EventArgs e)
615 WebTest.CurrentTest.UserData = "CancelButtonClick";
620 [Category ("NunitWeb")]
621 public void PostBackEventChanging ()
623 WebTest t = new WebTest ();
624 t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventChanging));
625 string html = t.Run ();
626 if (html.IndexOf ("Change Your Password") < 0)
627 Assert.Fail ("ChangePassword not created");
628 FormRequest fr = new FormRequest (t.Response, "form1");
629 fr.Controls.Add ("__EVENTTARGET");
630 fr.Controls.Add ("__EVENTARGUMENT");
632 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
633 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
634 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
636 fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "a";
637 fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "1";
638 fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "1";
639 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
640 fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
643 if (t.UserData == null || t.UserData.ToString () != "ChangingPassword")
644 Assert.Fail ("ChangingPassword event not fired");
647 public static void _PostBackEventChanging (Page p)
649 ChangePassword w = CreateTestControl (p);
650 w.DisplayUserName = false;
651 w.ChangingPassword +=new LoginCancelEventHandler(w_ChangingPassword);
654 public static void w_ChangingPassword (object sender, LoginCancelEventArgs e)
656 WebTest.CurrentTest.UserData = "ChangingPassword";
661 [Category ("NunitWeb")]
662 public void PostBackEventError ()
664 WebTest t = new WebTest ();
665 t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventError));
666 string html = t.Run ();
667 if (html.IndexOf ("Change Your Password") < 0)
668 Assert.Fail ("ChangePassword not created");
669 FormRequest fr = new FormRequest (t.Response, "form1");
670 fr.Controls.Add ("__EVENTTARGET");
671 fr.Controls.Add ("__EVENTARGUMENT");
673 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$UserName");
674 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
675 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
676 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
678 fr.Controls["ChangePassword1$ChangePasswordContainerID$UserName"].Value = "WrongUser";
679 fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "a";
680 fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "1";
681 fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "1";
682 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
683 fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
686 if (t.UserData == null || t.UserData.ToString () != "ChangePasswordError")
687 Assert.Fail ("ChangePasswordError event not fired");
690 public static void _PostBackEventError (Page p)
692 ChangePassword w = CreateTestControl (p);
693 w.ChangePasswordError += new EventHandler (w_ChangePasswordError);
696 public static void w_ChangePasswordError (object sender, EventArgs e)
698 WebTest.CurrentTest.UserData = "ChangePasswordError";
703 [Category ("NunitWeb")]
704 public void PostBackEventChangedPassword ()
706 WebTest t = new WebTest ();
707 t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventChangedPassword));
708 string html = t.Run ();
709 if (html.IndexOf ("Change Your Password") < 0)
710 Assert.Fail ("ChangePassword not created");
711 FormRequest fr = new FormRequest (t.Response, "form1");
712 fr.Controls.Add ("__EVENTTARGET");
713 fr.Controls.Add ("__EVENTARGUMENT");
715 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
716 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
717 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
719 fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "p@ssword";
720 fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "123456?";
721 fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "123456?";
722 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
723 fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
726 if (t.UserData == null || t.UserData.ToString () != "ChangedPassword")
727 Assert.Fail ("ChangedPassword event not fired");
730 public static void _PostBackEventChangedPassword (Page p)
732 ChangePassword w = CreateTestControl (p);
733 w.DisplayUserName = false;
734 w.ChangedPassword += new EventHandler (w_ChangedPassword);
737 public static void w_ChangedPassword (object sender, EventArgs e)
739 WebTest.CurrentTest.UserData = "ChangedPassword";
743 [Category ("NunitWeb")]
744 public void PostBackEventContinue ()
746 WebTest t = new WebTest ();
747 t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventContinue));
748 string html = t.Run ();
749 if (html.IndexOf ("Change Your Password") < 0)
750 Assert.Fail ("ChangePassword not created");
751 FormRequest fr = new FormRequest (t.Response, "form1");
752 fr.Controls.Add ("__EVENTTARGET");
753 fr.Controls.Add ("__EVENTARGUMENT");
755 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
756 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
757 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
758 fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "p@ssword";
759 fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "123456?";
760 fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "123456?";
761 fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
762 fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
766 if (html.IndexOf ("Change Password Complete") < 0)
767 Assert.Fail ("Password has not been changed!");
769 fr = new FormRequest (t.Response, "form1");
770 fr.Controls.Add ("__EVENTTARGET");
771 fr.Controls.Add ("__EVENTARGUMENT");
772 fr.Controls.Add ("ChangePassword1$SuccessContainerID$ContinuePushButton");
773 fr.Controls["ChangePassword1$SuccessContainerID$ContinuePushButton"].Value = "Continue";
778 if (t.UserData == null || t.UserData.ToString () != "ContinueButtonClick")
779 Assert.Fail ("ContinueButtonClick event not fired");
782 public static void _PostBackEventContinue (Page p)
784 ChangePassword w = CreateTestControl (p);
785 w.DisplayUserName = false;
786 w.ContinueButtonClick += new EventHandler (w_ContinueButtonClick);
789 public static void w_ContinueButtonClick (object sender, EventArgs e)
791 WebTest.CurrentTest.UserData = "ContinueButtonClick";
795 [Category ("NunitWeb")]
796 public void DefaultProvider ()
798 WebTest t = new WebTest ();
799 t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_DefaultProvider));
800 string html = t.Run ();
803 public static void _DefaultProvider (Page p)
805 MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");
806 Assert.AreEqual (section.DefaultProvider, "FakeProvider", "section.DefaultProvider");
807 Assert.AreEqual (Membership.Provider.GetType (), typeof (FakeMembershipProvider), "Membership.Provider.GetType ()");
811 public void ChangePasswordContainer_FindControl ()
813 WebTest t = new WebTest ("ChangePasswordContainer_FindControl.aspx");
814 t.Invoker = PageInvoker.CreateOnLoad (new PageDelegate (ChangePasswordContainer_FindControl_OnLoad));
818 public static void ChangePasswordContainer_FindControl_OnLoad (Page p)
820 ChangePassword cp = p.FindControl ("ChangePassword1") as ChangePassword;
821 Assert.IsNotNull (cp, "#A1");
823 RequiredFieldValidator rfv = cp.ChangePasswordTemplateContainer.FindControl ("text1required") as RequiredFieldValidator;
824 Assert.IsNotNull (rfv, "#A2");
828 public void RenderOuterTableForbiddenStyles ()
830 var cp = new ChangePassword ();
831 cp.RenderOuterTable = false;
832 cp.BackColor = Color.Red;
834 TestRenderFailure (cp, "BackColor");
836 cp = new ChangePassword ();
837 cp.RenderOuterTable = false;
838 cp.BorderColor = Color.Red;
839 TestRenderFailure (cp, "BorderColor");
841 cp = new ChangePassword ();
842 cp.RenderOuterTable = false;
843 cp.BorderStyle = BorderStyle.Dashed;
844 TestRenderFailure (cp, "BorderStyle");
846 cp = new ChangePassword ();
847 cp.RenderOuterTable = false;
848 cp.BorderWidth = new Unit (10, UnitType.Pixel);
849 TestRenderFailure (cp, "BorderWidth");
851 cp = new ChangePassword ();
852 cp.RenderOuterTable = false;
853 cp.CssClass = "MyClass";
854 TestRenderFailure (cp, "CssClass");
856 cp = new ChangePassword ();
857 cp.RenderOuterTable = false;
860 TestRenderFailure (cp, "Font", false);
862 cp = new ChangePassword ();
863 cp.RenderOuterTable = false;
864 cp.ForeColor = Color.Red;
865 TestRenderFailure (cp, "ForeColor");
867 cp = new ChangePassword ();
868 cp.RenderOuterTable = false;
869 cp.Height = new Unit (20, UnitType.Pixel);
870 TestRenderFailure (cp, "Height");
872 cp = new ChangePassword ();
873 cp.RenderOuterTable = false;
874 cp.Width = new Unit (20, UnitType.Pixel);
875 TestRenderFailure (cp, "Width");
878 void TestRenderFailure (ChangePassword cp, string message, bool shouldFail = true)
880 using (var sw = new StringWriter ()) {
881 using (var w = new HtmlTextWriter (sw)) {
883 AssertExtensions.Throws<InvalidOperationException> (() => {
884 cp.RenderControl (w);
887 cp.RenderControl (w);
888 Assert.IsTrue (sw.ToString ().Length > 0, message);
894 [TestFixtureTearDown]
895 public void TearDown ()