コード例 #1
0
    public void Copy()
    {
        IPermission p1 = new PolicyPermission("a");
        IPermission p2 = p1.Copy();

        SetShouldBe(p1, new String[] { "a" });
        SetShouldBe(p2, new String[] { "a" });
    }
コード例 #2
0
    public void Demand()
    {
        PolicyDecision decision = new PolicyDecision(config);
        decision.ApplicationName = "Application 3";

        PolicyPermission permission = new PolicyPermission("Permission 1", decision);

        IIdentity identity = new GenericIdentity("User 1");
        IPrincipal principal = new GenericPrincipal(identity, new String[] { "Role 1" });
        Thread.CurrentPrincipal = principal;
        Assert.Throws(typeof(SecurityException),
          permission.Demand);

        identity = new GenericIdentity("User 2");
        principal = new GenericPrincipal(identity, new String[] { "Role 1", "Role 2", "Role 3" });
        Thread.CurrentPrincipal = principal;
        Assert.DoesNotThrow(permission.Demand);
    }
コード例 #3
0
    public void SetOperations_CorrectValues()
    {
        IPermission p1 = new PolicyPermission("a");
        IPermission p2 = new PolicyPermission("b");
        IPermission p3 = p1.Union(p2);
        IPermission p4 = p1.Intersect(p3);
        IPermission p5 = p1.Intersect(p2);
        IPermission p6 = p1.Union(p1);

        SetShouldBe(p1, new String[] { "a" });
        SetShouldBe(p2, new String[] { "b" });
        SetShouldBe(p3, new String[] { "a", "b" });
        SetShouldBe(p4, new String[] { "a" });
        Assert.IsNull(p5);
        SetShouldBe(p6, new String[] { "a" });
        Assert.IsTrue(p1.IsSubsetOf(p1));
        Assert.IsTrue(p1.IsSubsetOf(p3));
        Assert.IsFalse(p3.IsSubsetOf(p1));
    }
コード例 #4
0
    public void Permission_InvalidArguments()
    {
        PolicyPermission permission = new PolicyPermission("abc");

        IPermission[] values = new IPermission[] {
          null,
          new PrincipalPermission("abc", "xyz")
        };
        Action<IPermission>[] tests = new Action<IPermission>[] {
          (value) => permission.Intersect(value),
        (value) => permission.Union(value),
        (value) => permission.IsSubsetOf(value)
        };

        for (Int32 i = 0; i != tests.Length; ++i)
          for (Int32 j = 0; j != values.Length; ++j)
        Assert.Throws(typeof(ArgumentNullException),
              () => tests[i](values[j]));
    }