示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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]);
        }
示例#8
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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }