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 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
|
//
// ChangePasswordTest.cs - Unit tests for System.Web.UI.WebControls.ChangePassword
//
// Author:
// Vladimir Krasnov <vladimirk@mainsoft.com>
//
// (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.
//
using System;
using System.Drawing;
using System.Threading;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text.RegularExpressions;
using MonoTests.SystemWeb.Framework;
using MonoTests.stand_alone.WebHarness;
using MonoTests.Common;
using NUnit.Framework;
using System.Collections.Specialized;
using System.Web.Configuration;
namespace MonoTests.System.Web.UI.WebControls
{
public class TestChangePassword : ChangePassword
{
public string Tag
{
get { return base.TagName; }
}
public StateBag StateBag
{
get { return base.ViewState; }
}
public string Render ()
{
StringWriter sw = new StringWriter ();
sw.NewLine = "\n";
HtmlTextWriter writer = new HtmlTextWriter (sw);
base.Render (writer);
return writer.InnerWriter.ToString ();
}
public Style GetStyle ()
{
return base.CreateControlStyle ();
}
public void TrackState ()
{
TrackViewState ();
}
public void LoadState (object state)
{
LoadViewState (state);
}
public object SaveState ()
{
return SaveViewState ();
}
public void SetDesignMode (IDictionary dic)
{
base.SetDesignModeState (dic);
}
private bool onBubble;
public bool OnBubbleEventCalled
{
get { return onBubble; }
set { onBubble = value; }
}
protected override bool OnBubbleEvent (object source, EventArgs e)
{
onBubble = true;
return base.OnBubbleEvent (source, e);
}
public bool DoBubbleEvent (object source, EventArgs e)
{
return base.OnBubbleEvent (source, e);
}
public void DoEnsureChildControls ()
{
base.EnsureChildControls ();
}
public bool DoOnBubbleEvent (EventArgs e)
{
return base.OnBubbleEvent (this, e);
}
}
[Serializable]
[TestFixture]
public class ChangePasswordTest
{
[TestFixtureSetUp]
public void CopyTestResources ()
{
WebTest.CopyResource (GetType (), "ChangePasswordContainer_FindControl.aspx", "ChangePasswordContainer_FindControl.aspx");
}
[Test]
public void DefaultProperties ()
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
try {
CultureInfo ci = CultureInfo.GetCultureInfo ("en-US");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
RunDefaultPropertiesTests ();
} finally {
Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentUICulture;
}
}
void RunDefaultPropertiesTests ()
{
TestChangePassword w = new TestChangePassword ();
Assert.AreEqual (0, w.Attributes.Count, "Attributes.Count");
Assert.AreEqual (0, w.StateBag.Count, "ViewState.Count");
Assert.AreEqual (string.Empty, w.CancelButtonImageUrl, "CancelButtonImageUrl");
Assert.AreEqual ("Cancel", w.CancelButtonText, "CancelButtonText");
Assert.AreEqual (ButtonType.Button, w.CancelButtonType, "CancelButtonType");
Assert.AreEqual (string.Empty, w.CancelDestinationPageUrl, "CancelDestinationPageUrl");
Assert.AreEqual (string.Empty, w.ChangePasswordButtonImageUrl, "ChangePasswordButtonImageUrl");
Assert.AreEqual ("Change Password", w.ChangePasswordButtonText, "ChangePasswordButtonText");
Assert.AreEqual (ButtonType.Button, w.ChangePasswordButtonType, "ChangePasswordButtonType");
Assert.AreEqual ("Change Your Password", w.ChangePasswordTitleText, "ChangePasswordTitleText");
Assert.AreEqual (string.Empty, w.ConfirmNewPassword, "CompleteSuccessText");
Assert.AreEqual (string.Empty, w.HelpPageIconUrl, "HelpPageIconUrl");
Assert.AreEqual (string.Empty, w.HelpPageText, "HelpPageText");
Assert.AreEqual (string.Empty, w.HelpPageUrl, "HelpPageUrl");
Assert.AreEqual (string.Empty, w.CreateUserIconUrl, "CreateUserIconUrl");
Assert.AreEqual (string.Empty, w.CreateUserText, "CreateUserText");
Assert.AreEqual (string.Empty, w.CreateUserUrl, "CreateUserUrl");
Assert.AreEqual (string.Empty, w.EditProfileIconUrl, "EditProfileIconUrl");
Assert.AreEqual (string.Empty, w.EditProfileText, "EditProfileText");
Assert.AreEqual (string.Empty, w.EditProfileUrl, "EditProfileUrl");
Assert.AreEqual (string.Empty, w.PasswordRecoveryIconUrl, "PasswordRecoveryIconUrl");
Assert.AreEqual (string.Empty, w.PasswordRecoveryText, "PasswordRecoveryText");
Assert.AreEqual (string.Empty, w.PasswordRecoveryUrl, "PasswordRecoveryUrl");
Assert.AreEqual ("Confirm New Password:", w.ConfirmNewPasswordLabelText, "ConfirmNewPasswordLabelText");
Assert.AreEqual ("The Confirm New Password must match the New Password entry.", w.ConfirmPasswordCompareErrorMessage, "ConfirmPasswordCompareErrorMessage");
Assert.AreEqual ("Confirm New Password is required.", w.ConfirmPasswordRequiredErrorMessage, "ConfirmPasswordRequiredErrorMessage");
Assert.AreEqual (string.Empty, w.ContinueButtonImageUrl, "ContinueButtonImageUrl");
Assert.AreEqual ("Continue", w.ContinueButtonText, "ContinueButtonText");
Assert.AreEqual (ButtonType.Button, w.ContinueButtonType, "ContinueButtonType");
Assert.AreEqual (string.Empty, w.ContinueDestinationPageUrl, "ContinueDestinationPageUrl");
Assert.AreEqual (false, w.DisplayUserName, "DisplayUserName");
Assert.AreEqual (string.Empty, w.InstructionText, "InstructionText");
Assert.AreEqual ("New Password:", w.NewPasswordLabelText, "NewPasswordLabelText");
Assert.AreEqual (string.Empty, w.PasswordHintText, "PasswordHintText");
Assert.AreEqual ("Password:", w.PasswordLabelText, "PasswordLabelText");
Assert.AreEqual (string.Empty, w.SuccessPageUrl, "SuccessPageUrl");
Assert.AreEqual ("Your password has been changed!", w.SuccessText, "SuccessText");
Assert.AreEqual ("Change Password Complete", w.SuccessTitleText, "SuccessTitleText");
Assert.AreEqual ("User Name:", w.UserNameLabelText, "UserNameLabelText");
}
[Test]
public void AssignToDefaultProperties ()
{
TestChangePassword w = new TestChangePassword ();
Assert.AreEqual (0, w.Attributes.Count, "Attributes.Count");
Assert.AreEqual (0, w.StateBag.Count, "ViewState.Count");
int count = 0;
w.CancelButtonImageUrl = "text";
Assert.AreEqual ("text", w.CancelButtonImageUrl, "Assign CancelButtonImageUrl,");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelButtonImageUrl,");
w.CancelButtonText = "text";
Assert.AreEqual ("text", w.CancelButtonText, "Assign CancelButtonText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelButtonText");
w.CancelDestinationPageUrl = "text";
Assert.AreEqual ("text", w.CancelDestinationPageUrl, "Assign CancelDestinationPageUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelDestinationPageUrl");
w.ChangePasswordButtonImageUrl = "text";
Assert.AreEqual ("text", w.ChangePasswordButtonImageUrl, "Assign ChangePasswordButtonImageUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordButtonImageUrl");
w.HelpPageText = "text";
Assert.AreEqual ("text", w.HelpPageText, "Assign HelpPageText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageText");
w.ChangePasswordButtonText = "text";
Assert.AreEqual ("text", w.ChangePasswordButtonText, "Assign ChangePasswordButtonText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordButtonText");
w.ChangePasswordFailureText = "text";
Assert.AreEqual ("text", w.ChangePasswordFailureText, "Assign ChangePasswordFailureText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordFailureText");
w.ChangePasswordTitleText = "msg";
Assert.AreEqual ("msg", w.ChangePasswordTitleText, "Assign ChangePasswordTitleText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordTitleText");
w.ConfirmNewPasswordLabelText = "msg";
Assert.AreEqual ("msg", w.ConfirmNewPasswordLabelText, "Assign ConfirmNewPasswordLabelText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ConfirmNewPasswordLabelText");
w.ContinueButtonImageUrl = "msg";
Assert.AreEqual ("msg", w.ContinueButtonImageUrl, "Assign ContinueButtonImageUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueButtonImageUrl");
w.ContinueButtonText = "msg";
Assert.AreEqual ("msg", w.ContinueButtonText, "Assign ContinueButtonText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueButtonText");
w.ContinueDestinationPageUrl = "msg";
Assert.AreEqual ("msg", w.ContinueDestinationPageUrl, "Assign ContinueDestinationPageUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueDestinationPageUrl");
w.CreateUserIconUrl = "msg";
Assert.AreEqual ("msg", w.CreateUserIconUrl, "Assign CreateUserIconUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserIconUrl");
w.CreateUserText = "msg";
Assert.AreEqual ("msg", w.CreateUserText, "Assign CreateUserText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserText");
w.CreateUserUrl = "msg";
Assert.AreEqual ("msg", w.CreateUserUrl, "Assign CreateUserUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserUrl");
w.DisplayUserName = true;
Assert.AreEqual (true, w.DisplayUserName, "Assign DisplayUserName");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate DisplayUserName");
w.EditProfileIconUrl = "msg";
Assert.AreEqual ("msg", w.EditProfileIconUrl, "Assign EditProfileIconUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate EditProfileIconUrl");
w.EditProfileText = "msg";
Assert.AreEqual ("msg", w.EditProfileText, "Assign EditProfileText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate EditProfileText");
w.HelpPageIconUrl = "msg";
Assert.AreEqual ("msg", w.HelpPageIconUrl, "Assign HelpPageIconUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageIconUrl");
w.HelpPageUrl = "msg";
Assert.AreEqual ("msg", w.HelpPageUrl, "Assign HelpPageUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageUrl");
w.InstructionText = "msg";
Assert.AreEqual ("msg", w.InstructionText, "Assign InstructionText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate InstructionText");
w.MembershipProvider = "msg";
Assert.AreEqual ("msg", w.MembershipProvider, "Assign MembershipProvider");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate MembershipProvider");
w.NewPasswordLabelText = "msg";
Assert.AreEqual ("msg", w.NewPasswordLabelText, "Assign NewPasswordLabelText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate NewPasswordLabelText");
w.PasswordHintText = "msg";
Assert.AreEqual ("msg", w.PasswordHintText, "Assign PasswordHintText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordHintText");
w.PasswordLabelText = "msg";
Assert.AreEqual ("msg", w.PasswordLabelText, "Assign PasswordLabelText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordLabelText");
w.PasswordRecoveryIconUrl = "msg";
Assert.AreEqual ("msg", w.PasswordRecoveryIconUrl, "Assign PasswordRecoveryIconUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryIconUrl");
w.PasswordRecoveryText = "msg";
Assert.AreEqual ("msg", w.PasswordRecoveryText, "Assign PasswordRecoveryText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryText");
w.PasswordRecoveryUrl = "msg";
Assert.AreEqual ("msg", w.PasswordRecoveryUrl, "Assign PasswordRecoveryUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryUrl");
w.PasswordRequiredErrorMessage = "msg";
Assert.AreEqual ("msg", w.PasswordRequiredErrorMessage, "Assign PasswordRequiredErrorMessage");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRequiredErrorMessage");
w.SuccessPageUrl = "msg";
Assert.AreEqual ("msg", w.SuccessPageUrl, "Assign SuccessPageUrl");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessPageUrl");
w.SuccessText = "msg";
Assert.AreEqual ("msg", w.SuccessText, "Assign SuccessText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessText");
w.SuccessTitleText = "msg";
Assert.AreEqual ("msg", w.SuccessTitleText, "Assign SuccessTitleText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessTitleText");
w.UserNameLabelText = "msg";
Assert.AreEqual ("msg", w.UserNameLabelText, "Assign UserNameLabelText");
Assert.AreEqual (++count, w.StateBag.Count, "Viewstate UserNameLabelText");
}
public static void BasicRenderTestInit (Page p)
{
CreateTestControl (p);
}
public static ChangePassword CreateTestControl (Page p)
{
LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
ChangePassword w = new ChangePassword ();
w.ID = "ChangePassword1";
w.DisplayUserName = true;
w.MembershipProvider = "FakeProvider";
p.Form.Controls.Add (lcb);
p.Form.Controls.Add (w);
p.Form.Controls.Add (lce);
return w;
}
[Test]
[Category ("NunitWeb")]
public void BasicRenderTest ()
{
string html = new WebTest (PageInvoker.CreateOnLoad (
new PageDelegate (BasicRenderTestInit))).Run ();
int st = 0;
Assert.IsTrue ((st = html.IndexOf ("<table", st)) > 0, "base render test 1");
Assert.IsTrue ((st = html.IndexOf ("ChangePassword1", st)) > 0, "base render test 2");
Assert.IsTrue ((st = html.IndexOf ("border-collapse:collapse", st)) > 0, "base render test 3");
Assert.IsTrue ((st = html.IndexOf ("<table", st)) > 0, "base render test 4");
Assert.IsTrue ((st = html.IndexOf ("Change Your Password", st)) > 0, "base render test 5");
Assert.IsTrue ((st = html.IndexOf ("User Name:", st)) > 0, "base render test 6");
Assert.IsTrue ((st = html.IndexOf ("Password:", st)) > 0, "base render test 7");
Assert.IsTrue ((st = html.IndexOf ("New Password:", st)) > 0, "base render test 8");
Assert.IsTrue ((st = html.IndexOf ("Change Password", st)) > 0, "base render test 9");
}
[Test]
[Category ("NunitWeb")]
public void TitlesRenderTest ()
{
string html = new WebTest (PageInvoker.CreateOnLoad (
new PageDelegate (TitlesRenderTestInit))).Run ();
Assert.IsTrue (html.IndexOf ("userid") > 0, "UserNameLabelText");
Assert.IsTrue (html.IndexOf ("PasswordLabelText") > 0, "PasswordLabelText");
Assert.IsTrue (html.IndexOf ("NewPasswordLabelText") > 0, "NewPasswordLabelText");
Assert.IsTrue (html.IndexOf ("ConfirmNewPasswordLabelText") > 0, "ConfirmNewPasswordLabelText");
Assert.IsTrue (html.IndexOf ("InstructionText") > 0, "InstructionText");
Assert.IsTrue (html.IndexOf ("PasswordHintText") > 0, "PasswordHintText");
Assert.IsTrue (html.IndexOf ("zzxcmnmncx") > 0, "zzxcmnmncx");
}
public static void TitlesRenderTestInit (Page p)
{
ChangePassword w = CreateTestControl (p);
w.UserNameLabelText = "userid";
w.PasswordLabelText = "PasswordLabelText";
w.NewPasswordLabelText = "NewPasswordLabelText";
w.ConfirmNewPasswordLabelText = "ConfirmNewPasswordLabelText";
w.InstructionText = "InstructionText";
w.PasswordHintText = "PasswordHintText";
w.ChangePasswordButtonText = "zzxcmnmncx";
}
[Test]
[Category ("NunitWeb")]
public void ExtraTitlesRenderTest ()
{
string html = new WebTest (PageInvoker.CreateOnLoad (
new PageDelegate (ExtraTitlesRenderTestInit))).Run ();
Assert.IsTrue (html.IndexOf ("PasswordHintText") > 0, "PasswordHintText");
Assert.IsTrue (html.IndexOf ("http://www.HelpPageUrl.com") > 0, "HelpPageUrl");
Assert.IsTrue (html.IndexOf ("HelpPageText") > 0, "HelpPageText");
Assert.IsTrue (html.IndexOf ("http://www.HelpPageIconUrl.com") > 0, "HelpPageIconUrl");
Assert.IsTrue (html.IndexOf ("CreateUserIconUrl") > 0, "CreateUserIconUrl");
Assert.IsTrue (html.IndexOf ("CreateUserText") > 0, "CreateUserText");
Assert.IsTrue (html.IndexOf ("CreateUserUrl") > 0, "CreateUserUrl");
}
public static void ExtraTitlesRenderTestInit (Page p)
{
ChangePassword w = CreateTestControl (p);
w.HelpPageUrl = "http://www.HelpPageUrl.com";
w.HelpPageText = "HelpPageText";
w.HelpPageIconUrl = "http://www.HelpPageIconUrl.com";
w.CreateUserIconUrl = "CreateUserIconUrl";
w.CreateUserText = "CreateUserText";
w.CreateUserUrl = "CreateUserUrl";
w.PasswordHintText = "PasswordHintText";
}
[Test]
[Category ("NunitWeb")]
public void StylesRenderTest ()
{
string html = new WebTest (PageInvoker.CreateOnLoad (
new PageDelegate (StylesRenderTestInit))).Run ();
Assert.IsTrue (html.IndexOf ("LightGoldenrodYellow;") > 0, "TextBoxStyle");
Assert.IsTrue (html.IndexOf ("732px") > 0, "TitleTextStyle");
Assert.IsTrue (html.IndexOf ("LightSkyBlue;") > 0, "HyperLinkStyle");
Assert.IsTrue (html.IndexOf ("MediumSeaGreen;") > 0, "InstructionTextStyle");
Assert.IsTrue (html.IndexOf ("MediumSpringGreen;") > 0, "LabelStyle");
}
private string GetDecoratedId (string html, string id)
{
Regex reg = new Regex ("name=\".*[\\$\\:]" + id + "\"");
Match match = reg.Match (html);
string fixedId = match.Value;
if (fixedId.Length > 0)
fixedId = fixedId.Substring (fixedId.IndexOf ("\""), fixedId.Length - fixedId.IndexOf ("\"")).Trim ('\"');
return fixedId;
}
private static string GetEventTarget (string html, string id)
{
Regex reg = new Regex ("__doPostBack.*\\(.*'.*" + id + "'");
Match match = reg.Match (html);
string fixedId = match.Value;
if (fixedId.Length > 0)
fixedId = fixedId.Substring (fixedId.IndexOf ("'"), fixedId.Length - fixedId.IndexOf ("'")).Trim ('\'');
return fixedId;
}
[Test]
[Category ("NunitWeb")]
public void BasicPostbackTest ()
{
PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (StylesRenderTestInit));
WebTest test = new WebTest (pi);
string html = test.Run ();
test.Invoker = pi;
FormRequest fr = new FormRequest (test.Response, "form1");
fr.Controls.Add (new BaseControl (GetDecoratedId (html, "UserName"), "username"));
PageDelegates pd = new PageDelegates ();
pd.PreRender = new PageDelegate (BasicPostTestPreRender);
pd.Load = new PageDelegate (StylesRenderTestInit);
pi.Delegates = pd;
test.Request = fr;
html = test.Run ();
Assert.IsTrue (html.IndexOf ("username") > 0, "rendered user name");
Assert.IsTrue (html.IndexOf ("LightGoldenrodYellow;") > 0, "TextBoxStyle");
Assert.IsTrue (html.IndexOf ("732px") > 0, "TitleTextStyle");
Assert.IsTrue (html.IndexOf ("LightSkyBlue;") > 0, "HyperLinkStyle");
Assert.IsTrue (html.IndexOf ("MediumSeaGreen;") > 0, "InstructionTextStyle");
Assert.IsTrue (html.IndexOf ("MediumSpringGreen;") > 0, "LabelStyle");
Assert.IsTrue (html.IndexOf ("PeachPuff;") > 0, "LabelStyle");
}
public static void BasicPostTestPreRender (Page p)
{
ChangePassword w = (ChangePassword) p.FindControl ("ChangePassword1");
if (w == null)
Assert.Fail ("postback1");
Assert.AreEqual ("username", w.UserName, "posted user name");
}
public static void StylesRenderTestInit (Page p)
{
ChangePassword w = CreateTestControl (p);
w.MembershipProvider = "FakeProvider";
w.SendingMail += new MailMessageEventHandler(w_SendingMail);
w.SendMailError += new SendMailErrorEventHandler(w_SendMailError);
w.DisplayUserName = true;
if (!p.IsPostBack) {
w.TextBoxStyle.BackColor = Color.LightGoldenrodYellow;
w.TitleTextStyle.Height = Unit.Pixel (732);
w.LabelStyle.BackColor = Color.MediumSpringGreen;
w.HelpPageUrl = "http://www.HelpPageUrl.com";
w.HelpPageText = "hhh";
w.HyperLinkStyle.BackColor = Color.LightSkyBlue;
w.InstructionText = "text";
w.InstructionTextStyle.BackColor = Color.MediumSeaGreen;
w.PasswordHintText = "PasswordHintText";
w.PasswordHintStyle.BackColor = Color.PeachPuff;
}
}
public static void w_SendingMail (object sender, MailMessageEventArgs e)
{
if (e.Message.Body.IndexOf ("123") > 0)
WebTest.CurrentTest.UserData = "w_SendingMail";
}
public static void w_SendMailError (object sender, SendMailErrorEventArgs e)
{
e.Handled = true;
}
// TODO:
// ValidatorTextStyle
// ErrorMessageStyle
[Test]
[Category ("NotDotNet")]
[Category ("NunitWeb")]
public void ChngPasswordTest ()
{
PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (StylesRenderTestInit));
WebTest test = new WebTest (pi);
string html = test.Run ();
test.Invoker = pi;
FormRequest fr = new FormRequest (test.Response, "form1");
fr.Controls.Add (new BaseControl (GetDecoratedId (html, "UserName"), "heh"));
fr.Controls.Add (new BaseControl (GetDecoratedId (html, "CurrentPassword"), "heh"));
fr.Controls.Add (new BaseControl (GetDecoratedId (html, "NewPassword"), "hehe"));
fr.Controls.Add (new BaseControl (GetDecoratedId (html, "ConfirmNewPassword"), "hehe"));
string button = GetDecoratedId (html, "ChangePasswordPushButton");
if (button.Length > 0)
fr.Controls.Add (new BaseControl (GetDecoratedId (html, "ChangePasswordPushButton"), "ChangePasswordPushButton"));
else
fr.Controls.Add (new BaseControl ("__EVENTTARGET", GetEventTarget (html, "ChangePassword")));
test.Request = fr;
html = test.Run ();
Assert.IsTrue (html.IndexOf ("has been changed") > 0, "GetPassword");
}
[Test]
[Category ("NunitWeb")]
public void PostBackEventCancel ()
{
WebTest t = new WebTest ();
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventCancel));
string html = t.Run ();
if (html.IndexOf ("Change Your Password") < 0)
Assert.Fail ("ChangePassword not created");
FormRequest fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CancelPushButton");
fr.Controls["ChangePassword1$ChangePasswordContainerID$CancelPushButton"].Value = "Cancel";
t.Request = fr;
html = t.Run ();
if (t.UserData == null || t.UserData.ToString () != "CancelButtonClick")
Assert.Fail ("CancelButtonClick event not fired");
}
public static void _PostBackEventCancel (Page p)
{
ChangePassword w = CreateTestControl (p);
w.CancelButtonClick += new EventHandler (w_CancelButtonClick);
}
static void w_CancelButtonClick (object sender, EventArgs e)
{
WebTest.CurrentTest.UserData = "CancelButtonClick";
}
[Test]
[Category ("NunitWeb")]
public void PostBackEventChanging ()
{
WebTest t = new WebTest ();
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventChanging));
string html = t.Run ();
if (html.IndexOf ("Change Your Password") < 0)
Assert.Fail ("ChangePassword not created");
FormRequest fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "a";
fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "1";
fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "1";
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
t.Request = fr;
html = t.Run ();
if (t.UserData == null || t.UserData.ToString () != "ChangingPassword")
Assert.Fail ("ChangingPassword event not fired");
}
public static void _PostBackEventChanging (Page p)
{
ChangePassword w = CreateTestControl (p);
w.DisplayUserName = false;
w.ChangingPassword +=new LoginCancelEventHandler(w_ChangingPassword);
}
public static void w_ChangingPassword (object sender, LoginCancelEventArgs e)
{
WebTest.CurrentTest.UserData = "ChangingPassword";
e.Cancel = true;
}
[Test]
[Category ("NunitWeb")]
public void PostBackEventError ()
{
WebTest t = new WebTest ();
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventError));
string html = t.Run ();
if (html.IndexOf ("Change Your Password") < 0)
Assert.Fail ("ChangePassword not created");
FormRequest fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$UserName");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
fr.Controls["ChangePassword1$ChangePasswordContainerID$UserName"].Value = "WrongUser";
fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "a";
fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "1";
fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "1";
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
t.Request = fr;
html = t.Run ();
if (t.UserData == null || t.UserData.ToString () != "ChangePasswordError")
Assert.Fail ("ChangePasswordError event not fired");
}
public static void _PostBackEventError (Page p)
{
ChangePassword w = CreateTestControl (p);
w.ChangePasswordError += new EventHandler (w_ChangePasswordError);
}
public static void w_ChangePasswordError (object sender, EventArgs e)
{
WebTest.CurrentTest.UserData = "ChangePasswordError";
}
[Test]
[Category ("NunitWeb")]
public void PostBackEventChangedPassword ()
{
WebTest t = new WebTest ();
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventChangedPassword));
string html = t.Run ();
if (html.IndexOf ("Change Your Password") < 0)
Assert.Fail ("ChangePassword not created");
FormRequest fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "p@ssword";
fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "123456?";
fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "123456?";
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
t.Request = fr;
html = t.Run ();
if (t.UserData == null || t.UserData.ToString () != "ChangedPassword")
Assert.Fail ("ChangedPassword event not fired");
}
public static void _PostBackEventChangedPassword (Page p)
{
ChangePassword w = CreateTestControl (p);
w.DisplayUserName = false;
w.ChangedPassword += new EventHandler (w_ChangedPassword);
}
public static void w_ChangedPassword (object sender, EventArgs e)
{
WebTest.CurrentTest.UserData = "ChangedPassword";
}
[Test]
[Category ("NunitWeb")]
public void PostBackEventContinue ()
{
WebTest t = new WebTest ();
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEventContinue));
string html = t.Run ();
if (html.IndexOf ("Change Your Password") < 0)
Assert.Fail ("ChangePassword not created");
FormRequest fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
fr.Controls["ChangePassword1$ChangePasswordContainerID$CurrentPassword"].Value = "p@ssword";
fr.Controls["ChangePassword1$ChangePasswordContainerID$NewPassword"].Value = "123456?";
fr.Controls["ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword"].Value = "123456?";
fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton");
fr.Controls["ChangePassword1$ChangePasswordContainerID$ChangePasswordPushButton"].Value = "Change+Password";
t.Request = fr;
html = t.Run ();
if (html.IndexOf ("Change Password Complete") < 0)
Assert.Fail ("Password has not been changed!");
fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls.Add ("ChangePassword1$SuccessContainerID$ContinuePushButton");
fr.Controls["ChangePassword1$SuccessContainerID$ContinuePushButton"].Value = "Continue";
t.Request = fr;
html = t.Run ();
if (t.UserData == null || t.UserData.ToString () != "ContinueButtonClick")
Assert.Fail ("ContinueButtonClick event not fired");
}
public static void _PostBackEventContinue (Page p)
{
ChangePassword w = CreateTestControl (p);
w.DisplayUserName = false;
w.ContinueButtonClick += new EventHandler (w_ContinueButtonClick);
}
public static void w_ContinueButtonClick (object sender, EventArgs e)
{
WebTest.CurrentTest.UserData = "ContinueButtonClick";
}
[Test]
[Category ("NunitWeb")]
public void DefaultProvider ()
{
WebTest t = new WebTest ();
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_DefaultProvider));
string html = t.Run ();
}
public static void _DefaultProvider (Page p)
{
MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");
Assert.AreEqual (section.DefaultProvider, "FakeProvider", "section.DefaultProvider");
Assert.AreEqual (Membership.Provider.GetType (), typeof (FakeMembershipProvider), "Membership.Provider.GetType ()");
}
[Test]
public void ChangePasswordContainer_FindControl ()
{
WebTest t = new WebTest ("ChangePasswordContainer_FindControl.aspx");
t.Invoker = PageInvoker.CreateOnLoad (new PageDelegate (ChangePasswordContainer_FindControl_OnLoad));
t.Run ();
}
public static void ChangePasswordContainer_FindControl_OnLoad (Page p)
{
ChangePassword cp = p.FindControl ("ChangePassword1") as ChangePassword;
Assert.IsNotNull (cp, "#A1");
RequiredFieldValidator rfv = cp.ChangePasswordTemplateContainer.FindControl ("text1required") as RequiredFieldValidator;
Assert.IsNotNull (rfv, "#A2");
}
[Test]
public void RenderOuterTableForbiddenStyles ()
{
var cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.BackColor = Color.Red;
TestRenderFailure (cp, "BackColor");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.BorderColor = Color.Red;
TestRenderFailure (cp, "BorderColor");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.BorderStyle = BorderStyle.Dashed;
TestRenderFailure (cp, "BorderStyle");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.BorderWidth = new Unit (10, UnitType.Pixel);
TestRenderFailure (cp, "BorderWidth");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.CssClass = "MyClass";
TestRenderFailure (cp, "CssClass");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.Font.Bold = true;
TestRenderFailure (cp, "Font", false);
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.ForeColor = Color.Red;
TestRenderFailure (cp, "ForeColor");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.Height = new Unit (20, UnitType.Pixel);
TestRenderFailure (cp, "Height");
cp = new ChangePassword ();
cp.RenderOuterTable = false;
cp.Width = new Unit (20, UnitType.Pixel);
TestRenderFailure (cp, "Width");
}
void TestRenderFailure (ChangePassword cp, string message, bool shouldFail = true)
{
using (var sw = new StringWriter ()) {
using (var w = new HtmlTextWriter (sw)) {
if (shouldFail)
AssertExtensions.Throws<InvalidOperationException> (() => {
cp.RenderControl (w);
}, message);
else {
cp.RenderControl (w);
Assert.IsTrue (sw.ToString ().Length > 0, message);
}
}
}
}
[TestFixtureTearDown]
public void TearDown ()
{
WebTest.Unload ();
}
}
}
|