public void RemoveTypeMappingsGeneric_RemoveAMapping() { //Arrange var typeMappings = new List <TypeMapping> { TypeMapping.Create <ILogger, SharePointLogger>(), TypeMapping.Create <IConfigManager, ConfigManager>(), TypeMapping.Create <IHierarchicalConfig, HierarchicalConfig>() }; var config = new ServiceLocationConfigData(typeMappings); var bag = new BIPropertyBag(); BSPFarm.SetLocal(); var cfgMgr = new SIConfigManager { ContainsKeyInPropertyBagStringIPropertyBag = (key, propertyBag) => true, CanAccessFarmConfigGet = () => true, GetPropertyBagConfigLevel = (configlevel) => bag, }; cfgMgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, propetyBag) => config); cfgMgr.BehaveAsDefaultValue(); //Act var target = new ServiceLocatorConfig(cfgMgr); target.RemoveTypeMappings <ILogger>(); List <TypeMapping> registeredTypeMappings = target.GetTypeMappings().ToList(); //Assert Assert.AreEqual(2, registeredTypeMappings.Count); Assert.AreSame(typeMappings[1], registeredTypeMappings[0]); Assert.AreSame(typeMappings[2], registeredTypeMappings[1]); }
public void RegisterTypeMapping_SetANewMappingForExistingMapping() { //Arrange List <TypeMapping> mappings = null; var propertyBag = new BIPropertyBag(); BSPFarm.SetLocal(); var configMgr = new SIConfigManager { ContainsKeyInPropertyBagStringIPropertyBag = (stringValue, farm) => false, SetInPropertyBagStringObjectIPropertyBag = (strValue, obj, farm) => mappings = obj as List <TypeMapping>, CanAccessFarmConfigGet = () => true, GetPropertyBagConfigLevel = (configlevel) => propertyBag }; configMgr.BehaveAsDefaultValue(); //Act var target = new ServiceLocatorConfig(configMgr); target.RegisterTypeMapping <ISomething, Something>(); target.RegisterTypeMapping <ISomething, SomethingElse>(); TypeMapping mapping = mappings.First(); //Assert Assert.IsTrue(mapping.ToType.Contains("SomethingElse")); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb web = properties.Feature.Parent as SPWeb; IConfigManager hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IConfigManager>(); hierarchicalConfig.SetInPropertyBag(Constants.SubSiteCreationConfigSiteKey, web.Url, SPFarm.Local); SPList taskList = web.Lists[taskListName]; SPList historyList = web.Lists[workflowHistoryName]; SPList subSiteCreationRequestList = web.Lists[subSiteRequestsListName]; var existingAssociation = subSiteCreationRequestList.WorkflowAssociations.GetAssociationByName(workflowTemplateName, CultureInfo.CurrentCulture); if (existingAssociation == null) { SPWorkflowManager workflowManager = web.Site.WorkflowManager; SPWorkflowTemplateCollection templates = workflowManager.GetWorkflowTemplatesByCategory(web, null); SPWorkflowTemplate template = templates.GetTemplateByBaseID(workflowTemplateId); SPWorkflowAssociation association = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, historyList); association.AllowManual = true; association.AutoStartCreate = true; subSiteCreationRequestList.AddWorkflowAssociation(association); subSiteCreationRequestList.Update(); association.Enabled = true; } ServiceLocatorConfig typeMappings = new ServiceLocatorConfig(); typeMappings.RegisterTypeMapping <IBusinessEventTypeConfigurationRepository, BusinessEventTypeConfigurationRepository>(); typeMappings.RegisterTypeMapping <ISubSiteCreationRequestRepository, SubSiteCreationRequestsRepository>(); }
public void RegisterTypeMapping_SaveNewMappingWithNoContext_ThrowsInvalidOperationException() { // Arrange object value = null; var rootConfig = new BIPropertyBag(); bool expectedExceptionThrown = false; var mgr = new SIConfigManager { ContainsKeyInPropertyBagStringIPropertyBag = (stringValue, propertyBag) => false, SetInPropertyBagStringObjectIPropertyBag = (strValue, obj, propertyBag) => value = obj as List <TypeMapping>, GetPropertyBagConfigLevel = (level) => rootConfig, CanAccessFarmConfigGet = () => false }; mgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, bag) => null); //Act var target = new ServiceLocatorConfig(mgr); try { target.RegisterTypeMapping <ISomething, Something>(); } catch (InvalidOperationException) { expectedExceptionThrown = true; } Assert.IsTrue(expectedExceptionThrown); }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { ServiceLocatorConfig serviceLocatorConfig = new ServiceLocatorConfig(); serviceLocatorConfig.RegisterTypeMapping<IIssueManagementRepository, IssueManagementRepository>(); }
public void SetSiteCacheInterval_WithValidValue_UpdatesConfiguration() { //Arrange int expected = 30; string expectedKey = "Microsoft.Practices.SharePoint.Common.SiteLocatorCacheInterval"; var bag = new BIPropertyBag(); int target = -1; var cfgMgr = new SIConfigManager(); cfgMgr.SetInPropertyBagStringObjectIPropertyBag = (key, value, propBag) => { if (key == expectedKey) { target = (int)value; } }; cfgMgr.GetPropertyBagConfigLevel = (configlevel) => bag; var config = new ServiceLocatorConfig(cfgMgr); //Act config.SetSiteCacheInterval(expected); //Assert Assert.AreEqual(expected, target); }
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 CanRemoveTypeMapping() { var mockPropertyBag = new MockPropertyBag(); MockConfigManager hierarchicalConfig = new MockConfigManager(); List <TypeMapping> typeMappings = new List <TypeMapping>(); typeMappings.Add(new TypeMapping() { FromAssembly = "1" }); typeMappings.Add(new TypeMapping() { FromAssembly = "2" }); typeMappings.Add(new TypeMapping() { FromAssembly = "3" }); hierarchicalConfig.Value = new List <TypeMapping>(typeMappings); var target = new ServiceLocatorConfig(hierarchicalConfig); target.RemoveTypeMapping(typeMappings[0]); IEnumerable <TypeMapping> registeredTypeMappings = target.GetTypeMappings(); Assert.AreEqual(2, registeredTypeMappings.Count()); Assert.AreSame(typeMappings[1], registeredTypeMappings.First()); Assert.AreSame(typeMappings[2], registeredTypeMappings.ElementAt(1)); }
public void CanGetTypeMappings() { var mockPropertyBag = new MockPropertyBag(); MockConfigManager hierarchicalConfig = new MockConfigManager(); List <TypeMapping> typeMappings = new List <TypeMapping>(); typeMappings.Add(new TypeMapping() { FromAssembly = "1" }); typeMappings.Add(new TypeMapping() { FromAssembly = "2" }); typeMappings.Add(new TypeMapping() { FromAssembly = "3" }); hierarchicalConfig.Value = typeMappings; var target = new ServiceLocatorConfig(hierarchicalConfig); IEnumerable <TypeMapping> registeredTypeMappings = target.GetTypeMappings(); Assert.AreEqual(3, registeredTypeMappings.Count()); }
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); }
public override void FeatureInstalled(SPFeatureReceiverProperties properties) { ServiceLocatorConfig typeMappings = new ServiceLocatorConfig(); typeMappings.RegisterTypeMapping <IBusinessEventTypeConfigurationRepository, BusinessEventTypeConfigurationRepository>(); typeMappings.RegisterTypeMapping <ISubSiteCreationRequestRepository, SubSiteCreationRequestsRepository>(); }
public void SerLocConfigGetTypeMappingsTest() { ServiceLocatorConfig target = new ServiceLocatorConfig(); List <TypeMapping> actual; actual = new List <TypeMapping>(target.GetTypeMappings()); Assert.IsTrue(actual.Count > 0); }
public override void FeatureInstalled(SPFeatureReceiverProperties properties) { ServiceLocatorConfig typeMappings = new ServiceLocatorConfig(); typeMappings.RegisterTypeMapping <IIncidentManagementRepository, IncidentManagementRepository>(); typeMappings.RegisterTypeMapping <IPricingRepository, PricingRepository>(); typeMappings.RegisterTypeMapping <IProductCatalogRepository, CachedBdcProductCatalogRepository>(); }
public override void Load() { Kernel.Bind <IExceptionLogger>().To <ElmahExceptionLogger>(); Kernel.Bind <IUserIdentityProvider>().To <ClaimsPrincipalUserIdentityProvider>(); Kernel.Bind <IObjectMapper>().ToConstant(new AutoMapperObjectMapper()); ServiceLocatorConfig.Configure(Kernel); }
public void RegisterTypeMapping_SaveNewMappingWithSite() { var mappings = new List <TypeMapping>(); string savedkey = null; object savedValue = null; var configData = new ServiceLocationConfigData(mappings); BSPFarm.SetLocal(); const string expectedKey = "Microsoft.Practices.SharePoint.Common.TypeMappings"; var web = new MSPWeb(); var propBag = new BIPropertyBag(); var mgr = new SIConfigManager() { SetInPropertyBagStringObjectIPropertyBag = (key, value, bag) => { savedkey = key; savedValue = value; }, ContainsKeyInPropertyBagStringIPropertyBag = (key, bag) => { if (key == expectedKey) { return(true); } return(false); }, CanAccessFarmConfigGet = () => true, GetPropertyBagConfigLevel = (level) => propBag, SetWebSPWeb = (w) => { }, }; mgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, bag) => { if (key == expectedKey) { return(configData); } return(null); }); var configSite = new MSPSite() { RootWebGet = () => web }; var target = new ServiceLocatorConfig(mgr); target.Site = configSite; //act target.RegisterTypeMapping <ISomething, Something>(); //assert Assert.IsNotNull(savedValue); Assert.AreEqual(expectedKey, savedkey); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); AutoMapperWebConfiguration.Configure(); ServiceLocatorConfig.RegisterContainer(new WebInstaller()); Database.SetInitializer(new DbInitializer()); }
void ISPServiceBehaviorAccessor.SetContainerAsFarm() { _container = SharePointServiceLocator.GetCurrentFarm(); _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig); if (_registrar == null) { throw new NullReferenceException("registrar"); } }
void ISPServiceBehaviorAccessor.SetContainer(SPSite site) { _container = (site != null ? SharePointServiceLocator.GetCurrent(site) : SharePointServiceLocator.GetCurrent()); _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig); if (_registrar == null) { throw new NullReferenceException("registrar"); } }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; if (site != null) { ServiceLocatorConfig serviceLocatorConfig = new ServiceLocatorConfig(); serviceLocatorConfig.Site = site; serviceLocatorConfig.RegisterTypeMapping <IPartManagementRepository, PartManagementRepository>(); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb incidentsWeb = properties.Feature.Parent as SPWeb; SPFile file = incidentsWeb.Files[IncidentDashboardFileName]; file.MoveTo(DefaultFileName, true); ServiceLocatorConfig config = new ServiceLocatorConfig(); config.RegisterTypeMapping <IIncidentTaskRepository, FullTextSearchIncidentTaskRepository>(); }
/// <summary> /// Initializes a new instance of the <see cref="SPServiceRegistrar"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="container">The container.</param> public SPServiceRegistrar(SPServiceLocator parent, SPIServiceLocator container) { _parent = parent; _container = container; _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig); if (_registrar == null) { throw new NullReferenceException("registrar"); } LifetimeForRegisters = ServiceRegistrarLifetime.Transient; }
public void SerLocConfigRegisterTypeMappingTestHelper() { int beforeCount; List <TypeMapping> actual; ServiceLocatorConfig target = new ServiceLocatorConfig(); actual = new List <TypeMapping>(target.GetTypeMappings()); beforeCount = actual.Count; target.RegisterTypeMapping <IConfig, ConfigTest>(); Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest)); actual = new List <TypeMapping>(target.GetTypeMappings()); Assert.AreEqual(beforeCount + 1, actual.Count); }
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()); }
public void RegisteringTypeMappingTwiceOverwritesLastOne() { var mockPropertyBag = new MockPropertyBag(); MockConfigManager hierarchicalConfig = new MockConfigManager(); var target = new ServiceLocatorConfig(hierarchicalConfig); target.RegisterTypeMapping <ISomething, Something>(); target.RegisterTypeMapping <ISomething, SomethingElse>(); var typeMappings = hierarchicalConfig.Value as List <TypeMapping>; TypeMapping mapping = typeMappings.First(); Assert.IsTrue(mapping.ToType.Contains("SomethingElse")); }
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)); }
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); }
public void CanRegisterTypeMappingWithKey() { var mockPropertyBag = new MockPropertyBag(); MockConfigManager hierarchicalConfig = new MockConfigManager(); var target = new ServiceLocatorConfig(hierarchicalConfig); target.RegisterTypeMapping <ISomething, Something>("key1"); target.RegisterTypeMapping <ISomething, Something>("key2"); var typeMappings = hierarchicalConfig.Value as List <TypeMapping>; TypeMapping mapping1 = typeMappings.First(); TypeMapping mapping2 = typeMappings.Skip(1).First(); Assert.AreEqual("key1", mapping1.Key); Assert.AreEqual("key2", mapping2.Key); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { featureDefinition = properties.Feature.Definition; SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent; webApp.WebConfigModifications.Add(GetModification()); webApp.Update(); webApp.WebService.ApplyWebConfigModifications(); ServiceLocatorConfig typeMappings = new ServiceLocatorConfig(); typeMappings.RegisterTypeMapping <IIncidentManagementRepository, IncidentManagementRepository>(); typeMappings.RegisterTypeMapping <IPricingRepository, PricingRepository>(); typeMappings.RegisterTypeMapping <IProductCatalogRepository, CachedBdcProductCatalogRepository>(); }
public void CTOR_ThrowsArgumentNullException_WithNullManager() { //Arrange bool argumentNullExceptionThrown = false; //act try { var target = new ServiceLocatorConfig((IConfigManager)null); } catch (ArgumentNullException) { argumentNullExceptionThrown = true; } //assert Assert.IsTrue(argumentNullExceptionThrown); }
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)); }
public void SitePropertySetter_ThrowsArgumentNullException_WithNullSite() { //Arrange bool argumentNullExceptionThrown = false; var target = new ServiceLocatorConfig(); //act try { target.Site = null; } catch (ArgumentNullException) { argumentNullExceptionThrown = true; } //assert Assert.IsTrue(argumentNullExceptionThrown); }