public void GetSettings_ReturnsDefaultInstance_IfEmptyDictionaryRegistered() { // Arrange SettingsDictionary instance = new SettingsDictionary(); instance.Clear(); _resolverMock.Setup(r => r.GetService(typeof(SettingsDictionary))) .Returns(instance) .Verifiable(); // Act SettingsDictionary actual = _resolverMock.Object.GetSettings(); // Assert Assert.NotSame(instance, actual); _resolverMock.Verify(); }
public void GetSettings_ReturnsDefaultInstance_IfEmptyDictionaryRegistered() { // Arrange SettingsDictionary instance = new SettingsDictionary(); instance.Clear(); _resolverMock.Setup(r => r.GetService(typeof(SettingsDictionary))) .Returns(instance) .Verifiable(); // Act SettingsDictionary actual = _resolverMock.Object.GetSettings(); // Assert Assert.NotSame(instance, actual); _resolverMock.Verify(); }
/// <summary> /// Stub function, this does the actual file loading. Run LoadFile(), not this function directly. /// </summary> private void LoadFile_() { CurrentGroup = ""; SettingsDictionary.Clear(); using (var sr = new StreamReader(Filename)) { while (!sr.EndOfStream) { var thisLine = sr.ReadLine(); if (thisLine == null || thisLine.StartsWith(";")) // -- Comment { continue; } if (thisLine.Contains(";")) // -- Deal with mid-line comments. { thisLine = thisLine.Substring(0, thisLine.IndexOf(";")); } if (!thisLine.Contains("=") && (!thisLine.Contains("[") && !thisLine.Contains("]"))) { continue; } if ((thisLine.StartsWith("[") && thisLine.EndsWith("]"))) // -- Group. { var grpName = thisLine.Substring(1, thisLine.Length - 2); Dictionary <string, string> group; while (SettingsDictionary.TryGetValue(grpName, out group)) { grpName += "§"; continue; } SettingsDictionary.Add(grpName, new Dictionary <string, string>()); CurrentGroup = grpName; continue; } if (!thisLine.Contains("=")) { continue; } var key = thisLine.Substring(0, thisLine.IndexOf("=")).Trim(' '); var value = thisLine.Substring(thisLine.IndexOf("=") + 1, thisLine.Length - (thisLine.IndexOf("=") + 1)) .Trim(' '); // -- Setting. if (CurrentGroup == "" && !SettingsDictionary.ContainsKey("")) { SettingsDictionary.Add("", new Dictionary <string, string>()); } if (SettingsDictionary[CurrentGroup].ContainsKey(key)) { SettingsDictionary[CurrentGroup][key] = value; } else { SettingsDictionary[CurrentGroup].Add(key, value); } } } }
public void Clear() { SettingsDictionary.Clear(); }