/// <summary> /// Indexer for getting and setting values for the key specified. Setting values at the web application level will always /// result in a InvalidOperationException. /// </summary> /// <param name="key">The key to check for in the property bag</param> /// <returns>The value for the key, null if not found</returns> public string this[string key] { [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)] [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)] get { Validation.ArgumentNotNullOrEmpty(key, "key"); var args = new ReadConfigArgs(); args.Key = key; args.SiteId = siteId; args.Level = (int)ConfigLevel.CurrentSPWebApplication; object result = SPUtility.ExecuteRegisteredProxyOperation( ReadConfigArgs.OperationAssemblyName, ReadConfigArgs.OperationTypeName, args); if (result != null && result.GetType().IsSubclassOf(typeof(System.Exception))) { ExceptionHelper.ThrowSandboxConfigurationException((Exception)result, ConfigLevel.CurrentSPWebApplication); } return((string)result); } [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)] [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)] set { Validation.ArgumentNotNullOrEmpty(key, "key"); throw new InvalidOperationException(Resources.WriteNotAllowedInSandboxToWebApplication); } }
public void Execute_ReturnsConfigurationException_WhenWrongArgTypeProvided() { var proxyOp = new ProxyInstalledOperation(); var args = new ReadConfigArgs(); //Act object result = proxyOp.Execute(args); //Assert Assert.IsInstanceOfType(result, typeof(ConfigurationException)); }
public void Execute_ReturnsConfigurationException_WhenSiteIdIsEmpty() { var proxyOp = new ReadConfigurationOperation(); var args = new ReadConfigArgs(); args.Key = ConfigManager.PnPKeyNamespace + "." + TestsConstants.TestGuidName; args.Level = (int)ConfigLevel.CurrentSPWebApplication; //Act object result = proxyOp.Execute(args); //Assert Assert.IsInstanceOfType(result, typeof(ConfigurationException)); }
public void Execute_ReturnsArgumentNullException_WhenKeyIsNull() { var proxyOp = new ReadConfigurationOperation(); var args = new ReadConfigArgs(); args.Key = null; args.SiteId = TestsConstants.TestGuid; args.Level = (int)ConfigLevel.CurrentSPWebApplication; //Act object result = proxyOp.Execute(args); //Assert Assert.IsInstanceOfType(result, typeof(ArgumentNullException)); }
public void Execute_ReadKeyReturnsConfigurationException_WithInvalidLevel() { //arrange var args = new ReadConfigArgs(); string key = ConfigManager.PnPKeyNamespace + "." + TestsConstants.TestGuidName; var proxyOp = new ReadConfigurationOperation(); args.Key = key; args.Level = (int)ConfigLevel.CurrentSPWeb; args.SiteId = TestsConstants.TestGuid; //Act var target = proxyOp.Execute(args); //Assert Assert.IsInstanceOfType(target, typeof(ConfigurationException)); }
public void Execute_ReturnsAConfigurationException_WhenKeyDoesntHaveNamespace() { //arrange var args = new ReadConfigArgs(); args.Key = TestsConstants.TestGuidName; args.Level = (int)ConfigLevel.CurrentSPWebApplication; args.SiteId = TestsConstants.TestGuid; var proxyOp = new ReadConfigurationOperation(); //Act var ex = proxyOp.Execute(args); //Assert Assert.IsInstanceOfType(ex, typeof(ConfigurationException)); }
public void Execute_ReturnsNull_WithValidKeyNotSetAtFarmLevel() { //arrange SPFarmPropertyBag.ClearCache(); var args = new ReadConfigArgs(); string key = ConfigManager.PnPKeyNamespace + "." + TestsConstants.TestGuidName; var proxyOp = new ReadConfigurationOperation(); var f = new BSPConfiguredFarm(); args.Key = key; args.Level = (int)ConfigLevel.CurrentSPFarm; args.SiteId = TestsConstants.TestGuid; //Act var target = proxyOp.Execute(args); //Assert Assert.IsNull(target); }
public void Execute_ReturnsKeyData_WithValidKeyAtWebAppLevel() { //arrange SPWebAppPropertyBag.ClearCache(); var args = new ReadConfigArgs(); string key = ConfigManager.PnPKeyNamespace + "." + TestsConstants.TestGuidName; args.Key = key; args.Level = (int)ConfigLevel.CurrentSPWebApplication; args.SiteId = TestsConstants.TestGuid; var proxyOp = new ReadConfigurationOperation(); string expectedData = "{92700BB6-B144-434F-A97B-5F696068A425}"; MSPPersistedObject webPO; WebAppSettingStore wss; MSPSite.ConstructorGuid = (instance, guid) => { var site = new MSPSite(instance) { WebApplicationGet = () => { var webApp = new BSPConfiguredWebApp(); wss = new WebAppSettingStore(); wss.Settings[key] = expectedData; webPO = new MSPPersistedObject((SPPersistedObject)webApp.Instance); webPO.GetChildString <WebAppSettingStore>((s) => wss); return(webApp); }, Dispose = () => { } }; }; //Act object target = proxyOp.Execute(args); //Assert . Assert.IsInstanceOfType(target, typeof(string)); Assert.AreEqual(expectedData, (string)target); }
public void Execute_ReturnsKey_WithValidKeyAtFarmLevel() { //arrange SPFarmPropertyBag.ClearCache(); var args = new ReadConfigArgs(); string key = ConfigManager.PnPKeyNamespace + "." + TestsConstants.TestGuidName; var proxyOp = new ReadConfigurationOperation(); var f = new BSPConfiguredFarm(); string expectedData = "{92700BB6-B144-434F-A97B-5F696068A425}"; args.Key = key; args.Level = (int)ConfigLevel.CurrentSPFarm; args.SiteId = TestsConstants.TestGuid; f.SettingStore.Settings[key] = expectedData; //Act var target = proxyOp.Execute(args); //Assert Assert.IsInstanceOfType(target, typeof(string)); Assert.AreEqual(expectedData, target); }
public void Execute_ReturnsNull_WithValidKeyNotSetAtWebAppLevel() { //arrange SPWebAppPropertyBag.ClearCache(); var args = new ReadConfigArgs(); string key = ConfigManager.PnPKeyNamespace + "." + TestsConstants.TestGuidName; args.Key = key; args.Level = (int)ConfigLevel.CurrentSPWebApplication; args.SiteId = TestsConstants.TestGuid; var proxyOp = new ReadConfigurationOperation(); MSPPersistedObject webPO; WebAppSettingStore wss; MSPSite.ConstructorGuid = (instance, guid) => { var site = new MSPSite(instance) { WebApplicationGet = () => { var webApp = new BSPConfiguredWebApp(); wss = new WebAppSettingStore(); webPO = new MSPPersistedObject((SPPersistedObject)webApp.Instance); webPO.GetChildString <WebAppSettingStore>((s) => wss); return(webApp); }, Dispose = () => { } }; }; //Act object target = proxyOp.Execute(args); //Assert Assert.IsNull(target); }