public void RemovePolicyRuleShouldPassIfExistingScope()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@"..\..\content\claimMappings-PassingTest4.xml"));

            Assert.AreEqual(1, store.RetrieveScopes().ElementAt(0).Rules.Count);

            var rule = store.RetrieveScopes().ElementAt(0).Rules.ElementAt(0);

            store.RemovePolicyRule(new Uri("http://localhost/1"), rule);

            Assert.AreEqual(0, store.RetrieveScopes().ElementAt(0).Rules.Count);
        }
        public void ValueOnOutputClaimShouldBePresentIfCopyFromInputIsFalseOrAbsent()
        {
            bool exceptionThrown = false;

            try
            {
                XmlPolicyStore store = new XmlPolicyStore(TestContext.CurrentContext.TestDirectory + @"..\..\..\content\claimMappings-FailingTest10.xml", new FileXmlRepository());
                store.RetrieveScopes();
            }
            catch (PolicyClaimException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);

            exceptionThrown = false;
            try
            {
                XmlPolicyStore store = new XmlPolicyStore(TestContext.CurrentContext.TestDirectory + @"..\..\..\content\claimMappings-FailingTest11.xml", new FileXmlRepository());
                store.RetrieveScopes();
            }
            catch (PolicyClaimException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
        public void RemoveIssuerShouldPass()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@"..\..\content\claimMappings-PassingTest4.xml"));

            store.RemoveIssuer(new Uri("http://localhost/1"), new Issuer("http://myIssuer21"));

            Assert.AreEqual(1, store.RetrieveScopes().ElementAt(0).Issuers.Count);
        }
        public void RemoveIssuerShouldThrowIsThereAreRulesForIssuer()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@".\content\claimMappings-FailingTest12.xml"));

            store.RemoveIssuer(new Uri("http://localhost/1"), new Issuer("http://myIssuer1"));

            Assert.AreEqual(1, store.RetrieveScopes().ElementAt(0).Issuers.Count());
        }
        public void AddPolicyRuleShouldPassIfExistingScope()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@"..\..\content\claimMappings-PassingTest2.xml"));

            int initialScopeCount = store.RetrieveScopes().Count();

            IList <InputPolicyClaim> inputClaims = new List <InputPolicyClaim>();
            Issuer    issuer    = new Issuer("http://myIssuer1");
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");

            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "nicolas"));
            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(claimType, string.Empty, CopyFromConstants.InputValue));

            store.AddPolicyRule(new Uri("http://localhost/1"), newRule);

            int expectedScopeCount = initialScopeCount;

            Assert.AreEqual(expectedScopeCount, store.RetrieveScopes().Count());
            Assert.AreEqual(2, store.RetrieveScopes().ElementAt(0).Rules.Count);
        }
        public void ShouldRetrieveClaimsPolicies()
        {
            XmlPolicyStore store = new XmlPolicyStore(TestContext.CurrentContext.TestDirectory + @"..\..\..\content\claimMappings-PassingTest1.xml", new FileXmlRepository());

            IEnumerable <PolicyScope> policyScopes = store.RetrieveScopes();

            Assert.IsNotNull(policyScopes);
            Assert.AreEqual(2, policyScopes.Count());

            Assert.AreEqual(new Uri("http://localhost/1"), policyScopes.ElementAt(0).Uri);
            Assert.AreEqual(2, policyScopes.ElementAt(0).Rules.Count());
            Assert.AreEqual(AssertionsMatch.All, policyScopes.ElementAt(0).Rules.ElementAt(0).AssertionsMatch);
            Assert.AreEqual(1, policyScopes.ElementAt(0).Rules.ElementAt(0).InputClaims.Count());
            Assert.AreEqual("http://myInputClaimType1", policyScopes.ElementAt(0).Rules.ElementAt(0).InputClaims.ElementAt(0).ClaimType.FullName);
            Assert.AreEqual("http://myIssuer1", policyScopes.ElementAt(0).Rules.ElementAt(0).InputClaims.ElementAt(0).Issuer.Uri);
            Assert.AreEqual("*", policyScopes.ElementAt(0).Rules.ElementAt(0).InputClaims.ElementAt(0).Value);
            Assert.AreEqual("http://myOutputClaimType1", policyScopes.ElementAt(0).Rules.ElementAt(0).OutputClaim.ClaimType.FullName);
            Assert.AreEqual("myOutputClaim", policyScopes.ElementAt(0).Rules.ElementAt(0).OutputClaim.Value);
            Assert.IsFalse(policyScopes.ElementAt(0).Rules.ElementAt(0).OutputClaim.CopyFromInput);

            Assert.AreEqual(AssertionsMatch.Any, policyScopes.ElementAt(0).Rules.ElementAt(1).AssertionsMatch);
            Assert.AreEqual(1, policyScopes.ElementAt(0).Rules.ElementAt(1).InputClaims.Count());
            Assert.AreEqual("http://myInputClaimType1", policyScopes.ElementAt(0).Rules.ElementAt(1).InputClaims.ElementAt(0).ClaimType.FullName);
            Assert.AreEqual("http://myIssuer2", policyScopes.ElementAt(0).Rules.ElementAt(1).InputClaims.ElementAt(0).Issuer.Uri);
            Assert.AreEqual("inputClaimValue", policyScopes.ElementAt(0).Rules.ElementAt(1).InputClaims.ElementAt(0).Value);
            Assert.AreEqual("http://myOutputClaimType1", policyScopes.ElementAt(0).Rules.ElementAt(1).OutputClaim.ClaimType.FullName);
            Assert.AreEqual(string.Empty, policyScopes.ElementAt(0).Rules.ElementAt(1).OutputClaim.Value);
            Assert.IsTrue(policyScopes.ElementAt(0).Rules.ElementAt(1).OutputClaim.CopyFromInput);

            Assert.AreEqual(new Uri("http://localhost/2"), policyScopes.ElementAt(1).Uri);
            Assert.AreEqual(1, policyScopes.ElementAt(1).Rules.Count());
            Assert.AreEqual(AssertionsMatch.All, policyScopes.ElementAt(1).Rules.ElementAt(0).AssertionsMatch);
            Assert.AreEqual(2, policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.Count());
            Assert.AreEqual("http://myInputClaimType2", policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.ElementAt(0).ClaimType.FullName);
            Assert.AreEqual("http://myIssuer3", policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.ElementAt(0).Issuer.Uri);
            Assert.AreEqual("scope 2 - input claim value from myIssuer3", policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.ElementAt(0).Value);
            Assert.AreEqual("http://myInputClaimType2", policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.ElementAt(1).ClaimType.FullName);
            Assert.AreEqual("http://myIssuer4", policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.ElementAt(1).Issuer.Uri);
            Assert.AreEqual("scope 2 - input claim value from myIssuer4", policyScopes.ElementAt(1).Rules.ElementAt(0).InputClaims.ElementAt(1).Value);
            Assert.AreEqual("http://myOutputClaimType2", policyScopes.ElementAt(1).Rules.ElementAt(0).OutputClaim.ClaimType.FullName);
            Assert.AreEqual("scope 2 - output claim value", policyScopes.ElementAt(1).Rules.ElementAt(0).OutputClaim.Value);
            Assert.IsFalse(policyScopes.ElementAt(1).Rules.ElementAt(0).OutputClaim.CopyFromInput);
        }
        public void RetrieveScopesShouldThrowIfIssuerDeclaredOnDifferentScope()
        {
            XmlPolicyStore store = new XmlPolicyStore(TestContext.CurrentContext.TestDirectory + @"..\..\..\content\claimMappings-FailingTest9.xml", new FileXmlRepository());

            Assert.Throws <PolicyClaimException>(() => store.RetrieveScopes());
        }
        public void RetrieveScopesShouldThrowIfDuplicatedUrisScope()
        {
            XmlPolicyStore store = new XmlPolicyStore(TestContext.CurrentContext.TestDirectory + @"..\..\..\content\claimMappings-FailingTest7.xml", new FileXmlRepository());

            Assert.Throws <PolicyScopeException>(() => store.RetrieveScopes());
        }
        public void RetrieveScopesShouldThrowIfCopyFromInputWithOutputValue()
        {
            XmlPolicyStore store = new XmlPolicyStore(TestContext.CurrentContext.TestDirectory + @"..\..\..\content\claimMappings-FailingTest6.xml", new FileXmlRepository());

            Assert.Throws <PolicyClaimException>(() => store.RetrieveScopes());
        }
        public void RetrieveScopesShouldThrowIfIssuerDeclaredOnDifferentScope()
        {
            XmlPolicyStore store = new XmlPolicyStore(@".\content\claimMappings-FailingTest9.xml", new FileXmlRepository());

            store.RetrieveScopes();
        }
        public void RetrieveScopesShouldThrowIfDuplicatedUrisScope()
        {
            XmlPolicyStore store = new XmlPolicyStore(@".\content\claimMappings-FailingTest7.xml", new FileXmlRepository());

            store.RetrieveScopes();
        }
        public void RetrieveScopesShouldThrowIfCopyFromInputWithOutputValue()
        {
            XmlPolicyStore store = new XmlPolicyStore(@".\content\claimMappings-FailingTest6.xml", new FileXmlRepository());

            store.RetrieveScopes();
        }
        public void RetrieveScopesShouldThrowIfWildcardOnOutputClaim()
        {
            XmlPolicyStore store = new XmlPolicyStore(@".\content\claimMappings-FailingTest4.xml", new FileXmlRepository());

            store.RetrieveScopes();
        }
        public void RetrieveScopesShouldThrowIfInvalidInputIssuer()
        {
            XmlPolicyStore store = new XmlPolicyStore(@".\content\claimMappings-FailingTest3.xml", new FileXmlRepository());

            store.RetrieveScopes();
        }