public async Task GetDnsSrvEntriesAsync_GetsSrvEntries_ReturnsUris(string scheme) { var records = new List <SrvRecord> { new SrvRecord(new ResourceRecordInfo("cb.somewhere.com", ResourceRecordType.SRV, QueryClass.IN, 0, 0), 1, 0, 8091, DnsString.Parse("node1.somewhere.com.")), new SrvRecord(new ResourceRecordInfo("cb.somewhere.com", ResourceRecordType.SRV, QueryClass.IN, 0, 0), 0, 0, 8091, DnsString.Parse("node2.somewhere.com.")) }; var mockQueryResponse = new Mock <IDnsQueryResponse>(); mockQueryResponse .Setup(x => x.HasError).Returns(false); mockQueryResponse .Setup(x => x.Answers).Returns(records); var mockLookupClient = new Mock <ILookupClient>(); mockLookupClient .Setup(x => x.QueryAsync($"_{scheme}._tcp.cb.somewhere.com", QueryType.SRV, QueryClass.IN, CancellationToken.None)) .Returns(Task.FromResult(mockQueryResponse.Object)); var bootstrapUri = new Uri($"{scheme}://cb.somewhere.com"); var resolver = new DnsClientDnsResolver(mockLookupClient.Object, new Mock <ILogger <DnsClientDnsResolver> >().Object); var result = (await resolver.GetDnsSrvEntriesAsync(bootstrapUri)).ToList(); Assert.NotNull(result); Assert.Equal(2, result.Count()); Assert.Contains(result, endpoint => endpoint.Host == "node1.somewhere.com" && endpoint.Port == 8091); Assert.Contains(result, endpoint => endpoint.Host == "node2.somewhere.com" && endpoint.Port == 8091); }
public async Task GetDnsSrvEntriesAsync_NoSrvRecords_ReturnsNoUris() { var mockQueryResponse = new Mock <IDnsQueryResponse>(); mockQueryResponse .Setup(x => x.HasError).Returns(false); mockQueryResponse .Setup(x => x.Answers).Returns(new List <SrvRecord>()); var mockLookupClient = new Mock <ILookupClient>(); mockLookupClient .Setup(x => x.QueryAsync("_couchbase._tcp.cb.somewhere.com", QueryType.SRV, QueryClass.IN, CancellationToken.None)) .Returns(Task.FromResult(mockQueryResponse.Object)); var mockDotNetDnsClient = new Mock <IDotNetDnsClient>(); var bootstrapUri = new Uri("couchbase://cb.somewhere.com"); var resolver = new DnsClientDnsResolver(mockLookupClient.Object, mockDotNetDnsClient.Object, new Mock <ILogger <DnsClientDnsResolver> >().Object); var result = await resolver.GetDnsSrvEntriesAsync(bootstrapUri); Assert.NotNull(result); Assert.Empty(result); }
public async Task QueryErrorsReturnsnoUris() { var mockQueryResponse = new Mock <IDnsQueryResponse>(); mockQueryResponse .Setup(x => x.HasError).Returns(true); var mockLookupClient = new Mock <ILookupClient>(); mockLookupClient .Setup(x => x.QueryAsync("_couchbase._tcp.cb.somewhere.com", QueryType.SRV, QueryClass.IN, CancellationToken.None)) .Returns(Task.FromResult(mockQueryResponse.Object)); var bootstrapUri = new Uri("couchbase://cb.somewhere.com"); var resolver = new DnsClientDnsResolver(mockLookupClient.Object); var result = await resolver.GetDnsSrvEntriesAsync(bootstrapUri); Assert.NotNull(result); Assert.Empty(result); }