public RailDriverSettings(IEnumerable <string> options, SettingsStore store) : base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "RailDriver")) { CalibrationSettings = new byte[DefaultCalibrationSettings.Length]; LoadSettings(options); }
public void GetLocalIniStoreFromNewFile() { string path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Ini, path, null); Assert.IsInstanceOfType(store, typeof(SettingsStoreLocalIni)); }
public void GetLocalIniStoreFromExistingFile() { string path = Path.GetTempFileName(); SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Ini, path, null); Assert.IsInstanceOfType(store, typeof(SettingsStoreLocalIni)); }
public void OpenRegistryStoreTest() { string path = "SOFTWARE\\OpenRails"; SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Registry, path, null); Assert.IsInstanceOfType(store, typeof(SettingsStoreRegistry)); }
public void ReadSingleFolderTest() { using (TestFile testFile = new TestFile("[Folders]\r\nName=string:Value")) { FolderSettings folders = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null)); Assert.IsTrue(folders.Folders.Count == 1); } }
public void OpenFolderSettingsTest() { using (TestFile testFile = new TestFile(string.Empty)) { FolderSettings folders = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null)); Assert.IsNotNull(folders.Folders); } }
public void GetSectionNamesTest() { string path = "SOFTWARE\\OpenRails"; SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Registry, path, null); var sections = store.GetSectionNames(); Assert.IsNotNull(sections); }
public void GetSettingValueTimeSpan() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name={nameof(TimeSpan)}:1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; Assert.AreEqual(TimeSpan.FromSeconds(1000), store.GetSettingValue("name", TimeSpan.Zero)); } }
public void GetSettingValueInt() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", "name=int:7" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; Assert.AreEqual(7, store.GetSettingValue("name", 0)); } }
public void GetSettingValueBool() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", "name=bool:true" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; Assert.IsTrue(store.GetSettingValue("name", false)); } }
public void GetSettingValueNotExisting() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", "name=bool:value" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; Assert.IsNull(store.GetSettingValue("name1", (string)null)); } }
public void GetSettingValueStringArray() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; CollectionAssert.AreEqual(new string[] { "0", "1", "10", "100", "1000" }, store.GetSettingValue("name", Array.Empty <string>())); } }
public void GetSettingValueIntArrayGeneric() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=int[]:0,1,10,100,1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; CollectionAssert.AreEqual(new int[] { 0, 1, 10, 100, 1000 }, store.GetSettingValue("name", new int[0])); } }
public void LoadSectionsEmptyTest() { using (TestFile file = new TestFile(string.Empty)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni; string[] sections = store.GetSectionNames(); CollectionAssert.AreEqual(Array.Empty <string>(), sections); } }
public void SetSettingValueEnum() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; store.SetSettingValue("enumValue", TestEnum.Value2); Assert.AreEqual(TestEnum.Value2, store.GetSettingValue("enumValue", default(TestEnum))); } }
public void SetSettingValueFlags() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; store.SetSettingValue("flagsValue", SimpleFlagsTest.Value2 | SimpleFlagsTest.Value1); Assert.AreEqual(SimpleFlagsTest.Value2 | SimpleFlagsTest.Value1, store.GetSettingValue("flagsValue", default(SimpleFlagsTest))); } }
public void SetSettingValueString() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; store.SetSettingValue("stringValue", "abcdef"); Assert.AreEqual("abcdef", store.GetSettingValue("stringValue", string.Empty)); } }
public void SetSettingValueByte() { string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" }); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni; store.SetSettingValue("byteValue", 127); Assert.AreEqual(127, store.GetSettingValue("byteValue", byte.MaxValue)); } }
public void SavedDedicatdTest() { using (TestFile testFile = new TestFile("[Folders]\r\nName=string:Value")) { FolderSettings source = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null)); source.Folders.Add("Another", "Folder"); source.Save("Another"); FolderSettings target = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null)); Assert.IsTrue(target.Folders.Count == 2); } }
public void ResetTest() { using (TestFile testFile = new TestFile("[Folders]\r\nName=string:Value")) { FolderSettings source = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null)); source.Reset(); source.Save(); FolderSettings target = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null)); Assert.IsTrue(target.Folders.Count == 0); } }
public void LoadSectionsSimpleTest() { string[] contentArray = new string[] { "[ORTS]", "[End]", "#[End]" }; string content = string.Join(Environment.NewLine, contentArray); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni; var sections = store.GetSectionNames(); CollectionAssert.AreEqual(contentArray.Where((s) => !s.StartsWith("#")).Select((s) => s.Trim('[', ']')).ToArray(), sections); } }
public void GetValueNamesSectionNotExistingTest() { string[] contentArray = new string[] { "[ORTS]", "name=value", "name1=value", "name2=value", "#[End]", "name=value", "[End]", "name=value" }; string content = string.Join(Environment.NewLine, contentArray); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "STRO") as SettingsStoreLocalIni; string[] names = store.GetSettingNames(); CollectionAssert.AreEqual(Array.Empty <string>(), names); } }
public void LoadSectionsExtendedTest() { string[] contentArray = new string[] { "[ORTS]", "name=value", "[End]", "name=value", "name=value", "#[End]" }; string content = string.Join(Environment.NewLine, contentArray); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni; string[] sections = store.GetSectionNames(); CollectionAssert.AreEqual(contentArray.Where((s) => s.StartsWith("[", StringComparison.OrdinalIgnoreCase)).Select((s) => s.Trim('[', ']')).ToArray(), sections); } }
public InputSettings(IEnumerable <string> options, SettingsStore store) : base(SettingsStore.GetSettingsStore(store?.StoreType ?? StoreType.Registry, store.Location, "Keyboard")) { InitializeCommands(UserCommands); LoadSettings(options); UserCommandModifierInput userCommandModifier = UserCommands[UserCommand.DisplayNextWindowTab] as UserCommandModifierInput; WindowTabCommandModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None); userCommandModifier = UserCommands[UserCommand.CameraMoveFast] as UserCommandModifierInput; CameraMoveFastModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None); userCommandModifier = UserCommands[UserCommand.CameraMoveSlow] as UserCommandModifierInput; CameraMoveSlowModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None); userCommandModifier = UserCommands[UserCommand.GameSuspendOldPlayer] as UserCommandModifierInput; GameSuspendOldPlayerModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None); userCommandModifier = UserCommands[UserCommand.GameSwitchWithMouse] as UserCommandModifierInput; GameSwitchWithMouseModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None); }
public void LoadSectionsExcessiveTest() { int count = 100; string[] contentArray = new string[count * 6]; for (int i = 0; i < 100; i++) { contentArray[i * 6 + 0] = "[ORTS]"; contentArray[i * 6 + 1] = "name=value"; contentArray[i * 6 + 2] = "[End]"; contentArray[i * 6 + 3] = "name=value"; contentArray[i * 6 + 4] = "name=value"; contentArray[i * 6 + 5] = "#[End]"; } string content = string.Join(Environment.NewLine, contentArray); using (TestFile file = new TestFile(content)) { SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni; string[] sections = store.GetSectionNames(); CollectionAssert.AreEqual(contentArray.Where((s) => s.StartsWith("[", StringComparison.OrdinalIgnoreCase)).Select((s) => s.Trim('[', ']')).ToArray(), sections); } }
public UpdateState(SettingsStore store) : base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "UpdateState")) { LoadSettings(new string[0]); }
public FolderSettings(IEnumerable <string> options, SettingsStore store) : base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "Folders")) { Folders = new Dictionary <string, string>(); LoadSettings(options); }
internal TrackViewerSettings(IEnumerable <string> options, SettingsStore store) : base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, SettingLiteral)) { LoadSettings(options); UserSettings = new UserSettings(options, store); }
public InputSettings(IEnumerable <string> options, SettingsStore store) : base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "Keyboard")) { InitializeCommands(Commands); LoadSettings(options); }
public UserSettings(IEnumerable <string> options) : this(options, SettingsStore.GetSettingsStore(SettingsStoreType, Location, null)) { }