public void TheServiceLocatorFromCommonServiceLocatorThrowsClearErrorMessage()
        {
            Isolate.WhenCalled(() => SPFarm.Local).WillReturn(Isolate.Fake.Instance <SPFarm>());
            ServiceLocatorConfig fakeConfig = Isolate.Fake.Instance <ServiceLocatorConfig>();

            Isolate.Swap.NextInstance <ServiceLocatorConfig>().With(fakeConfig);
            Isolate.WhenCalled(() => fakeConfig.GetTypeMappings()).WillReturn(null);
            SharePointServiceLocator.Reset();
            var sl = SharePointServiceLocator.Current;

            try
            {
                var sl1 = ServiceLocator.Current;
                Assert.Fail();
            }
            catch (NotSupportedException ex)
            {
                Assert.AreEqual(ex.Message,
                                "ServiceLocator.Current is not supported. Use SharePointServiceLocator.Current instead.");
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
        public void CallingServiceLocatorWithoutSharePointContextFails()
        {
            Isolate.WhenCalled(() => SPFarm.Local).WillReturn(null);
            SharePointServiceLocator.Reset();
            Assert.IsNull(SPFarm.Local, "SPFarm should be local after this message");
            var target = SharePointServiceLocator.Current;

            Assert.Fail(target.ToString());
        }
        /// <summary>
        /// Removes the mappings for the configuration manager for list backed configuration.  This results
        /// in the default implementations being picked up for these services.
        /// </summary>
        /// <param name="properties">The properties related to the current context</param>
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            var slConfig = SharePointServiceLocator.GetCurrent().GetInstance <IServiceLocatorConfig>();
            var site     = properties.Feature.Parent as SPSite;

            slConfig.Site = site;
            slConfig.RemoveTypeMapping <IConfigManager>(null);
            slConfig.RemoveTypeMapping <IHierarchicalConfig>(null);
            SharePointServiceLocator.Reset();
        }
Beispiel #4
0
        public void SerLocConfigRemoveTypeMappings()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IConfig, ConfigTest>();
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            target.RemoveTypeMappings <IConfig>();
            SharePointServiceLocator.Reset();
            Assert.AreEqual(actual.Count - 1, target.GetTypeMappings().Count());
        }
Beispiel #5
0
        public void SetServiceLocatorTest()
        {
            SharePointServiceLocator.ReplaceCurrentServiceLocator(SharePointServiceLocator.Current);

            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IFirstType, FirstTest1>();
            target.RegisterTypeMapping <IFirstType, FirstTest1>("First");
            target.RegisterTypeMapping <IFirstType, FirstTest2>("Second");
            SharePointServiceLocator.Reset();


            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>(), typeof(FirstTest1));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>("First"), typeof(FirstTest1));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>("Second"), typeof(FirstTest2));
        }
Beispiel #6
0
        public void SerLocConfigRegisterTypeMappingOverwritekey()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();
            int beforeCount;

            target.RegisterTypeMapping <IConfig, ConfigTest>("key");
            actual = new List <TypeMapping>(target.GetTypeMappings());

            beforeCount = actual.Count;
            target.RegisterTypeMapping <IConfig, ConfigTest1>("key");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>("key"), typeof(ConfigTest1));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            Assert.AreEqual(beforeCount, actual.Count);
        }
Beispiel #7
0
        public void SetServiceLocatorTest2()
        {
            SharePointServiceLocator.ReplaceCurrentServiceLocator(SharePointServiceLocator.Current);

            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IFirstType, FirstTest1>();
            target.RegisterTypeMapping <IFirstType, FirstTest1>("First");
            target.RegisterTypeMapping <IFirstType, FirstTest2>("Second");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>(), typeof(FirstTest1));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>("First"), typeof(FirstTest1));

            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <ILogger>(), typeof(SharePointLogger));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <ITraceLogger>(), typeof(TraceLogger));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IEventLogLogger>(), typeof(EventLogLogger));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfigManager>(), typeof(HierarchicalConfig));
        }
        /// <summary>
        /// Provisions the service locator settings, and ensures the list is created for storing configuration
        /// on the site collection root web.  The service locator configuration is defined for the site level.
        /// </summary>
        /// <param name="properties">The properties for this configuration</param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            string configListLocation = CentralSiteConfig.GetCentralConfigSiteUrl();

            // Configuration List Deployment
            using (var centralSite = new SPSite(configListLocation))
            {
                ConfigurationList.EnsureConfigurationList(centralSite);
            }

            var site     = properties.Feature.Parent as SPSite;
            var slConfig = SharePointServiceLocator.GetCurrent(site).GetInstance <IServiceLocatorConfig>();

            slConfig.Site = site;
            slConfig.RegisterTypeMapping <IConfigManager, ListBackedConfigManager>();
            slConfig.RegisterTypeMapping <IHierarchicalConfig, ListBackedHierarchicalConfig>();
            SharePointServiceLocator.Reset();
            ConfigurationList.EnsureConfigurationList(site);

            // Add WP to new page and add to navigation


            AddWPToSiteNavigation(site.RootWeb, "listconfig.aspx", "List Configuration Test", wpXml, "left");
        }
Beispiel #9
0
 public void Cleanup()
 {
     SharePointServiceLocator.Reset();
     Isolate.CleanUp();
 }
 public void CleanupMocks()
 {
     Isolate.CleanUp();
     SharePointServiceLocator.Reset();
 }
 public void Cleanup()
 {
     SharePointServiceLocator.Reset();
     SharePointEnvironment.Reset();
 }
Beispiel #12
0
 //TODO: expected Exception
 public void NullInstanceTest()
 {
     SharePointServiceLocator.Reset();
     Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>(), null);
 }
 public void CleanupTest()
 {
     SharePointServiceLocator.Reset();
 }
Beispiel #14
0
 public void TestCleanup()
 {
     Isolate.CleanUp();
     SharePointServiceLocator.Reset();
 }
Beispiel #15
0
 public void Teardown()
 {
     SharePointServiceLocator.Reset();
     SharePointEnvironment.Reset();
 }