public void ApplyNoRecordNameWithConnectionString_CouchbaseDnsSrvFound_Replaces(string scheme) { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync($"_{scheme}._tcp.services.local")) .ReturnsAsync(new List <SrvRecord> { SrvRecord1Priority10, SrvRecord2Priority10 }); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { ConnectionString = $"{scheme}://services.local/additionalPath?queryParam=5" }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition); // Assert Assert.Equal($"{scheme}://couchbaseserver1.services.local:8091,couchbaseserver2.services.local:8091/additionalPath?queryParam=5", clientDefinition.ConnectionString); Assert.Null(clientDefinition.Servers); }
public void ApplyNoRecordNameWithConnectionString_CouchbaseDnsSrvFound_IgnoresPriority() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(FullRecordName)) .ReturnsAsync(new List <SrvRecord> { SrvRecord1Priority10, SrvRecord2Priority10, SrvRecord3Priority20, SrvRecord4Priority20 }); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { ConnectionString = "couchbase://services.local" }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition); // Assert Assert.Equal("couchbase://couchbaseserver1.services.local:8091,couchbaseserver2.services.local:8091,couchbaseserver3.services.local:8091,couchbaseserver4.services.local:8091/", clientDefinition.ConnectionString); Assert.Null(clientDefinition.Servers); }
public void ApplyNoRecordNameWithConnectionString_MultipleEntriesWithSemicolon_NoDnsLookup() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(It.IsAny <string>())) .ReturnsAsync(new List <SrvRecord>()); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { ConnectionString = "couchbase://server;server2/" }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition); // Assert Assert.Equal("couchbase://server;server2/", clientDefinition.ConnectionString); Assert.Null(clientDefinition.Servers); lookupClient .Verify(m => m.QuerySrvAsync(It.IsAny <string>()), Times.Never); }
public void ApplyNoRecordNameWithConnectionString_CouchbaseNoDnsSrvFound_Unmodified() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(FullRecordName)) .ReturnsAsync(new List <SrvRecord>()); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { ConnectionString = "couchbase://services.local/" }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition); // Assert Assert.Equal("couchbase://services.local/", clientDefinition.ConnectionString); Assert.Null(clientDefinition.Servers); lookupClient .Verify(m => m.QuerySrvAsync(FullRecordName), Times.Once); }
public void ApplyNoRecordName_CouchbaseWithPort_NoDnsLookup() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(It.IsAny <string>())) .ReturnsAsync(new List <SrvRecord>()); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { Servers = new List <Uri> { new Uri("couchbase://server:1000/") } }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition); // Assert Assert.Equal(1, clientDefinition.Servers.Count); Assert.Equal(new Uri("couchbase://server:1000/"), clientDefinition.Servers[0]); lookupClient .Verify(m => m.QuerySrvAsync(It.IsAny <string>()), Times.Never); }
public void Apply_UnhandledException_LogsError() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(RecordName)) .ThrowsAsync(new Exception("Badness Happened")); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); logger.Setup( m => m.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <object>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >())); var clientDefinition = new CouchbaseClientDefinition(); var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition, RecordName); // Assert logger.Verify( m => m.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <object>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.AtLeastOnce); }
public void Apply_ShortRecordName_ReturnsServersFromFullRecordNameIfPresent() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(RecordName)) .Returns(Task.FromResult(new[] { SrvRecord2Priority10 }.AsEnumerable())); lookupClient .Setup(m => m.QuerySrvAsync(FullRecordName)) .Returns(Task.FromResult(new[] { SrvRecord1Priority10 }.AsEnumerable())); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition(); var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition, RecordName); // Assert Assert.Equal(1, clientDefinition.Servers.Count); Assert.Equal(ServerRecord1ExpectedUrl, clientDefinition.Servers[0]); }
public void Apply_HasServerList_ClearsListFirst() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(RecordName)) .Returns(Task.FromResult(new [] { SrvRecord1Priority10, SrvRecord2Priority10 }.AsEnumerable())); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { Servers = new List <Uri> { new Uri("http://shouldremove/") } }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition, RecordName); // Assert Assert.Equal(2, clientDefinition.Servers.Count); }
public void Apply_NoClientDefinition_Exception() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act/Assert var ex = Assert.Throws <ArgumentNullException>(() => lookup.Apply(null, RecordName)); Assert.Equal("clientDefinition", ex.ParamName); }
public void ApplyNoRecordName_CouchbaseDnsSrvFound_IgnoresPriority() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(FullRecordName)) .ReturnsAsync(new List <SrvRecord> { SrvRecord1Priority10, SrvRecord2Priority10, SrvRecord3Priority20, SrvRecord4Priority20 }); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition { Servers = new List <Uri> { new Uri("couchbase://services.local/") } }; var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition); // Assert Assert.Equal(4, clientDefinition.Servers.Count); Assert.Contains(ServerRecord1ExpectedUrl, clientDefinition.Servers); Assert.Contains(ServerRecord2ExpectedUrl, clientDefinition.Servers); Assert.Contains(ServerRecord3ExpectedUrl, clientDefinition.Servers); Assert.Contains(ServerRecord4ExpectedUrl, clientDefinition.Servers); }
public void Apply_UnhandledException_ReturnsEmptyList() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(RecordName)) .ThrowsAsync(new Exception("Badness Happened")); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition(); var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition, RecordName); // Assert Assert.Equal(0, clientDefinition.Servers.Count); }
public void Apply_NoResults_ReturnsEmptyList() { // Arrange var lookupClient = new Mock <ILookupClientAdapter>(); lookupClient .Setup(m => m.QuerySrvAsync(RecordName)) .Returns(Task.FromResult(new SrvRecord[] {}.AsEnumerable())); var logger = new Mock <ILogger <CouchbaseDnsLookup> >(); var clientDefinition = new CouchbaseClientDefinition(); var lookup = new CouchbaseDnsLookup(lookupClient.Object, logger.Object); // Act lookup.Apply(clientDefinition, RecordName); // Assert Assert.Equal(0, clientDefinition.Servers.Count); }