public void TestGetConfigLineMixedCase() { config = Config.FromText("[Section]\r\nKey=bob"); var result = config.GetValue("section", "key", "default"); Assert.AreEqual("bob", result); }
public void TestAsAliasWhenFalse() { var config = new Config(); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); Assert.IsFalse(service.IsAlias("test")); }
public void TestAsAliasWhenTrue() { var config = new Config(); config.SetValue("Aliases", "test", "alias one"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); Assert.IsTrue(service.IsAlias("test")); }
public void TestGetAlias() { var config = new Config(); config.SetValue("Aliases", "test", "alias one"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); Assert.AreEqual("alias one", service.GetAlias("test")); }
public void TestMergeConfig() { var toMerge = new Config(); toMerge.Lines.Add(new ConfigLine { Key = "key", Value = "New Value", Section = "section" }); config.Lines.Add(new ConfigLine { Key = "key", Value = "Old Value", Section = "section" }); var result = config.Merge(toMerge); Assert.AreEqual(1, result.Lines.Count); Assert.AreEqual("New Value", result.Lines[0].Value); }
public void TestSetAliasWithSingleQuotes() { var config = new Config(); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.SetAlias("test", "alias 'three four'"); Assert.AreEqual(@"alias ""three four""", config.GetValue("Aliases", "test", string.Empty)); }
public void TestSetAlias() { var config = new Config(); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.SetAlias("test", "alias"); Assert.AreEqual("alias", config.GetValue("Aliases", "test", string.Empty)); }
public void TestDeleteValue() { config = Config.FromText(""); config.SetValue("section2", "key1", "default"); config.SetValue("section2", "key2", "default"); config.Delete("section2", "key1"); var result = config.ToString(); Assert.AreEqual("[section2]\r\nkey2=default\r\n", result); }
public void TestGetCredentialsWhenNotSet() { var config = new Config(); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); var result = service.CredentialsSet(); Assert.AreEqual(false, result); }
public void TestGetCredentialsWhenSet() { var config = new Config(); config.SetValue("Credentials", "Server", "example.com"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); var result = service.CredentialsSet(); Assert.AreEqual(true, result); }
public void TestAddNickname() { var config = new Config(); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.Add("bob"); var section = config.GetSection("Nicknames"); Assert.AreEqual(1, section.Count); Assert.AreEqual("bob", section[0].Key); }
public void TestListNicknames() { var config = new Config(); config.SetValue("Nicknames", "bob", string.Empty); config.SetValue("Nicknames", "alice", string.Empty); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); var results = service.List(); Assert.AreEqual(2, results.Count); Assert.AreEqual("bob", results[0]); Assert.AreEqual("alice", results[1]); }
public void TestListAliases() { var config = new Config(); config.SetValue("Aliases", "test one", "alias one"); config.SetValue("Aliases", "test two", "alias two"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); var lines = service.ListAliases(); Assert.AreEqual(2, lines.Count); Assert.AreEqual("test one=alias one", lines[0]); Assert.AreEqual("test two=alias two", lines[1]); }
public void TestIsNewVersionAvailableWhenFalse() { var config = new Config(); config.SetValue("Update", "Current", "http://localhost/HipBot.12345678.zip"); config.SetValue("Update", "Url", "http://localhost/version.txt"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); Mock<IHttpService>() .Setup(call => call.Get("http://localhost/version.txt")) .Returns(new FakeHttpResponse("http://localhost/HipBot.12345678.zip")); Assert.IsFalse(service.IsNewVersionAvailable()); }
public void TestGetCredentials() { var config = new Config(); config.SetValue("Credentials", "Server", "irc.example.com"); config.SetValue("Credentials", "Port", "123"); config.SetValue("Credentials", "Password", "Password"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); var result = service.GetCredentials(); Assert.AreEqual("irc.example.com", result.Server); Assert.AreEqual(123, result.Port); Assert.AreEqual("Password", result.Password); }
public void TestRemoveNickname() { var config = new Config(); config.SetValue("Nicknames", "bob", string.Empty); config.SetValue("Nicknames", "alice", string.Empty); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.Remove("bob"); var section = config.GetSection("Nicknames"); Assert.AreEqual(1, section.Count); Assert.AreEqual("alice", section[0].Key); }
public void TestGetCredentials() { var config = new Config(); config.SetValue("Credentials", "Name", "Bob"); config.SetValue("Credentials", "JabberID", "123"); config.SetValue("Credentials", "Password", "Password"); config.SetValue("Credentials", "ApiToken", "123456"); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); var result = service.GetCredentials(); Assert.AreEqual("123456", result.ApiToken); Assert.AreEqual("123", result.JabberId); Assert.AreEqual("Bob", result.Name); Assert.AreEqual("Password", result.Password); }
public void TestStoreCredentials() { var config = new Config(); var credentials = new Credentials { Name = "Bob", JabberId = "123", Password = "******", ApiToken = "123456" }; Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.SetCredentials(credentials); Assert.AreEqual("123456", config.GetValue("Credentials", "ApiToken", string.Empty)); Assert.AreEqual("123", config.GetValue("Credentials", "JabberID", string.Empty)); Assert.AreEqual("Bob", config.GetValue("Credentials", "Name", string.Empty)); Assert.AreEqual("Password", config.GetValue("Credentials", "Password", string.Empty)); }
/// <summary> /// Sets the configuration. /// </summary> /// <param name="config">The configuration to set.</param> public void SetConfig(Config config) { config.Write(GetConfigurationFilename()); }
/// <summary> /// Merges the specified to configuration into a new configuration. /// </summary> /// <param name="toMerge">To merge.</param> /// <returns></returns> public Config Merge(Config toMerge) { var config = new Config(Lines); foreach (var line in toMerge.Lines) { config.Remove(line); config.Lines.Add(line); } return config; }
private void ExpectCallToGetConfiguration() { var config = new Config(); config.SetValue("Nicknames", "bob", string.Empty); config.SetValue("Nicknames", "alice", string.Empty); Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); }
public void TestSetConfigLineDoesntDuplicate() { config = Config.FromText(""); config.SetValue("section", "key", "value1"); config.SetValue("section", "key", "value2"); Assert.AreEqual("section", config.Lines[0].Section); Assert.AreEqual("key", config.Lines[0].Key); Assert.AreEqual("value2", config.Lines[0].Value); }
public void SetUp() { fileService = new Mock<IFileService>(); config = new Config {FileService = fileService.Object}; }
public void TestToStringMultipleSections() { config = Config.FromText(""); config.SetValue("section1", "key1", "default"); config.SetValue("section2", "key2", "default"); var result = config.ToString(); Assert.AreEqual("[section1]\r\nkey1=default\r\n\r\n[section2]\r\nkey2=default\r\n", result); }
public void TestToString() { config = Config.FromText(""); config.SetValue("section", "key", "default"); var result = config.ToString(); Assert.AreEqual("[section]\r\nkey=default\r\n", result); }
public void TestStoreCredentials() { var config = new Config(); var credentials = new Credentials { Server = "irc.example.com", Port = 123, Password = "******" }; Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.SetCredentials(credentials); Assert.AreEqual("123", config.GetValue("Credentials", "Port", string.Empty)); Assert.AreEqual("irc.example.com", config.GetValue("Credentials", "Server", string.Empty)); Assert.AreEqual("Password", config.GetValue("Credentials", "Password", string.Empty)); }
/// <summary> /// Initializes a new instance of the <see cref="Config"/> class from the given text. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static Config FromText(string text) { var lines = new Config().Parse(text); return FromConfigLines(lines); }