Ejemplo n.º 1
0
        public void GetSettingFrom_GetASettingWithHierarchyDoesntFindKey_FromLevelAboveKey()
        {
            //Arrange
            var           hierarchy     = new TestablePropertyBagHierarchy();
            string        key           = TestsConstants.TestGuidName;
            string        namespacedKey = ConfigManager.PnPKeyNamespace + "." + key;
            string        value         = "{80C23A3E-566B-4B11-A881-5868F2BCB198}";
            BIPropertyBag bag           = GetPropertyBag(ConfigLevel.CurrentSPWeb);

            bag.Values[namespacedKey] = value;
            hierarchy.AddPropertyBag(bag);
            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPSite));
            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPWebApplication));
            var target = new HierarchicalConfig(hierarchy);
            ConfigurationException configEx = null;

            //Act
            try
            {
                string result = target.GetByKey <string>(key, ConfigLevel.CurrentSPSite);
            }
            catch (ConfigurationException ex)
            {
                configEx = ex;
            }

            //Assert
            Assert.IsNotNull(configEx);
            Assert.IsTrue(configEx.Message.Contains(key));
        }
Ejemplo n.º 2
0
        public void GetPropertyBagForLevel_WithMultiplePropertyBags_ReturnsBag()
        {
            //Arrange
            var hierarchy = new TestablePropertyBagHierarchy();

            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPWeb));
            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPSite));
            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPWebApplication));
            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPFarm));

            //Act
            IPropertyBag farmBag   = hierarchy.GetPropertyBagForLevel(ConfigLevel.CurrentSPFarm);
            IPropertyBag webBag    = hierarchy.GetPropertyBagForLevel(ConfigLevel.CurrentSPWeb);
            IPropertyBag siteBag   = hierarchy.GetPropertyBagForLevel(ConfigLevel.CurrentSPSite);
            IPropertyBag webAppBag = hierarchy.GetPropertyBagForLevel(ConfigLevel.CurrentSPWebApplication);

            //Assert
            Assert.IsNotNull(farmBag);
            Assert.IsTrue(farmBag.Level == ConfigLevel.CurrentSPFarm);
            Assert.IsNotNull(webBag);
            Assert.IsTrue(webBag.Level == ConfigLevel.CurrentSPWeb);
            Assert.IsNotNull(siteBag);
            Assert.IsTrue(siteBag.Level == ConfigLevel.CurrentSPSite);
            Assert.IsNotNull(webBag);
            Assert.IsTrue(webBag.Level == ConfigLevel.CurrentSPWeb);
        }
Ejemplo n.º 3
0
        public void GetSettingFrom_GetASetting_NoKeyReturnsNull()
        {
            //Arrange
            var           hierarchy = new TestablePropertyBagHierarchy();
            BIPropertyBag bag       = GetPropertyBag(ConfigLevel.CurrentSPWeb);

            hierarchy.AddPropertyBag(bag);
            string key    = TestsConstants.TestGuidName;
            var    config = new HierarchicalConfig(hierarchy);
            ConfigurationException configEx = null;

            //Act
            try
            {
                string target = config.GetByKey <string>(key, ConfigLevel.CurrentSPWeb);
            }
            catch (ConfigurationException ex)
            {
                configEx = ex;
            }

            //Assert
            Assert.IsNotNull(configEx);
            Assert.IsTrue(configEx.Message.Contains(key));
        }
Ejemplo n.º 4
0
        public void GetPropertyBagForLevel_WithOnePropertyBag_ReturnsBag()
        {
            //Arrange
            var hierarchy = new TestablePropertyBagHierarchy();

            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPWeb));

            //Act
            IPropertyBag bag = hierarchy.GetPropertyBagForLevel(ConfigLevel.CurrentSPWeb);

            //Assert
            Assert.IsNotNull(bag);
            Assert.IsTrue(bag.Level == ConfigLevel.CurrentSPWeb);
        }
Ejemplo n.º 5
0
        public void GetPropertyBagForMissingLevel_ReturnsNull()
        {
            //Arrange
            var hierarchy = new TestablePropertyBagHierarchy();

            hierarchy.AddPropertyBag(new BIPropertyBag()
            {
                Level = ConfigLevel.CurrentSPFarm
            });

            //Act
            IPropertyBag bag = hierarchy.GetPropertyBagForLevel(ConfigLevel.CurrentSPWeb);

            //Assert
            Assert.IsNull(bag);
        }
Ejemplo n.º 6
0
        public void ContainsFrom_ContainsASettingWithHierarchy_NoKeyReturnsFalse()
        {
            //Arrange
            var    hierarchy = new TestablePropertyBagHierarchy();
            string key       = TestsConstants.TestGuidName;
            bool   expected  = false;

            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPWeb));
            hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPSite));
            var config = new HierarchicalConfig(hierarchy);

            //Act
            bool target = config.ContainsKey(key, ConfigLevel.CurrentSPWeb);

            //Assert
            Assert.AreEqual(expected, target);
        }
Ejemplo n.º 7
0
        public void ContainsFrom_ContainsASetting_WithNullKeyThrowsArgumentNullException()
        {
            //Arrange
            bool expectedExceptionThrown = false;
            var  hierarchy = new TestablePropertyBagHierarchy();
            var  config    = new HierarchicalConfig(hierarchy);

            //Act
            try
            {
                config.ContainsKey(null, ConfigLevel.CurrentSPSite);
            }
            catch (ArgumentNullException)
            {
                expectedExceptionThrown = true;
            }

            Assert.IsTrue(expectedExceptionThrown);
        }
Ejemplo n.º 8
0
        public void GetSettingFrom_GetASetting_WithNullKey()
        {
            //Arrange
            var  hierarchy = new TestablePropertyBagHierarchy();
            bool expectedExceptionThrown = false;
            var  target = new HierarchicalConfig(hierarchy);

            //Act
            try
            {
                target.GetByKey <string>(null, ConfigLevel.CurrentSPSite);
            }
            catch (ArgumentNullException)
            {
                expectedExceptionThrown = true;
            }

            Assert.IsTrue(expectedExceptionThrown);
        }
Ejemplo n.º 9
0
        public void ContainsFrom_ContainsASetting()
        {
            //Arrange
            var           hierarchy = new TestablePropertyBagHierarchy();
            bool          expected  = true;
            BIPropertyBag bag       = GetPropertyBag(ConfigLevel.CurrentSPWeb);

            hierarchy.AddPropertyBag(bag);
            string key           = TestsConstants.TestGuidName;
            string namespacedKey = ConfigManager.PnPKeyNamespace + "." + key;
            string value         = "{80C23A3E-566B-4B11-A881-5868F2BCB198}";

            bag.Values[namespacedKey] = value;
            var config = new HierarchicalConfig(hierarchy);

            //Act
            bool target = config.ContainsKey(key, ConfigLevel.CurrentSPWeb);

            //Assert
            Assert.AreEqual(expected, target);
        }
Ejemplo n.º 10
0
        public void GetSettingFrom_GetASetting()
        {
            //Arrange
            var           hierarchy = new TestablePropertyBagHierarchy();
            BIPropertyBag bag       = GetPropertyBag(ConfigLevel.CurrentSPSite);

            hierarchy.AddPropertyBag(bag);
            string key           = TestsConstants.TestGuidName;
            string namespacedKey = ConfigManager.PnPKeyNamespace + "." + key;
            string expected      = "{80C23A3E-566B-4B11-A881-5868F2BCB198}";

            bag.Values[namespacedKey] = expected;
            bag.Level = ConfigLevel.CurrentSPWeb;
            var config = new HierarchicalConfig(hierarchy);

            //Act
            string target = config.GetByKey <string>(key, ConfigLevel.CurrentSPWeb);

            //Assert
            Assert.AreEqual(expected, target);
        }