Example #1
0
        public void GetSiteCacheInterval_WithoutConfiguredFarmValue_ReturnsNegativeOne()
        {
            //Arrange
            int    expected    = -1;
            string expectedKey = "Microsoft.Practices.SharePoint.Common.SiteLocatorCacheInterval";
            var    bag         = new BIPropertyBag();
            SPFarm farm        = BSPFarm.SetLocal();

            var context = new SIApplicationContextProvider();

            context.GetCurrentAppDomainFriendlyName = () => "FullTrust";
            context.GetSPFarmLocal = () => farm;
            SharePointEnvironment.ApplicationContextProvider = context;

            var configMgr = new SIConfigManager();

            configMgr.ContainsKeyInPropertyBagStringIPropertyBag = (key, propertyBag) =>
            {
                if (key == expectedKey)
                {
                    return(false);
                }
                return(true);
            };
            configMgr.GetPropertyBagConfigLevel = (cfgLevel) => bag;

            var config = new ServiceLocatorConfig(configMgr);

            //Act
            int target = config.GetSiteCacheInterval();

            //Assert
            Assert.AreEqual(expected, target);
        }
Example #2
0
        public void GetSiteCacheInterval_WithConfiguredFarmValue_ReturnsValue()
        {
            //Arrange
            int    expected    = 30;
            string expectedKey = "Microsoft.Practices.SharePoint.Common.SiteLocatorCacheInterval";
            var    bag         = new BIPropertyBag();

            BSPFarm.SetLocal();

            var configMgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (key, propertyBag) =>
                {
                    if (key == expectedKey)
                    {
                        return(true);
                    }
                    return(false);
                },
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (configlevel) => bag,
            };

            configMgr.GetFromPropertyBagStringIPropertyBag <int>((key, propetyBag) =>
            {
                if (key == expectedKey)
                {
                    return(expected);
                }
                return(-1);
            });

            var config = new ServiceLocatorConfig(configMgr);

            //Act
            int target = config.GetSiteCacheInterval();

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