public void CustomSettingsCanBeRetrieved() { _appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nProperty1: Foo\r\nProperty2: Bar"); IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1)); var settings = loader.LoadSettings().First(); Assert.That(settings.Name, Is.EqualTo("Default")); Assert.That(settings["Property1"], Is.EqualTo("Foo")); Assert.That(settings["Property2"], Is.EqualTo("Bar")); }
public void SaveSettingsAndLoadSettingsTest() { var settings = new[] { new ShellSettings { Name = "租户1" }, new ShellSettings { Name = "租户2" }, new ShellSettings { Name = "租户3" } }; foreach (var setting in settings) { ShellSettingsManager.SaveSettings(setting); } var settingsList = ShellSettingsManager.LoadSettings().ToArray(); Assert.IsTrue(settingsList.Length >= 3); foreach (var setting in settings) { Assert.IsTrue(settingsList.Any(i => i.Name == setting.Name)); } Assert.IsTrue(_eventIsRun); }
public void EncryptionSettingsAreStoredAndReadable() { IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); var foo = new ShellSettings { Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux", EncryptionAlgorithm = "AES", EncryptionKey = "ABCDEFG", HashAlgorithm = "HMACSHA256", HashKey = "HIJKLMN" }; loader.SaveSettings(foo); Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1)); var settings = loader.LoadSettings().First(); Assert.That(settings.EncryptionAlgorithm, Is.EqualTo("AES")); Assert.That(settings.EncryptionKey, Is.EqualTo("ABCDEFG")); Assert.That(settings.HashAlgorithm, Is.EqualTo("HMACSHA256")); Assert.That(settings.HashKey, Is.EqualTo("HIJKLMN")); }
public void CustomSettingsCanBeStoredAndRetrieved() { IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); var foo = new ShellSettings { Name = "Default" }; foo["Property1"] = "Foo"; foo["Property2"] = "Bar"; loader.SaveSettings(foo); Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1)); var settings = loader.LoadSettings().First(); Assert.That(settings.Name, Is.EqualTo("Default")); Assert.That(settings["Property1"], Is.EqualTo("Foo")); Assert.That(settings["Property2"], Is.EqualTo("Bar")); }
/// <summary> /// 执行命令。 /// </summary> /// <param name="context">命令执行上下文。</param> public override void Execute(CommandExecuteContext context) { var settings = ShellSettingsManager.LoadSettings() .FirstOrDefault(i => i.Name.Equals(TenantName, StringComparison.OrdinalIgnoreCase)); if (settings == null) { context.WriteLine("找名称为 '{0}' 的租户信息。", TenantName); return; } if (Domains == null) { Domains = new List <string>(); } Domains = Domains.Where(i => !string.IsNullOrWhiteSpace(i)).Select(i => i.Trim()).ToList(); var host = settings["RequestUrlHost"]; string[] hosts = null; var msg = string.Empty; context.Is(() => { msg = "添加"; var list = string.IsNullOrWhiteSpace(host) ? new string[0] : host.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); var domains = Domains.Where(i => !list.Any(d => i.Equals(d, StringComparison.OrdinalIgnoreCase))); hosts = list.Concat(domains).ToArray(); }, "Add-SiteDomain"); context.Is(() => { msg = "设置"; hosts = Domains.ToArray(); }, "Set-SiteDomain"); context.Is(() => { msg = "删除"; var list = string.IsNullOrWhiteSpace(host) ? new string[0] : host.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); hosts = list.Where(i => !Domains.Any(d => i.Equals(d, StringComparison.OrdinalIgnoreCase))).ToArray(); }, "Remove-SiteDomain", "Delete-SiteDomain"); if (hosts == null) { return; } settings["RequestUrlHost"] = string.Join(",", hosts); ShellSettingsManager.SaveSettings(settings); context.WriteLine(msg + "成功。"); }
public void NewSettingsCanBeStored() { _appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else"); IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); var foo = new ShellSettings { Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux" }; Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1)); loader.SaveSettings(foo); Assert.That(loader.LoadSettings().Count(), Is.EqualTo(2)); var text = _appDataFolder.ReadFile("Sites\\Foo\\Settings.txt"); Assert.That(text, Is.StringContaining("Foo")); Assert.That(text, Is.StringContaining("Bar")); Assert.That(text, Is.StringContaining("Quux")); }
public void SingleSettingsFileShouldComeBackAsExpected() { _appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else"); IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); var settings = loader.LoadSettings().Single(); Assert.That(settings, Is.Not.Null); Assert.That(settings.Name, Is.EqualTo(ShellSettings.DefaultName)); Assert.That(settings.DataProvider, Is.EqualTo("SqlCe")); Assert.That(settings.DataConnectionString, Is.EqualTo("something else")); }
public void SettingsDontLoseTenantState() { IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); var foo = new ShellSettings { Name = "Default" }; foo.State = TenantState.Disabled; loader.SaveSettings(foo); var settings = loader.LoadSettings().First(); Assert.That(settings.Name, Is.EqualTo("Default")); Assert.That(settings.State, Is.EqualTo(TenantState.Disabled)); }
public void MultipleFilesCanBeDetected() { _appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else"); _appDataFolder.CreateFile("Sites\\Another\\Settings.txt", "Name: Another\r\nDataProvider: SqlCe2\r\nDataConnectionString: something else2"); IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock <IShellSettingsManagerEventHandler>().Object); var settings = loader.LoadSettings(); Assert.Equal(settings.Count(), 2); var def = settings.Single(x => x.Name == ShellSettings.DefaultName); Assert.Equal(def.Name, ShellSettings.DefaultName); Assert.Equal(def.DataProvider, "SqlCe"); Assert.Equal(def.DataConnectionString, "something else"); var alt = settings.Single(x => x.Name == "Another"); Assert.Equal(alt.Name, "Another"); Assert.Equal(alt.DataProvider, "SqlCe2"); Assert.Equal(alt.DataConnectionString, "something else2"); }