public void RemoveChild()
        {
            PolicyStatement ps = new PolicyStatement(new NamedPermissionSet(ps_Name));
            MyCodeGroup     cg = new MyCodeGroup(new AllMembershipCondition(), ps);

            cg.Name        = "SomeName";
            cg.Description = "Some Description";

            MyCodeGroup cgChild = new MyCodeGroup(new ApplicationDirectoryMembershipCondition(), ps);

            cgChild.Name        = "ChildName";
            cgChild.Description = "Child Descripiton";
            cg.AddChild(cgChild);

            MyCodeGroup cgChild2 = new MyCodeGroup(new ApplicationDirectoryMembershipCondition(), ps);

            cgChild2.Name        = "ChildName2";
            cgChild2.Description = "Child Descripiton 2";
            cg.AddChild(cgChild2);

            Assert.AreEqual(2, cg.Children.Count, "Should be two children before the call to Remove()");
            cg.RemoveChild(cgChild);
            Assert.AreEqual(1, cg.Children.Count, "Should be one children after the call to Remove()");
            Assert.AreEqual("ChildName2", ((CodeGroup)cg.Children[0]).Name, "Remaining child does not have correct name");
        }
示例#2
0
		public void AddChild ()
		{
			MyCodeGroup cg = new MyCodeGroup(new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
			Assert.AreEqual (0, cg.Children.Count, "Unexpected number of children (before add)");
			cg.AddChild (new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.Unrestricted))));
			Assert.AreEqual (1, cg.Children.Count, "Unexpected number of children (after add)");
		}
        public void EqualsWithChildren()
        {
            PolicyStatement ps = new PolicyStatement(new NamedPermissionSet(ps_Name));

            MyCodeGroup cgChild = new MyCodeGroup(new ApplicationDirectoryMembershipCondition(), ps);

            cgChild.Name        = "ChildName";
            cgChild.Description = "Child Descripiton";

            MyCodeGroup cg = new MyCodeGroup(new AllMembershipCondition(), ps);

            cg.Name        = "SomeName";
            cg.Description = "Some Description";
            cg.AddChild(cgChild);

            MyCodeGroup cg2 = new MyCodeGroup(cg.MembershipCondition, cg.PolicyStatement);

            cg2.Name        = cg.Name;
            cg2.Description = cg.Description;

            Assert.IsTrue(cg.Equals(cg2), "Should be equal when Children are ignored");
            Assert.IsTrue(!cg.Equals(cg2, true), "Should not be equal when Child count is different");

            cg2.AddChild(cgChild);
            Assert.IsTrue(cg2.Equals(cg, true), "Should be equal when children are equal");
        }
示例#4
0
		public void ToFromXmlRoundtrip_WithChildren () 
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));

			MyCodeGroup cgChild = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";

			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			cg.AddChild (cgChild);
			cg.AddChild (cgChild);
			Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
			SecurityElement se = cg.ToXml ();

			MyCodeGroup cg2 = (MyCodeGroup) cg.Copy ();
			cg2.FromXml (se);
			// MissingMethodException down here (stangely not up here ?!? delayed ?)
			Assert.IsTrue (cg.Equals (cg2, true), "Equals (FromXml)");
		}
示例#5
0
		public void ToXml () 
		{
			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
			SecurityElement se = cg.ToXml ();
			string s = se.ToString ();
			Assert.IsTrue (s.StartsWith ("<CodeGroup class=\"MonoTests.System.Security.Policy.MyCodeGroup,"), "ToXml-Starts");
			Assert.IsTrue (s.EndsWith ("version=\"1\"/>" + Environment.NewLine + "</CodeGroup>" + Environment.NewLine), "ToXml-Ends");

			cg.AddChild (new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.Unrestricted))));
			se = cg.ToXml ();
			s = se.ToString ();
			Assert.IsTrue (s.IndexOf ("<CodeGroup class=\"MonoTests.System.Security.Policy.MyCodeGroup,", 1) > 0, "ToXml-Child");
		}
示例#6
0
		public void RemoveChild_NonExistant () 
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));

			MyCodeGroup cgChild = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";

			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.AddChild (cgChild);
			cg.RemoveChild (cgChild);
			cg.RemoveChild (cgChild);
			// no exception
		}
示例#7
0
		public void ToFromXmlRoundtrip_WithChildren_Second () 
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));

			// only the child is MySecondCodeGroup
			MySecondCodeGroup cgChild = new MySecondCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";

			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			cg.AddChild (cgChild);
			Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
			SecurityElement se = cg.ToXml ();

			MyCodeGroup cg2 = (MyCodeGroup) cg.Copy ();
			cg2.FromXml (se);
			Assert.IsTrue (cg.Equals (cg2, true), "Equals (FromXml)");
		}
示例#8
0
		public void RemoveChild ()
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));
			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";

			MyCodeGroup cgChild = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";
			cg.AddChild (cgChild);

			MyCodeGroup cgChild2 = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild2.Name = "ChildName2";
			cgChild2.Description = "Child Descripiton 2";
			cg.AddChild (cgChild2);

			Assert.AreEqual (2, cg.Children.Count, "Should be two children before the call to Remove()");
			cg.RemoveChild(cgChild);
			Assert.AreEqual (1, cg.Children.Count, "Should be one children after the call to Remove()");
			Assert.AreEqual("ChildName2", ((CodeGroup)cg.Children[0]).Name, "Remaining child does not have correct name");
		}
示例#9
0
		public void EqualsWithChildren ()
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));
			
			MyCodeGroup cgChild = new MyCodeGroup(new ApplicationDirectoryMembershipCondition(), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";

			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			cg.AddChild (cgChild);

			MyCodeGroup cg2 = new MyCodeGroup (cg.MembershipCondition, cg.PolicyStatement);
			cg2.Name = cg.Name;
			cg2.Description = cg.Description;

			Assert.IsTrue (cg.Equals (cg2), "Should be equal when Children are ignored");
			Assert.IsTrue (!cg.Equals(cg2, true), "Should not be equal when Child count is different");

			cg2.AddChild(cgChild);
			Assert.IsTrue (cg2.Equals(cg, true), "Should be equal when children are equal");
		}
示例#10
0
		public void AddChild_Null () 
		{
			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
			cg.AddChild (null);
		}