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