示例#1
0
                    public SocketImpl(MockStreamSocketFactory socketFactory)
                    {
                        if (socketFactory == null)
                        {
                            throw new ArgumentNullException("socketFactory");
                        }

                        m_socketFactory = socketFactory;
                    }
示例#2
0
            public void Test_IQUERY_TCP()
            {
                var connectedInvoked        = false;
                var beginConnectInvoked     = false;
                var getSendStreamInvoked    = false;
                var getReceiveStreamInvoked = false;
                var disposeInvoked          = false;

                var sendStream    = new MemoryStream();
                var receiveStream = new MemoryStream(ReceivedData);

                var streamSocketFactory = new MockStreamSocketFactory(
                    () =>
                {
                    Assert.IsFalse(connectedInvoked);
                    Assert.IsTrue(beginConnectInvoked);
                    Assert.IsFalse(getSendStreamInvoked);
                    Assert.IsFalse(getReceiveStreamInvoked);
                    Assert.IsFalse(disposeInvoked);
                    connectedInvoked = true;
                    return(true);
                },
                    (address, port, requestCallback, state) =>
                {
                    Assert.AreEqual("192.168.11.1", address.ToString());
                    Assert.AreEqual(53, port);
                    Assert.IsNull(requestCallback);
                    Assert.IsNull(state);

                    Assert.IsFalse(connectedInvoked);
                    Assert.IsFalse(beginConnectInvoked);
                    Assert.IsFalse(getSendStreamInvoked);
                    Assert.IsFalse(getReceiveStreamInvoked);
                    Assert.IsFalse(disposeInvoked);
                    var result          = new MockConnectAsyncResult();
                    beginConnectInvoked = true;
                    return(result);
                },
                    () =>
                {
                    Assert.IsTrue(connectedInvoked);
                    Assert.IsTrue(beginConnectInvoked);
                    Assert.IsFalse(getSendStreamInvoked);
                    Assert.IsFalse(getReceiveStreamInvoked);
                    Assert.IsFalse(disposeInvoked);
                    getSendStreamInvoked = true;
                    return(sendStream);
                },
                    () =>
                {
                    Assert.IsTrue(connectedInvoked);
                    Assert.IsTrue(beginConnectInvoked);
                    Assert.IsTrue(getSendStreamInvoked);
                    Assert.IsFalse(getReceiveStreamInvoked);
                    Assert.IsFalse(disposeInvoked);
                    getReceiveStreamInvoked = true;
                    return(receiveStream);
                },
                    () =>
                {
                    Assert.IsTrue(connectedInvoked);
                    Assert.IsTrue(beginConnectInvoked);
                    Assert.IsTrue(getSendStreamInvoked);
                    Assert.IsTrue(getReceiveStreamInvoked);
                    Assert.IsFalse(disposeInvoked);
                    disposeInvoked = true;
                });
                var options = new DnsResolverOptions
                {
                    Timeout    = 1000,
                    RetryCount = 3,
                    Recursion  = true,
                    UseCache   = true
                };
                var resolver = new TcpDnsResolver(
                    options,
                    streamSocketFactory,
                    new IPEndpoint(IPAddress.Parse("192.168.11.1"), 53), new Random(0));

                var response = resolver.Query("167.11.168.192.in-addr.arpa", QType.PTR, QClass.IN);

                Assert.AreEqual(0, response.Error.Length);

                sendStream.ToArray().ShouldEqual(ExpectedSendData);

                Assert.AreEqual(1, response.header.ANCOUNT);
                Assert.AreEqual(1, response.Answers.Count);

                var answerRR = response.Answers.First();

                Assert.AreEqual("167.11.168.192.in-addr.arpa.", answerRR.NAME);
                Assert.AreEqual(0u, answerRR.TTL);
                Assert.AreEqual(Class.IN, answerRR.Class);
                Assert.AreEqual(Lanscan.Networking.Dns.RecordType.PTR, answerRR.Type);
                Assert.IsInstanceOfType(answerRR.RECORD, typeof(PTRRecord));
                var recordPtr = (PTRRecord)answerRR.RECORD;

                Assert.AreEqual("alpha.example.com.", recordPtr.PTRDNAME);

                Assert.IsTrue(connectedInvoked);
                Assert.IsTrue(beginConnectInvoked);
                Assert.IsTrue(getSendStreamInvoked);
                Assert.IsTrue(disposeInvoked);
            }