Merge branch 'master' of http://github.com/mono/mono
[mono.git] / mcs / class / System / Test / System.Net / NetworkCredentialTest.cs
1 //
2 // Unit tests for System.Net.NetworkCredential
3 //
4 // Contact:
5 //   Moonlight List (moonlight-list@lists.ximian.com)
6 //
7 // Copyright (C) 2010 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 using System;
30 using System.Net;
31
32 using NUnit.Framework;
33
34 namespace MoonTest.System.Net {
35
36         [TestFixture]
37         public class NetworkCredentialTest {
38
39                 void CheckDefaults (NetworkCredential nc)
40                 {
41                         Assert.AreSame (String.Empty, nc.Domain, "Domain");
42                         Assert.AreSame (String.Empty, nc.Password, "Password");
43                         Assert.AreSame (String.Empty, nc.UserName, "UserName");
44                         Assert.AreSame (nc, nc.GetCredential (null, null), "GetCredential");
45                 }
46
47                 void CheckCustom (NetworkCredential nc)
48                 {
49                         Assert.AreEqual ("dom", nc.Domain, "Domain");
50                         Assert.AreEqual ("********", nc.Password, "Password");
51                         Assert.AreEqual ("user", nc.UserName, "UserName");
52                         Assert.AreSame (nc, nc.GetCredential (new Uri ("http://www.mono-project.com"), "basic"), "GetCredential");
53                 }
54
55                 [Test]
56                 public void Constructor_0 ()
57                 {
58                         NetworkCredential nc = new NetworkCredential ();
59                         CheckDefaults (nc);
60
61                         nc.UserName = null;
62                         nc.Domain = null;
63                         nc.Password = null;
64                         CheckDefaults (nc);
65
66                         nc.UserName = "user";
67                         nc.Domain = "dom";
68                         nc.Password = "********";
69                         CheckCustom (nc);
70                 }
71
72                 [Test]
73                 public void Constructor_2 ()
74                 {
75                         NetworkCredential nc = new NetworkCredential (null, null);
76                         CheckDefaults (nc);
77
78                         nc.UserName = String.Empty;
79                         nc.Domain = String.Empty;
80                         nc.Password = null;
81                         CheckDefaults (nc);
82
83                         nc = new NetworkCredential ("user", "********");
84                         nc.Domain = "dom";
85                         CheckCustom (nc);
86                 }
87
88                 [Test]
89                 public void Constructor_3 ()
90                 {
91                         NetworkCredential nc = new NetworkCredential (null, null, null);
92                         CheckDefaults (nc);
93
94                         nc.UserName = String.Empty;
95                         nc.Domain = null;
96                         nc.Password = String.Empty;
97                         CheckDefaults (nc);
98
99                         nc = new NetworkCredential ("user", "********", "dom");
100                         CheckCustom (nc);
101                 }
102         }
103 }
104