Esempio n. 1
0
        public void GetListFromCredentials_ThrowsWhenListNotPossible()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                {
                    "foo", new Credential()
                    {
                        {
                            "bar", new Credential()
                            {
                                { "bang", new Credential("badabing") }
                            }
                        },
                    }
                }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif = new TestServiceInfoFactory(tags, scheme);
            var ex  = Assert.Throws <ConnectorException>(() => sif.GetListFromCredentials(credentials, "foo"));

            Assert.Contains("key=foo", ex.Message);
            Assert.Contains("value=bar/", ex.Message);
        }
Esempio n. 2
0
        public void GetUriFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "uri", new Credential("https://boo:222") }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif = new TestServiceInfoFactory(tags, scheme);
            var uri = sif.GetUriFromCredentials(credentials);

            Assert.Equal("https://boo:222", uri);

            credentials = new Dictionary <string, Credential>()
            {
                { "url", new Credential("https://boo:222") }
            };
            uri = sif.GetUriFromCredentials(credentials);
            Assert.Equal("https://boo:222", uri);

            credentials = new Dictionary <string, Credential>()
            {
            };
            uri = sif.GetUriFromCredentials(credentials);
            Assert.Null(uri);
        }
Esempio n. 3
0
        public void GetHostFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "host", new Credential("host") }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif  = new TestServiceInfoFactory(tags, scheme);
            var host = sif.GetHostFromCredentials(credentials);

            Assert.Equal("host", host);

            credentials = new Dictionary <string, Credential>()
            {
                { "hostname", new Credential("hostname") }
            };
            host = sif.GetHostFromCredentials(credentials);
            Assert.Equal("hostname", host);

            credentials = new Dictionary <string, Credential>()
            {
            };
            host = sif.GetHostFromCredentials(credentials);
            Assert.Null(host);
        }
Esempio n. 4
0
        public void GetIntFromCredentials_ThrowsFormatException()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "key", new Credential("foobar") }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif = new TestServiceInfoFactory(tags, scheme);
            var ex  = Assert.Throws <FormatException>(() => sif.GetIntFromCredentials(credentials, "key"));
        }
Esempio n. 5
0
        public void TagsMatch_DoesntMatch()
        {
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif      = new TestServiceInfoFactory(tags, scheme);
            var service1 = new Service()
            {
                Tags = new string[] { "noMatch" }
            };

            Assert.False(sif.TagsMatch(service1));
        }
Esempio n. 6
0
        public void LabelStartsWithTag_DoesntMatch()
        {
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif      = new TestServiceInfoFactory(tags, scheme);
            var service1 = new Service()
            {
                Tags  = new string[] { "noMatch" },
                Label = "baby"
            };

            Assert.False(sif.LabelStartsWithTag(service1));
        }
Esempio n. 7
0
        public void UriMatchesScheme_Matches()
        {
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif      = new TestServiceInfoFactory(tags, scheme);
            var service1 = new Service()
            {
                Tags        = new string[] { "noMatch" },
                Label       = "noMatch",
                Credentials = new Dictionary <string, Credential>()
                {
                    { "uri", new Credential("scheme://foo") }
                }
            };

            Assert.True(sif.UriMatchesScheme(service1));
        }
Esempio n. 8
0
        public void GetPortFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "port", new Credential("123") }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif  = new TestServiceInfoFactory(tags, scheme);
            var port = sif.GetPortFromCredentials(credentials);

            Assert.Equal(123, port);
            credentials = new Dictionary <string, Credential>()
            {
            };
            port = sif.GetPortFromCredentials(credentials);
            Assert.Equal(0, port);
        }
Esempio n. 9
0
        public void GetPasswordFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "password", new Credential("password") }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif = new TestServiceInfoFactory(tags, scheme);
            var pwd = sif.GetPasswordFromCredentials(credentials);

            Assert.Equal("password", pwd);
            credentials = new Dictionary <string, Credential>()
            {
            };
            pwd = sif.GetPasswordFromCredentials(credentials);
            Assert.Null(pwd);
        }
Esempio n. 10
0
        public void GetListFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                {
                    "uris", new Credential()
                    {
                        { "0", new Credential("https://foo:11") },
                        { "1", new Credential("https://bar:11") }
                    }
                }
            };
            var tags   = new Tags(new string[] { "foo", "bar" });
            var scheme = "scheme";

            var sif  = new TestServiceInfoFactory(tags, scheme);
            var list = sif.GetListFromCredentials(credentials, "uris");

            Assert.NotNull(list);
            Assert.Equal(2, list.Count);
            Assert.True(list[0].Equals("https://foo:11") || list[0].Equals("https://bar:11"));
            Assert.True(list[1].Equals("https://foo:11") || list[1].Equals("https://bar:11"));
        }