1 //
2 // AuthorizationRuleCollectionTest.cs
3 //	- unit tests for System.Web.Configuration.AuthorizationRuleCollection
4 //
5 // Author:
6 //	Chris Toshok  <toshok@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 
30 
31 using NUnit.Framework;
32 
33 using System;
34 using System.Configuration;
35 using System.Web.Configuration;
36 using System.Web;
37 using System.Web.Security;
38 using System.IO;
39 using System.Xml;
40 using System.Reflection;
41 
42 namespace MonoTests.System.Web.Configuration {
43 
44 	[TestFixture]
45 	public class AuthorizationRuleCollectionTest  {
46 
47 		[Test]
AddDuplicate()48 		public void AddDuplicate ()
49 		{
50 			AuthorizationRuleCollection col = new AuthorizationRuleCollection ();
51 			AuthorizationRule rule = new AuthorizationRule (AuthorizationRuleAction.Deny);
52 
53 			rule.Users.Add ("toshok");
54 			rule.Verbs.Add ("GET");
55 
56 			col.Add (rule);
57 			col.Add (rule);
58 
59 			Assert.AreEqual (2, col.Count, "A1");
60 			Assert.AreEqual ("toshok", col[0].Users.ToString(), "A2");
61 		}
62 
63 		[Test]
AddDuplicate2()64 		public void AddDuplicate2 ()
65 		{
66 			AuthorizationRuleCollection col = new AuthorizationRuleCollection ();
67 			AuthorizationRule rule1 = new AuthorizationRule (AuthorizationRuleAction.Deny);
68 			AuthorizationRule rule2 = new AuthorizationRule (AuthorizationRuleAction.Allow);
69 
70 			rule1.Users.Add ("toshok");
71 			rule1.Verbs.Add ("GET");
72 
73 			rule2.Users.Add ("toshok");
74 			rule2.Verbs.Add ("GET");
75 
76 			col.Add (rule1);
77 			col.Add (rule2);
78 
79 			Assert.AreEqual (2, col.Count, "A1");
80 			Assert.AreEqual ("toshok", col[0].Users.ToString(), "A2");
81 			Assert.AreEqual (AuthorizationRuleAction.Deny, col[0].Action, "A3");
82 			Assert.AreEqual (AuthorizationRuleAction.Allow, col[1].Action, "A4");
83 		}
84 
85 		[Test]
GetElementKey()86 		public void GetElementKey ()
87 		{
88 			MethodInfo minfo = typeof (AuthorizationRuleCollection).GetMethod ("GetElementKey", BindingFlags.Instance | BindingFlags.NonPublic);
89 			AuthorizationRuleCollection col = new AuthorizationRuleCollection ();
90 
91 			AuthorizationRule rule = new AuthorizationRule (AuthorizationRuleAction.Deny);
92 
93 			rule.Users.Add ("toshok");
94 			rule.Verbs.Add ("GET");
95 
96 			col.Add (rule);
97 
98 			object[] args = new object[1];
99 			args[0] = rule;
100 			string key = (string)minfo.Invoke (col, args);
101 
102 			Assert.AreEqual ("Deny", key, "A1");
103 		}
104 	}
105 
106 }
107 
108