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)); }
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); }
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)); }
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); }
public void ContainsFrom_ContainsASettingWithHierarchyReturnsFalse_FromLevelAboveKey() { //Arrange var hierarchy = new TestablePropertyBagHierarchy(); string key = TestsConstants.TestGuidName; string namespacedKey = ConfigManager.PnPKeyNamespace + "." + key; bool expected = false; 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 config = new HierarchicalConfig(hierarchy); //Act bool target = config.ContainsKey(key, ConfigLevel.CurrentSPSite); //Assert Assert.AreEqual(expected, target); }
public void GetSettingFrom_GetASettingWithHierarchy_FromMidHierarchyFindsKey() { //Arrange var hierarchy = new TestablePropertyBagHierarchy(); string key = TestsConstants.TestGuidName; string namespacedKey = ConfigManager.PnPKeyNamespace + "." + key; string expected = "{80C23A3E-566B-4B11-A881-5868F2BCB198}"; hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPWeb)); hierarchy.AddPropertyBag(GetPropertyBag(ConfigLevel.CurrentSPSite)); BIPropertyBag bag = GetPropertyBag(ConfigLevel.CurrentSPWebApplication); bag.Values[namespacedKey] = expected; hierarchy.AddPropertyBag(bag); var config = new HierarchicalConfig(hierarchy); //Act string target = config.GetByKey <string>(key, ConfigLevel.CurrentSPSite); //Assert Assert.AreEqual(expected, target); }
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); }
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); }