Beispiel #1
0
        internal async Task GetIpAddressAsync_Force_IsRespected(IpAddressMode ipAddressMode, string expectedResult)
        {
            // Arrange

            var addresses = new IPAddress[]
            {
                IPAddress.Parse("127.0.0.1"),
                IPAddress.Parse("::1")
            };

            var mockLookupClient = new Mock <ILookupClient>();

            var mockDotNetDnsClient = new Mock <IDotNetDnsClient>();

            mockDotNetDnsClient
            .Setup(m => m.GetHostAddressesAsync("cb.somewhere.com"))
            .ReturnsAsync(addresses);

            var resolver =
                new DnsClientDnsResolver(mockLookupClient.Object, mockDotNetDnsClient.Object, new Mock <ILogger <DnsClientDnsResolver> >().Object)
            {
                IpAddressMode = ipAddressMode
            };

            // Act

            var result = await resolver.GetIpAddressAsync("cb.somewhere.com");

            // Assert

            Assert.NotNull(result);
            Assert.Equal(IPAddress.Parse(expectedResult), result);
        }
Beispiel #2
0
        internal async Task GetIpAddressAsync_Preference_IsRespected(IpAddressMode ipAddressMode, AddressFamily expectedFamily)
        {
            // Arrange

            var ipv4Record = new AddressRecord(
                new ResourceRecordInfo("cb.somewhere.com.", ResourceRecordType.A, QueryClass.IN, 100, 100),
                IPAddress.Parse("127.0.0.1"));

            var mockIpv4Response = new Mock <IDnsQueryResponse>();

            mockIpv4Response
            .Setup(x => x.HasError).Returns(false);
            mockIpv4Response
            .Setup(x => x.Answers)
            .Returns(new List <AddressRecord> {
                ipv4Record
            });

            var ipv6Record = new AddressRecord(
                new ResourceRecordInfo("cb.somewhere.com.", ResourceRecordType.AAAA, QueryClass.IN, 100, 100),
                IPAddress.Parse("::1"));

            var mockIpv6Response = new Mock <IDnsQueryResponse>();

            mockIpv6Response
            .Setup(x => x.HasError).Returns(false);
            mockIpv6Response
            .Setup(x => x.Answers)
            .Returns(new List <AddressRecord> {
                ipv6Record
            });

            var mockLookupClient = new Mock <ILookupClient>();

            mockLookupClient
            .Setup(x => x.QueryAsync("cb.somewhere.com.", QueryType.A, QueryClass.IN, default))
            .ReturnsAsync(mockIpv4Response.Object);
            mockLookupClient
            .Setup(x => x.QueryAsync("cb.somewhere.com.", QueryType.AAAA, QueryClass.IN, default))
            .ReturnsAsync(mockIpv6Response.Object);

            var resolver =
                new DnsClientDnsResolver(mockLookupClient.Object, new Mock <ILogger <DnsClientDnsResolver> >().Object)
            {
                IpAddressMode = ipAddressMode
            };

            // Act

            var result = await resolver.GetIpAddressAsync("cb.somewhere.com");

            // Assert

            Assert.NotNull(result);
            Assert.Equal(expectedFamily, result.AddressFamily);
        }
Beispiel #3
0
        internal async Task GetIpAddressAsync_Force_IsRespected(IpAddressMode ipAddressMode)
        {
            // Arrange

            var expectedQuery    = ipAddressMode == IpAddressMode.ForceIpv4 ? QueryType.A : QueryType.AAAA;
            var notExpectedQuery = ipAddressMode == IpAddressMode.ForceIpv4 ? QueryType.AAAA : QueryType.A;

            var record = expectedQuery == QueryType.A
                ? new AddressRecord(
                new ResourceRecordInfo("cb.somewhere.com.", ResourceRecordType.A, QueryClass.IN, 100, 100),
                IPAddress.Parse("127.0.0.1"))
                : new AddressRecord(
                new ResourceRecordInfo("cb.somewhere.com.", ResourceRecordType.AAAA, QueryClass.IN, 100, 100),
                IPAddress.Parse("::1"));

            var mockResponse = new Mock <IDnsQueryResponse>();

            mockResponse
            .Setup(x => x.HasError).Returns(false);
            mockResponse
            .Setup(x => x.Answers)
            .Returns(new List <AddressRecord> {
                record
            });

            var mockLookupClient = new Mock <ILookupClient>();

            mockLookupClient
            .Setup(x => x.QueryAsync("cb.somewhere.com.", expectedQuery, QueryClass.IN, default))
            .ReturnsAsync(mockResponse.Object);

            var resolver =
                new DnsClientDnsResolver(mockLookupClient.Object, new Mock <ILogger <DnsClientDnsResolver> >().Object)
            {
                IpAddressMode = ipAddressMode
            };

            // Act

            var result = await resolver.GetIpAddressAsync("cb.somewhere.com");

            // Assert

            Assert.NotNull(result);
            Assert.Equal(record.Address, result);

            mockLookupClient.Verify(
                x => x.QueryAsync(It.IsAny <string>(), notExpectedQuery, It.IsAny <QueryClass>(), It.IsAny <CancellationToken>()),
                Times.Never);
        }
 public ArpEntry(IPAddress ipAddress, ulong macAddress, IpAddressMode mode)
 {
     this.IpAddress = ipAddress;
     this.MacAddress = macAddress;
     this.Mode = mode;
 }