[System] UriKind.RelativeOrAbsolute workaround.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / ChangePasswordTest.cs
1 //
2 // ChangePasswordTest.cs - Unit tests for System.Web.UI.WebControls.ChangePassword
3 //
4 // Author:
5 //      Vladimir Krasnov  <vladimirk@mainsoft.com>
6 //
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.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
29
30 using System;
31 using System.Drawing;
32 using System.Threading;
33 using System.Collections;
34 using System.Globalization;
35 using System.IO;
36 using System.Web;
37 using System.Web.UI;
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;
44
45 using NUnit.Framework;
46 using System.Collections.Specialized;
47 using System.Web.Configuration;
48
49 namespace MonoTests.System.Web.UI.WebControls
50 {
51
52         public class TestChangePassword : ChangePassword
53         {
54
55                 public string Tag
56                 {
57                         get { return base.TagName; }
58                 }
59
60                 public StateBag StateBag
61                 {
62                         get { return base.ViewState; }
63                 }
64
65                 public string Render ()
66                 {
67                         StringWriter sw = new StringWriter ();
68                         sw.NewLine = "\n";
69                         HtmlTextWriter writer = new HtmlTextWriter (sw);
70                         base.Render (writer);
71                         return writer.InnerWriter.ToString ();
72                 }
73
74                 public Style GetStyle ()
75                 {
76                         return base.CreateControlStyle ();
77                 }
78
79                 public void TrackState ()
80                 {
81                         TrackViewState ();
82                 }
83
84                 public void LoadState (object state)
85                 {
86                         LoadViewState (state);
87                 }
88
89                 public object SaveState ()
90                 {
91                         return SaveViewState ();
92                 }
93
94                 public void SetDesignMode (IDictionary dic)
95                 {
96                         base.SetDesignModeState (dic);
97                 }
98
99                 private bool onBubble;
100
101                 public bool OnBubbleEventCalled
102                 {
103                         get { return onBubble; }
104                         set { onBubble = value; }
105                 }
106
107                 protected override bool OnBubbleEvent (object source, EventArgs e)
108                 {
109                         onBubble = true;
110                         return base.OnBubbleEvent (source, e);
111                 }
112
113                 public bool DoBubbleEvent (object source, EventArgs e)
114                 {
115                         return base.OnBubbleEvent (source, e);
116                 }
117
118                 public void DoEnsureChildControls ()
119                 {
120                         base.EnsureChildControls ();
121                 }
122
123                 public bool DoOnBubbleEvent (EventArgs e)
124                 {
125                         return base.OnBubbleEvent (this, e);
126                 }
127         }
128
129         [Serializable]
130         [TestFixture]
131         public class ChangePasswordTest
132         {
133                 [TestFixtureSetUp]
134                 public void CopyTestResources ()
135                 {
136                         WebTest.CopyResource (GetType (), "ChangePasswordContainer_FindControl.aspx", "ChangePasswordContainer_FindControl.aspx");
137                 }
138
139                 [Test]
140                 public void DefaultProperties ()
141                 {
142                         CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
143                         CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
144
145                         try {
146                                 CultureInfo ci = CultureInfo.GetCultureInfo ("en-US");
147                                 Thread.CurrentThread.CurrentCulture = ci;
148                                 Thread.CurrentThread.CurrentUICulture = ci;
149                                 RunDefaultPropertiesTests ();
150                         } finally {
151                                 Thread.CurrentThread.CurrentCulture = currentCulture;
152                                 Thread.CurrentThread.CurrentUICulture = currentUICulture;
153                         }
154                 }
155
156                 void RunDefaultPropertiesTests ()
157                 {
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");
198                 }
199
200                 [Test]
201                 public void AssignToDefaultProperties ()
202                 {
203                         TestChangePassword w = new TestChangePassword ();
204                         Assert.AreEqual (0, w.Attributes.Count, "Attributes.Count");
205                         Assert.AreEqual (0, w.StateBag.Count, "ViewState.Count");
206
207                         int count = 0;
208
209                         w.CancelButtonImageUrl = "text";
210                         Assert.AreEqual ("text", w.CancelButtonImageUrl, "Assign CancelButtonImageUrl,");
211                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelButtonImageUrl,");
212
213                         w.CancelButtonText = "text";
214                         Assert.AreEqual ("text", w.CancelButtonText, "Assign CancelButtonText");
215                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelButtonText");
216
217                         w.CancelDestinationPageUrl = "text";
218                         Assert.AreEqual ("text", w.CancelDestinationPageUrl, "Assign CancelDestinationPageUrl");
219                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CancelDestinationPageUrl");
220
221                         w.ChangePasswordButtonImageUrl = "text";
222                         Assert.AreEqual ("text", w.ChangePasswordButtonImageUrl, "Assign ChangePasswordButtonImageUrl");
223                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordButtonImageUrl");
224
225                         w.HelpPageText = "text";
226                         Assert.AreEqual ("text", w.HelpPageText, "Assign HelpPageText");
227                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageText");
228
229                         w.ChangePasswordButtonText = "text";
230                         Assert.AreEqual ("text", w.ChangePasswordButtonText, "Assign ChangePasswordButtonText");
231                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordButtonText");
232
233                         w.ChangePasswordFailureText = "text";
234                         Assert.AreEqual ("text", w.ChangePasswordFailureText, "Assign ChangePasswordFailureText");
235                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordFailureText");
236
237                         w.ChangePasswordTitleText = "msg";
238                         Assert.AreEqual ("msg", w.ChangePasswordTitleText, "Assign ChangePasswordTitleText");
239                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ChangePasswordTitleText");
240
241                         w.ConfirmNewPasswordLabelText = "msg";
242                         Assert.AreEqual ("msg", w.ConfirmNewPasswordLabelText, "Assign ConfirmNewPasswordLabelText");
243                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ConfirmNewPasswordLabelText");
244
245                         w.ContinueButtonImageUrl = "msg";
246                         Assert.AreEqual ("msg", w.ContinueButtonImageUrl, "Assign ContinueButtonImageUrl");
247                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueButtonImageUrl");
248
249                         w.ContinueButtonText = "msg";
250                         Assert.AreEqual ("msg", w.ContinueButtonText, "Assign ContinueButtonText");
251                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueButtonText");
252
253                         w.ContinueDestinationPageUrl = "msg";
254                         Assert.AreEqual ("msg", w.ContinueDestinationPageUrl, "Assign ContinueDestinationPageUrl");
255                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate ContinueDestinationPageUrl");
256
257                         w.CreateUserIconUrl = "msg";
258                         Assert.AreEqual ("msg", w.CreateUserIconUrl, "Assign CreateUserIconUrl");
259                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserIconUrl");
260
261                         w.CreateUserText = "msg";
262                         Assert.AreEqual ("msg", w.CreateUserText, "Assign CreateUserText");
263                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserText");
264
265                         w.CreateUserUrl = "msg";
266                         Assert.AreEqual ("msg", w.CreateUserUrl, "Assign CreateUserUrl");
267                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate CreateUserUrl");
268
269                         w.DisplayUserName = true;
270                         Assert.AreEqual (true, w.DisplayUserName, "Assign DisplayUserName");
271                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate DisplayUserName");
272
273                         w.EditProfileIconUrl = "msg";
274                         Assert.AreEqual ("msg", w.EditProfileIconUrl, "Assign EditProfileIconUrl");
275                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate EditProfileIconUrl");
276
277                         w.EditProfileText = "msg";
278                         Assert.AreEqual ("msg", w.EditProfileText, "Assign EditProfileText");
279                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate EditProfileText");
280
281                         w.HelpPageIconUrl = "msg";
282                         Assert.AreEqual ("msg", w.HelpPageIconUrl, "Assign HelpPageIconUrl");
283                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageIconUrl");
284
285                         w.HelpPageUrl = "msg";
286                         Assert.AreEqual ("msg", w.HelpPageUrl, "Assign HelpPageUrl");
287                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate HelpPageUrl");
288
289                         w.InstructionText = "msg";
290                         Assert.AreEqual ("msg", w.InstructionText, "Assign InstructionText");
291                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate InstructionText");
292
293                         w.MembershipProvider = "msg";
294                         Assert.AreEqual ("msg", w.MembershipProvider, "Assign MembershipProvider");
295                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate MembershipProvider");
296
297                         w.NewPasswordLabelText = "msg";
298                         Assert.AreEqual ("msg", w.NewPasswordLabelText, "Assign NewPasswordLabelText");
299                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate NewPasswordLabelText");
300
301                         w.PasswordHintText = "msg";
302                         Assert.AreEqual ("msg", w.PasswordHintText, "Assign PasswordHintText");
303                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordHintText");
304
305                         w.PasswordLabelText = "msg";
306                         Assert.AreEqual ("msg", w.PasswordLabelText, "Assign PasswordLabelText");
307                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordLabelText");
308
309                         w.PasswordRecoveryIconUrl = "msg";
310                         Assert.AreEqual ("msg", w.PasswordRecoveryIconUrl, "Assign PasswordRecoveryIconUrl");
311                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryIconUrl");
312
313                         w.PasswordRecoveryText = "msg";
314                         Assert.AreEqual ("msg", w.PasswordRecoveryText, "Assign PasswordRecoveryText");
315                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryText");
316
317                         w.PasswordRecoveryUrl = "msg";
318                         Assert.AreEqual ("msg", w.PasswordRecoveryUrl, "Assign PasswordRecoveryUrl");
319                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRecoveryUrl");
320
321                         w.PasswordRequiredErrorMessage = "msg";
322                         Assert.AreEqual ("msg", w.PasswordRequiredErrorMessage, "Assign PasswordRequiredErrorMessage");
323                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate PasswordRequiredErrorMessage");
324
325                         w.SuccessPageUrl = "msg";
326                         Assert.AreEqual ("msg", w.SuccessPageUrl, "Assign SuccessPageUrl");
327                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessPageUrl");
328
329                         w.SuccessText = "msg";
330                         Assert.AreEqual ("msg", w.SuccessText, "Assign SuccessText");
331                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessText");
332
333                         w.SuccessTitleText = "msg";
334                         Assert.AreEqual ("msg", w.SuccessTitleText, "Assign SuccessTitleText");
335                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate SuccessTitleText");
336
337                         w.UserNameLabelText = "msg";
338                         Assert.AreEqual ("msg", w.UserNameLabelText, "Assign UserNameLabelText");
339                         Assert.AreEqual (++count, w.StateBag.Count, "Viewstate UserNameLabelText");
340                 }
341
342                 public static void BasicRenderTestInit (Page p)
343                 {
344                         CreateTestControl (p);
345                 }
346
347                 public static ChangePassword CreateTestControl (Page p)
348                 {
349                         LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
350                         LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
351
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);
359
360                         return w;
361                 }
362
363                 [Test]
364                 [Category ("NunitWeb")]
365                 public void BasicRenderTest ()
366                 {
367                         string html = new WebTest (PageInvoker.CreateOnLoad (
368                                 new PageDelegate (BasicRenderTestInit))).Run ();
369
370                         int st = 0;
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");
380                 }
381
382                 [Test]
383                 [Category ("NunitWeb")]
384                 public void TitlesRenderTest ()
385                 {
386                         string html = new WebTest (PageInvoker.CreateOnLoad (
387                                 new PageDelegate (TitlesRenderTestInit))).Run ();
388
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");
396                 }
397
398                 public static void TitlesRenderTestInit (Page p)
399                 {
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";
408                 }
409
410                 [Test]
411                 [Category ("NunitWeb")]
412                 public void ExtraTitlesRenderTest ()
413                 {
414                         string html = new WebTest (PageInvoker.CreateOnLoad (
415                                 new PageDelegate (ExtraTitlesRenderTestInit))).Run ();
416
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");
424                 }
425
426                 public static void ExtraTitlesRenderTestInit (Page p)
427                 {
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";
436                 }
437
438                 [Test]
439                 [Category ("NunitWeb")]
440                 public void StylesRenderTest ()
441                 {
442                         string html = new WebTest (PageInvoker.CreateOnLoad (
443                                 new PageDelegate (StylesRenderTestInit))).Run ();
444
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");
450                 }
451
452                 private string GetDecoratedId (string html, string id)
453                 {
454                         Regex reg = new Regex ("name=\".*[\\$\\:]" + id + "\"");
455                         Match match = reg.Match (html);
456
457                         string fixedId = match.Value;
458                         if (fixedId.Length > 0)
459                                 fixedId = fixedId.Substring (fixedId.IndexOf ("\""), fixedId.Length - fixedId.IndexOf ("\"")).Trim ('\"');
460
461                         return fixedId;
462                 }
463
464                 private static string GetEventTarget (string html, string id)
465                 {
466                         Regex reg = new Regex ("__doPostBack.*\\(.*'.*" + id + "'");
467                         Match match = reg.Match (html);
468
469                         string fixedId = match.Value;
470                         if (fixedId.Length > 0)
471                                 fixedId = fixedId.Substring (fixedId.IndexOf ("'"), fixedId.Length - fixedId.IndexOf ("'")).Trim ('\'');
472
473                         return fixedId;
474                 }
475
476                 [Test]
477                 [Category ("NunitWeb")]
478                 public void BasicPostbackTest ()
479                 {
480                         PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (StylesRenderTestInit));
481                         WebTest test = new WebTest (pi);
482
483                         string html = test.Run ();
484                         test.Invoker = pi;
485
486                         FormRequest fr = new FormRequest (test.Response, "form1");
487
488                         fr.Controls.Add (new BaseControl (GetDecoratedId (html, "UserName"), "username"));
489
490                         PageDelegates pd = new PageDelegates ();
491                         pd.PreRender = new PageDelegate (BasicPostTestPreRender);
492                         pd.Load = new PageDelegate (StylesRenderTestInit);
493                         pi.Delegates = pd;
494
495                         test.Request = fr;
496                         html = test.Run ();
497
498                         Assert.IsTrue (html.IndexOf ("username") > 0, "rendered user name");
499
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");
506                 }
507
508                 public static void BasicPostTestPreRender (Page p)
509                 {
510                         ChangePassword w = (ChangePassword) p.FindControl ("ChangePassword1");
511                         if (w == null)
512                                 Assert.Fail ("postback1");
513
514                         Assert.AreEqual ("username", w.UserName, "posted user name");
515                 }
516
517                 public static void StylesRenderTestInit (Page p)
518                 {
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;
524
525                         if (!p.IsPostBack) {
526                                 w.TextBoxStyle.BackColor = Color.LightGoldenrodYellow;
527                                 w.TitleTextStyle.Height = Unit.Pixel (732);
528                                 w.LabelStyle.BackColor = Color.MediumSpringGreen;
529
530                                 w.HelpPageUrl = "http://www.HelpPageUrl.com";
531                                 w.HelpPageText = "hhh";
532                                 w.HyperLinkStyle.BackColor = Color.LightSkyBlue;
533
534                                 w.InstructionText = "text";
535                                 w.InstructionTextStyle.BackColor = Color.MediumSeaGreen;
536
537                                 w.PasswordHintText = "PasswordHintText";
538                                 w.PasswordHintStyle.BackColor = Color.PeachPuff;
539                         }
540                 }
541
542                 public static void w_SendingMail (object sender, MailMessageEventArgs e)
543                 {
544                         if (e.Message.Body.IndexOf ("123") > 0)
545                                 WebTest.CurrentTest.UserData = "w_SendingMail";
546                 }
547                 
548                 public static void w_SendMailError (object sender, SendMailErrorEventArgs e)
549                 {
550                         e.Handled = true;
551                 }
552
553                 // TODO:
554                 // ValidatorTextStyle
555                 // ErrorMessageStyle
556                 [Test]
557                 [Category ("NotDotNet")]
558                 [Category ("NunitWeb")]
559                 public void ChngPasswordTest ()
560                 {
561                         PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (StylesRenderTestInit));
562                         WebTest test = new WebTest (pi);
563
564                         string html = test.Run ();
565                         test.Invoker = pi;
566
567                         FormRequest fr = new FormRequest (test.Response, "form1");
568
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"));
576                         else
577                                 fr.Controls.Add (new BaseControl ("__EVENTTARGET", GetEventTarget (html, "ChangePassword")));
578
579                         test.Request = fr;
580                         html = test.Run ();
581                         Assert.IsTrue (html.IndexOf ("has been changed") > 0, "GetPassword");
582                 }
583
584                 [Test]
585                 [Category ("NunitWeb")]
586                 public void PostBackEventCancel ()
587                 {
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";
601                         t.Request = fr;
602                         html = t.Run ();
603                         if (t.UserData == null || t.UserData.ToString () != "CancelButtonClick")
604                                 Assert.Fail ("CancelButtonClick event not fired");
605                 }
606
607                 public static void _PostBackEventCancel (Page p)
608                 {
609                         ChangePassword w = CreateTestControl (p);
610                         w.CancelButtonClick += new EventHandler (w_CancelButtonClick);
611                 }
612
613                 static void w_CancelButtonClick (object sender, EventArgs e)
614                 {
615                         WebTest.CurrentTest.UserData = "CancelButtonClick";
616                 }
617
618
619                 [Test]
620                 [Category ("NunitWeb")]
621                 public void PostBackEventChanging ()
622                 {
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");
631                         
632                         fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
633                         fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
634                         fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
635                         
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";
641                         t.Request = fr;
642                         html = t.Run ();
643                         if (t.UserData == null || t.UserData.ToString () != "ChangingPassword")
644                                 Assert.Fail ("ChangingPassword event not fired");
645                 }
646
647                 public static void _PostBackEventChanging (Page p)
648                 {
649                         ChangePassword w = CreateTestControl (p);
650                         w.DisplayUserName = false;
651                         w.ChangingPassword +=new LoginCancelEventHandler(w_ChangingPassword);
652                 }
653
654                 public static void w_ChangingPassword (object sender, LoginCancelEventArgs e)
655                 {
656                         WebTest.CurrentTest.UserData = "ChangingPassword";
657                         e.Cancel = true;
658                 }
659
660                 [Test]
661                 [Category ("NunitWeb")]
662                 public void PostBackEventError ()
663                 {
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");
672
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");
677
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";
684                         t.Request = fr;
685                         html = t.Run ();
686                         if (t.UserData == null || t.UserData.ToString () != "ChangePasswordError")
687                                 Assert.Fail ("ChangePasswordError event not fired");
688                 }
689
690                 public static void _PostBackEventError (Page p)
691                 {
692                         ChangePassword w = CreateTestControl (p);
693                         w.ChangePasswordError += new EventHandler (w_ChangePasswordError);
694                 }
695
696                 public static void w_ChangePasswordError (object sender, EventArgs e)
697                 {
698                         WebTest.CurrentTest.UserData = "ChangePasswordError";
699                 }
700
701                 
702                 [Test]
703                 [Category ("NunitWeb")]
704                 public void PostBackEventChangedPassword ()
705                 {
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");
714
715                         fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$CurrentPassword");
716                         fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$NewPassword");
717                         fr.Controls.Add ("ChangePassword1$ChangePasswordContainerID$ConfirmNewPassword");
718
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";
724                         t.Request = fr;
725                         html = t.Run ();
726                         if (t.UserData == null || t.UserData.ToString () != "ChangedPassword")
727                                 Assert.Fail ("ChangedPassword event not fired");
728                 }
729
730                 public static void _PostBackEventChangedPassword (Page p)
731                 {
732                         ChangePassword w = CreateTestControl (p);
733                         w.DisplayUserName = false;
734                         w.ChangedPassword += new EventHandler (w_ChangedPassword);
735                 }
736
737                 public static void w_ChangedPassword (object sender, EventArgs e)
738                 {
739                         WebTest.CurrentTest.UserData = "ChangedPassword";
740                 }
741
742                 [Test]
743                 [Category ("NunitWeb")]
744                 public void PostBackEventContinue ()
745                 {
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");
754
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";
763
764                         t.Request = fr;
765                         html = t.Run ();
766                         if (html.IndexOf ("Change Password Complete") < 0)
767                                 Assert.Fail ("Password has not been changed!");
768                         
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";
774
775                         t.Request = fr;
776                         html = t.Run ();
777
778                         if (t.UserData == null || t.UserData.ToString () != "ContinueButtonClick")
779                                 Assert.Fail ("ContinueButtonClick event not fired");
780                 }
781
782                 public static void _PostBackEventContinue (Page p)
783                 {
784                         ChangePassword w = CreateTestControl (p);
785                         w.DisplayUserName = false;
786                         w.ContinueButtonClick += new EventHandler (w_ContinueButtonClick);
787                 }
788
789                 public static void w_ContinueButtonClick (object sender, EventArgs e)
790                 {
791                         WebTest.CurrentTest.UserData = "ContinueButtonClick";
792                 }
793
794                 [Test]
795                 [Category ("NunitWeb")]
796                 public void DefaultProvider ()
797                 {
798                         WebTest t = new WebTest ();
799                         t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_DefaultProvider));
800                         string html = t.Run ();
801                 }
802                 
803                 public static void _DefaultProvider (Page p)
804                 {
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 ()");
808                 }
809
810                 [Test]
811                 public void ChangePasswordContainer_FindControl ()
812                 {
813                         WebTest t = new WebTest ("ChangePasswordContainer_FindControl.aspx");
814                         t.Invoker = PageInvoker.CreateOnLoad (new PageDelegate (ChangePasswordContainer_FindControl_OnLoad));
815                         t.Run ();
816                 }
817
818                 public static void ChangePasswordContainer_FindControl_OnLoad (Page p)
819                 {
820                         ChangePassword cp = p.FindControl ("ChangePassword1") as ChangePassword;
821                         Assert.IsNotNull (cp, "#A1");
822                         
823                         RequiredFieldValidator rfv = cp.ChangePasswordTemplateContainer.FindControl ("text1required") as RequiredFieldValidator;
824                         Assert.IsNotNull (rfv, "#A2");
825                 }
826 #if NET_4_0
827                 [Test]
828                 public void RenderOuterTableForbiddenStyles ()
829                 {
830                         var cp = new ChangePassword ();
831                         cp.RenderOuterTable = false;
832                         cp.BackColor = Color.Red;
833
834                         TestRenderFailure (cp, "BackColor");
835
836                         cp = new ChangePassword ();
837                         cp.RenderOuterTable = false;
838                         cp.BorderColor = Color.Red;
839                         TestRenderFailure (cp, "BorderColor");
840
841                         cp = new ChangePassword ();
842                         cp.RenderOuterTable = false;
843                         cp.BorderStyle = BorderStyle.Dashed;
844                         TestRenderFailure (cp, "BorderStyle");
845
846                         cp = new ChangePassword ();
847                         cp.RenderOuterTable = false;
848                         cp.BorderWidth = new Unit (10, UnitType.Pixel);
849                         TestRenderFailure (cp, "BorderWidth");
850
851                         cp = new ChangePassword ();
852                         cp.RenderOuterTable = false;
853                         cp.CssClass = "MyClass";
854                         TestRenderFailure (cp, "CssClass");
855
856                         cp = new ChangePassword ();
857                         cp.RenderOuterTable = false;
858                         cp.Font.Bold = true;
859
860                         TestRenderFailure (cp, "Font", false);
861
862                         cp = new ChangePassword ();
863                         cp.RenderOuterTable = false;
864                         cp.ForeColor = Color.Red;
865                         TestRenderFailure (cp, "ForeColor");
866
867                         cp = new ChangePassword ();
868                         cp.RenderOuterTable = false;
869                         cp.Height = new Unit (20, UnitType.Pixel);
870                         TestRenderFailure (cp, "Height");
871
872                         cp = new ChangePassword ();
873                         cp.RenderOuterTable = false;
874                         cp.Width = new Unit (20, UnitType.Pixel);
875                         TestRenderFailure (cp, "Width");
876                 }
877
878                 void TestRenderFailure (ChangePassword cp, string message, bool shouldFail = true)
879                 {
880                         using (var sw = new StringWriter ()) {
881                                 using (var w = new HtmlTextWriter (sw)) {
882                                         if (shouldFail)
883                                                 AssertExtensions.Throws<InvalidOperationException> (() => {
884                                                         cp.RenderControl (w);
885                                                 }, message);
886                                         else {
887                                                 cp.RenderControl (w);
888                                                 Assert.IsTrue (sw.ToString ().Length > 0, message);
889                                         }
890                                 }
891                         }
892                 }
893 #endif
894                 [TestFixtureTearDown]
895                 public void TearDown ()
896                 {
897                         WebTest.Unload ();
898                 }
899         }
900 }
901