Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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]);
        }
Пример #6
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]);
        }
Пример #7
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());
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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"));
        }
Пример #13
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"));
        }
Пример #14
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);
        }
Пример #15
0
        public void TestSetAliasOverwritesExistingValue()
        {
            var config = new Config();
            config.SetValue("Aliases", "test", "alias one");

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

            service.SetAlias("test", "alias two");

            Assert.AreEqual("alias two", config.GetValue("Aliases", "test", string.Empty));
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
0
        public void TestRemoveAlias()
        {
            var config = new Config();
            config.SetValue("Aliases", "test", "alias one");

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

            service.RemoveAlias("test");

            Assert.AreEqual(string.Empty, config.GetValue("Aliases", "test", string.Empty));
        }
Пример #20
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);
        }