public void CanSetValueAndOverrideAtLowerLevel()
        {
            SPSite    spSite    = new SPSite("http://localhost:9001/sites/pssportal");
            SPContext spContext = SPContext.GetContext(spSite.RootWeb);

            Isolate.WhenCalled(() => SPContext.Current.Site).WillReturn(spSite);
            Isolate.WhenCalled(() => SPContext.Current).WillReturn(spContext);

            //Set Values at levels of hierarchy
            HierarchicalConfig target = new HierarchicalConfig();

            target.SetInPropertyBag("IntegrationTest-FarmLevelKey", "FarmLevelValue", new SPFarmPropertyBag());
            Assert.AreEqual("FarmLevelValue", target.GetByKey <string>("IntegrationTest-FarmLevelKey"));

            target.SetInPropertyBag("IntegrationTest-FarmLevelKey", "Over-riddenValue1", new SPWebAppPropertyBag());
            Assert.AreEqual("Over-riddenValue1", target.GetByKey <string>("IntegrationTest-FarmLevelKey"));

            target.SetInPropertyBag("IntegrationTest-FarmLevelKey", "Over-riddenValue2", new SPWebAppPropertyBag());
            Assert.AreEqual("Over-riddenValue2", target.GetByKey <string>("IntegrationTest-FarmLevelKey"));

            target.SetInPropertyBag("IntegrationTest-FarmLevelKey", "Over-riddenValue3", new SPSitePropertyBag());
            Assert.AreEqual("Over-riddenValue3", target.GetByKey <string>("IntegrationTest-FarmLevelKey"));

            target.SetInPropertyBag("IntegrationTest-FarmLevelKey", "Over-riddenValue4", new SPWebPropertyBag());
            Assert.AreEqual("Over-riddenValue4", target.GetByKey <string>("IntegrationTest-FarmLevelKey"));
        }
        public void CanSetAndGetValues()
        {
            SPSite    spSite    = new SPSite("http://localhost:9001/sites/pssportal");
            SPContext spContext = SPContext.GetContext(spSite.RootWeb);

            Isolate.WhenCalled(() => SPContext.Current.Site).WillReturn(spSite);
            Isolate.WhenCalled(() => SPContext.Current).WillReturn(spContext);

            //Set Values at levels of hierarchy
            HierarchicalConfig target1 = new HierarchicalConfig();

            target1.SetInPropertyBag("IntegrationTest-FarmLevelKey", "FarmLevelValue", new SPFarmPropertyBag());
            target1.SetInPropertyBag("IntegrationTest-WebAppLevelKey", "WebAppLevelValue", new SPWebAppPropertyBag());
            target1.SetInPropertyBag("IntegrationTest-SiteLevelKey", "SiteLevelValue", new SPSitePropertyBag());
            target1.SetInPropertyBag("IntegrationTest-WebLevelKey", "WebLevelValue", new SPWebPropertyBag());

            HierarchicalConfig target2 = new HierarchicalConfig();

            Assert.AreEqual("FarmLevelValue", target2.GetByKey <string>("IntegrationTest-FarmLevelKey"));
            Assert.AreEqual("WebAppLevelValue", target2.GetByKey <string>("IntegrationTest-WebAppLevelKey"));
            Assert.AreEqual("SiteLevelValue", target2.GetByKey <string>("IntegrationTest-SiteLevelKey"));
            Assert.AreEqual("WebLevelValue", target2.GetByKey <string>("IntegrationTest-WebLevelKey"));

            Assert.AreEqual("FarmLevelValue", SPFarm.Local.Properties["IntegrationTest-FarmLevelKey"]);
            Assert.AreEqual("WebAppLevelValue", SPContext.Current.Site.WebApplication.Properties["IntegrationTest-WebAppLevelKey"]);
            Assert.AreEqual("SiteLevelValue", SPContext.Current.Site.RootWeb.AllProperties["IntegrationTest-SiteLevelKey"]);
            Assert.AreEqual("WebLevelValue", SPContext.Current.Web.AllProperties["IntegrationTest-WebLevelKey"]);
        }
Exemplo n.º 3
0
        public void CanSetValueBasedOnKey()
        {
            MockPropertyBag defaultPropertyBag = new MockPropertyBag();
            var             target             = new HierarchicalConfig(defaultPropertyBag, new MockConfigSettingSerializer());

            target.SetInPropertyBag("Key", 3, defaultPropertyBag);
        }
Exemplo n.º 4
0
        public void SerializeErrorGivesClearErrroMessage()
        {
            MockPropertyBag defaultPropertyBag = new MockPropertyBag();
            var             target             = new HierarchicalConfig(defaultPropertyBag, new MockConfigSettingSerializer()
            {
                ThrowError = true
            });

            target.SetInPropertyBag("key", "MyValue", defaultPropertyBag);
        }
Exemplo n.º 5
0
        public void SetConfigValueLogs()
        {
            SPFarm fakeFarm = Isolate.Fake.Instance <SPFarm>();

            Isolate.WhenCalled(() => fakeFarm.Properties).WillReturn(new Hashtable());
            var target = new HierarchicalConfig(new MockPropertyBag());

            target.SetInPropertyBag("myKey", "myValue", fakeFarm);

            Assert.AreEqual("Set value in hierarchical config.\n\tKey: 'myKey'\n\tLevel: 'CurrentSPFarm'\n\tValue: 'myValue'", logger.TraceMessage);
        }
Exemplo n.º 6
0
        public void UsingSiteAsPrefixFails()
        {
            var target = new HierarchicalConfig(new MockPropertyBag());

            target.SetInPropertyBag("Site_BadValue", "value", new MockPropertyBag());
        }