Exemple #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);
        }
Exemple #2
0
        public void WriteSandboxLog_LogsMessage()
        {
            //Arrange
            SharePointEnvironment.Reset();
            var context = new SIApplicationContextProvider()
            {
                GetCurrentAppDomainFriendlyName = () => "SandboxDomain",
                IsProxyCheckerInstalled         = () => true,
                IsProxyInstalledStringString    = (a, t) => true,
            };

            SharePointEnvironment.ApplicationContextProvider = context;
            string testMessage = testMessageString;
            int    testEventId = 99;
            LoggingOperationArgs loggingArgs = null;
            BSPSite site = new BSPSite();
            MSPSite s    = new MSPSite(site)
            {
                IDGet = () => TestsConstants.TestGuid
            };

            BSPContext.SetCurrent();
            MSPContext c = new MSPContext(BSPContext.Current)
            {
                SiteGet = () => site
            };

            MSPUtility.ExecuteRegisteredProxyOperationStringStringSPProxyOperationArgs = (a, t, args) =>
            {
                loggingArgs =
                    args as
                    LoggingOperationArgs;
                return(null);
            };


            //Act
            var target = new SharePointLogger();

            target.LogToOperations(testMessage, testEventId, SandboxEventSeverity.Error, TestsConstants.AreasCategories);

            // Assert
            Assert.IsNotNull(loggingArgs);
            Assert.AreEqual(loggingArgs.Message, testMessage);
            Assert.AreEqual(loggingArgs.Category, TestsConstants.AreasCategories);
            Assert.AreEqual(loggingArgs.EventId, testEventId);
            Assert.AreEqual((SandboxEventSeverity)loggingArgs.Severity, SandboxEventSeverity.Error);
        }
Exemple #3
0
        public void WriteSandboxTrace_NoContext_TracesMessage()
        {
            //Arrange
            SharePointEnvironment.Reset();
            string testMessage = testMessageString;
            int    testEventId = 99;
            TracingOperationArgs tracingArgs = null;
            BSPSite site = new BSPSite();
            MSPSite s    = new MSPSite(site)
            {
                IDGet = () => TestsConstants.TestGuid
            };

            MSPContext.CurrentGet = () => null;
            MSPUtility.ExecuteRegisteredProxyOperationStringStringSPProxyOperationArgs = (a, t, args) =>
            {
                tracingArgs =
                    args as
                    TracingOperationArgs;
                return(null);
            };

            var context = new SIApplicationContextProvider()
            {
                GetCurrentAppDomainFriendlyName = () => "SandboxDomain",
                IsProxyCheckerInstalled         = () => true,
                IsProxyInstalledStringString    = (a, t) => true,
            };

            SharePointEnvironment.ApplicationContextProvider = context;

            //Act
            var target = new SharePointLogger();

            target.TraceToDeveloper(testMessage, testEventId, SandboxTraceSeverity.High, TestsConstants.AreasCategories);

            // Assert
            Assert.IsNotNull(tracingArgs);
            Assert.AreEqual(tracingArgs.Message, testMessage);
            Assert.AreEqual(tracingArgs.Category, TestsConstants.AreasCategories);
            Assert.AreEqual(tracingArgs.EventId, testEventId);
            Assert.AreEqual((SandboxTraceSeverity)tracingArgs.Severity, SandboxTraceSeverity.High);
        }