Ejemplo n.º 1
0
 /// <summary>
 /// Factory method for creating new instances of AuthorizationMap.
 /// </summary>
 /// <param name="xmlDocument">The XML document.</param>
 /// <returns></returns>
 public static AuthorizationMap FromXml(IXPathNavigable xmlDocument)
 {
     var map = new AuthorizationMap();
     XmlElement root = ((XmlDocument)xmlDocument).DocumentElement;
     map.AddAuthorizationsFromXml(root, "/Authorizations/WebParts/WebPart", "className");
     map.AddAuthorizationsFromXml(root, "/Authorizations/NamedBehaviors/NamedBehavior", "name");
     return map;
 }
Ejemplo n.º 2
0
        private static void AssertMapConstructedCorrectly(AuthorizationMap map)
        {
            Assert.IsNotNull(map);

            var componentSetsForString = map.ListComponentSets(typeof(string));
            Assert.IsNotNull(componentSetsForString);
            Assert.AreEqual(1, componentSetsForString.Count());
            Assert.AreEqual(1, componentSetsForString.ElementAt(0).Count());
            Assert.IsTrue(componentSetsForString.ElementAt(0).Contains(11));

            var componentSetsForInt = map.ListComponentSets(typeof(int));
            Assert.IsNotNull(componentSetsForInt);
            Assert.AreEqual(1, componentSetsForInt.Count());
            Assert.AreEqual(2, componentSetsForInt.ElementAt(0).Count());
            Assert.IsTrue(componentSetsForInt.ElementAt(0).Contains(11));
            Assert.IsTrue(componentSetsForInt.ElementAt(0).Contains(12));

            var componentSetsForBoolean = map.ListComponentSets(typeof(bool));
            Assert.IsNotNull(componentSetsForBoolean);
            Assert.AreEqual(2, componentSetsForBoolean.Count());
            Assert.AreEqual(2, componentSetsForBoolean.ElementAt(0).Count());
            Assert.IsTrue(componentSetsForBoolean.ElementAt(0).Contains(11));
            Assert.IsTrue(componentSetsForBoolean.ElementAt(0).Contains(12));
            Assert.AreEqual(1, componentSetsForBoolean.ElementAt(1).Count());
            Assert.IsTrue(componentSetsForBoolean.ElementAt(1).Contains(13));

            var componentSetsForBehaviorX = map.ListComponentSets("BehaviorX");
            Assert.IsNotNull(componentSetsForBehaviorX);
            Assert.AreEqual(1, componentSetsForBehaviorX.Count());
            Assert.AreEqual(1, componentSetsForBehaviorX.ElementAt(0).Count());
            Assert.IsTrue(componentSetsForBehaviorX.ElementAt(0).Contains(13));

            var componentSetsForBehaviorY = map.ListComponentSets("BehaviorY");
            Assert.IsNotNull(componentSetsForBehaviorY);
            Assert.AreEqual(1, componentSetsForBehaviorY.Count());
            Assert.AreEqual(2, componentSetsForBehaviorY.ElementAt(0).Count());
            Assert.IsTrue(componentSetsForBehaviorY.ElementAt(0).Contains(13));
            Assert.IsTrue(componentSetsForBehaviorY.ElementAt(0).Contains(14));

            var componentSetsForBehaviorZ = map.ListComponentSets("BehaviorZ");
            Assert.IsNotNull(componentSetsForBehaviorZ);
            Assert.AreEqual(2, componentSetsForBehaviorZ.Count());
            Assert.AreEqual(2, componentSetsForBehaviorZ.ElementAt(0).Count());
            Assert.IsTrue(componentSetsForBehaviorZ.ElementAt(0).Contains(11));
            Assert.IsTrue(componentSetsForBehaviorZ.ElementAt(0).Contains(12));
            Assert.AreEqual(1, componentSetsForBehaviorZ.ElementAt(1).Count());
            Assert.IsTrue(componentSetsForBehaviorZ.ElementAt(1).Contains(13));
        }