Beispiel #1
0
		public void ConstructorLevel_Deny_Unrestricted ()
		{
			StorePermission p = new StorePermission (StorePermissionFlags.AllFlags);
			Assert.AreEqual (StorePermissionFlags.AllFlags, p.Flags, "Flags");
			Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
			Assert.IsNotNull (p.Copy (), "Copy");
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml");
			p.FromXml (se);
			Assert.IsNotNull (p.Intersect (p), "Intersect");
			Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
			Assert.IsNotNull (p.Union (p), "Union");
		}
Beispiel #2
0
		public void ConstructorState_Deny_Unrestricted ()
		{
			StorePermission p = new StorePermission (PermissionState.None);
			Assert.AreEqual (StorePermissionFlags.NoFlags, p.Flags, "Flags");
			Assert.IsFalse (p.IsUnrestricted (), "IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml");
			p.FromXml (se);
			Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
			// strange behaviour of Copy under MS fx 2.0 (returns null for NoFlags)
			p.Copy ();
			p.Intersect (p);
			p.Union (p);
		}
Beispiel #3
0
		public void Union_Unrestricted ()
		{
			// Union with unrestricted is unrestricted
			StorePermission sp1 = new StorePermission (PermissionState.Unrestricted);
			StorePermission sp2 = new StorePermission (PermissionState.None);
			// a. source (this) is unrestricted
			for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
				// 8 isn't a valid value (so we exclude it from the rest of the loop)
				if ((i & 8) == 8)
					continue;
				sp2.Flags = (StorePermissionFlags) i;
				StorePermission union = (StorePermission) sp1.Union (sp2);
				Assert.IsTrue (union.IsUnrestricted (), "target " + sp2.Flags.ToString ());
			}
			// b. destination (target) is unrestricted
			for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
				// 8 isn't a valid value (so we exclude it from the rest of the loop)
				if ((i & 8) == 8)
					continue;
				sp2.Flags = (StorePermissionFlags) i;
				StorePermission union = (StorePermission) sp2.Union (sp1);
				Assert.IsTrue (union.IsUnrestricted (), "source " + sp2.Flags.ToString ());
			}
		}
Beispiel #4
0
		public void Union_Self ()
		{
			StorePermission sp = new StorePermission (PermissionState.None);
			StorePermission union = (StorePermission) sp.Union (sp);
			Assert.IsNull (union, "NoFlags");
			for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
				// 8 isn't a valid value (so we exclude it from the rest of the loop)
				if ((i & 8) == 8)
					continue;
				sp.Flags = (StorePermissionFlags) i;
				union = (StorePermission) sp.Union (sp);
				Assert.AreEqual (sp.Flags, union.Flags, sp.Flags.ToString ());
			}
		}
Beispiel #5
0
		public void Union_None ()
		{
			// Union with none is same
			StorePermission sp1 = new StorePermission (PermissionState.None);
			StorePermission sp2 = new StorePermission (PermissionState.None);

			StorePermission union = (StorePermission) sp1.Union (sp1);
			Assert.IsNull (union, "NoFlags");

			for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
				// 8 isn't a valid value (so we exclude it from the rest of the loop)
				if ((i & 8) == 8)
					continue;
				sp2.Flags = (StorePermissionFlags) i;

				union = (StorePermission) sp1.Union (sp2);
				Assert.IsFalse (union.IsUnrestricted (), "target.Unrestricted " + sp2.Flags.ToString ());
				Assert.AreEqual (sp2.Flags, union.Flags, "target.Level " + sp2.Flags.ToString ());

				union = (StorePermission) sp2.Union (sp1);
				Assert.IsFalse (union.IsUnrestricted (), "source.Unrestricted " + sp2.Flags.ToString ());
				Assert.AreEqual (sp2.Flags, union.Flags, "source.Level " + sp2.Flags.ToString ());
			}

			sp2.Flags = StorePermissionFlags.AllFlags;
			union = (StorePermission) sp1.Union (sp2);
			Assert.IsTrue (union.IsUnrestricted (), "target.Unrestricted Unrestricted");
			Assert.AreEqual (StorePermissionFlags.AllFlags, union.Flags, "target.Level Unrestricted");

			union = (StorePermission) sp2.Union (sp1);
			Assert.IsTrue (union.IsUnrestricted (), "source.Unrestricted Unrestricted");
			Assert.AreEqual (StorePermissionFlags.AllFlags, union.Flags, "source.Level Unrestricted");
		}
Beispiel #6
0
		public void Union_Null ()
		{
			StorePermission sp = new StorePermission (PermissionState.None);
			// Union with null is a simple copy
			for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
				// 8 isn't a valid value (so we exclude it from the rest of the loop)
				if ((i & 8) == 8)
					continue;
				sp.Flags = (StorePermissionFlags) i;
				StorePermission union = (StorePermission) sp.Union (null);
				Assert.AreEqual (sp.Flags, union.Flags, sp.Flags.ToString ());
			}
			// except fot NoFlags (which returns null)
			sp.Flags = StorePermissionFlags.NoFlags;
			Assert.IsNull (sp.Union (null), "NoFlags");
		}