public void GetUriFromCredentials_ReturnsCorrect() { var credentials = new Dictionary <string, Credential>() { { "uri", new Credential("https://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("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); }
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 GetUsernameFromCredentials_ReturnsCorrect() { var credentials = new Dictionary <string, Credential>() { { "username", new Credential("username") } }; var tags = new Tags(new string[] { "foo", "bar" }); var scheme = "scheme"; var sif = new TestServiceInfoFactory(tags, scheme); var uname = sif.GetUsernameFromCredentials(credentials); Assert.Equal("username", uname); credentials = new Dictionary <string, Credential>() { { "user", new Credential("username") } }; uname = sif.GetUsernameFromCredentials(credentials); Assert.Equal("username", uname); credentials = new Dictionary <string, Credential>() { }; uname = sif.GetUsernameFromCredentials(credentials); Assert.Null(uname); }
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 TagsMatch_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[] { "bar" } }; Assert.True(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 LabelStartsWithTag_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 = "foobarfoo" }; Assert.True(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 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)); }
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_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")); }