public void GetUriFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "uri", new Credential("http://boo:222") }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string scheme = "scheme";

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

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

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

            credentials = new Dictionary <string, Credential>()
            {
            };
            uri = sif.GetUriFromCredentials(credentials);
            Assert.Null(uri);
        }
        public void GetHostFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "host", new Credential("host") }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string 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);
        }
        public void GetIntFromCredentials_ThrowsFormatException()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "key", new Credential("foobar") }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string scheme = "scheme";

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

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

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

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

            Assert.False(sif.LabelStartsWithTag(service1));
        }
        public void UriMatchesScheme_DoesntMatch()
        {
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string scheme = "scheme";

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

            Assert.False(sif.UriMatchesScheme(service1));
        }
        public void GetPortFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "port", new Credential("123") }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string 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);;
        }
        public void GetPasswordFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "password", new Credential("password") }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string 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);
        }
        public void GetListFromCredentials_ThrowsWhenListNotPossible()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "foo", new Credential()
                  {
                      { "bar", new Credential()
                        {
                            { "bang", new Credential("badabing") }
                        } },
                  } }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string 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);
        }
        public void GetListFromCredentials_ReturnsCorrect()
        {
            var credentials = new Dictionary <string, Credential>()
            {
                { "uris", new Credential()
                  {
                      { "0", new Credential("http://foo:11") },
                      { "1", new Credential("http://bar:11") }
                  } }
            };
            Tags   tags   = new Tags(new string[] { "foo", "bar" });
            string 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("http://foo:11") || list[0].Equals("http://bar:11"));
            Assert.True(list[1].Equals("http://foo:11") || list[1].Equals("http://bar:11"));
        }