Example #1
0
        public void TestGetConfigLineMixedCase()
        {
            config = Config.FromText("[Section]\r\nKey=bob");

            var result = config.GetValue("section", "key", "default");

            Assert.AreEqual("bob", result);
        }
Example #2
0
        public void TestAsAliasWhenFalse()
        {
            var config = new Config();

            Mock<IConfigService>()
                .Setup(call => call.GetConfig())
                .Returns(config);

            Assert.IsFalse(service.IsAlias("test"));
        }
Example #3
0
        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"));
        }
Example #4
0
        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"));
        }
Example #5
0
        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);
        }
Example #6
0
        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));
        }
Example #7
0
        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));
        }
Example #8
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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]);
        }
Example #13
0
        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]);
        }
Example #14
0
        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());
        }
Example #15
0
        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);
        }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        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));
        }
Example #19
0
 /// <summary>
 /// Sets the configuration.
 /// </summary>
 /// <param name="config">The configuration to set.</param>
 public void SetConfig(Config config)
 {
     config.Write(GetConfigurationFilename());
 }
Example #20
0
        /// <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;
        }
Example #21
0
        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);
        }
Example #22
0
        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);
        }
Example #23
0
 public void SetUp()
 {
     fileService = new Mock<IFileService>();
     config = new Config {FileService = fileService.Object};
 }
Example #24
0
        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);
        }
Example #25
0
        public void TestToString()
        {
            config = Config.FromText("");

            config.SetValue("section", "key", "default");

            var result = config.ToString();

            Assert.AreEqual("[section]\r\nkey=default\r\n", result);
        }
Example #26
0
        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));
        }
Example #27
0
        /// <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);
        }