Exemple #1
0
 private void ServerResponded(object sender, DnsServer.RespondedEventArgs args)
 {
     _logger.LogTrace($"Service has responded:\n {args.Request}, {args.Response}");
 }
Exemple #2
0
        public async Task ServerLookup()
        {
            await Create(new IPAddressRequestResolver(), async server => {
                DnsServer.RequestedEventArgs requestedEvent = null;
                DnsServer.RespondedEventArgs respondedEvent = null;
                DnsServer.ErroredEventArgs erroredEvent     = null;

                server.Requested += (sender, e) => {
                    requestedEvent = e;
                };

                server.Responded += (sender, e) => {
                    respondedEvent = e;
                };

                server.Errored += (sender, e) => {
                    erroredEvent = e;
                };

                IRequest clientRequest         = new Request();
                Question clientRequestQuestion = new Question(new Domain("google.com"), RecordType.A);

                clientRequest.Id = 1;
                clientRequest.Questions.Add(clientRequestQuestion);
                clientRequest.OperationCode = OperationCode.Query;

                IResponse clientResponse = await Resolve(clientRequest);

                Assert.Equal(1, clientResponse.Id);
                Assert.Equal(1, clientResponse.Questions.Count);
                Assert.Equal(1, clientResponse.AnswerRecords.Count);
                Assert.Equal(0, clientResponse.AuthorityRecords.Count);
                Assert.Equal(0, clientResponse.AdditionalRecords.Count);

                Question clientResponseQuestion = clientResponse.Questions[0];

                Assert.Equal(RecordType.A, clientResponseQuestion.Type);
                Assert.Equal("google.com", clientResponseQuestion.Name.ToString());

                IResourceRecord clientResponseRecord = clientResponse.AnswerRecords[0];

                Assert.Equal("google.com", clientResponseRecord.Name.ToString());
                Assert.Equal(Helper.GetArray <byte>(192, 168, 0, 1), clientResponseRecord.Data);
                Assert.Equal(RecordType.A, clientResponseRecord.Type);

                Assert.NotNull(requestedEvent);

                Assert.NotNull(requestedEvent.Request);
                Assert.Equal(1, requestedEvent.Request.Id);
                Assert.Equal(1, requestedEvent.Request.Questions.Count);

                Question requestedRequestQuestion = requestedEvent.Request.Questions[0];

                Assert.Equal(RecordType.A, requestedRequestQuestion.Type);
                Assert.Equal("google.com", requestedRequestQuestion.Name.ToString());

                Assert.NotNull(respondedEvent);
                Assert.Equal(requestedEvent.Request, respondedEvent.Request);

                Assert.NotNull(respondedEvent.Response);

                Assert.Equal(1, respondedEvent.Response.Id);
                Assert.Equal(1, respondedEvent.Response.Questions.Count);
                Assert.Equal(1, respondedEvent.Response.AnswerRecords.Count);
                Assert.Equal(0, respondedEvent.Response.AuthorityRecords.Count);
                Assert.Equal(0, respondedEvent.Response.AdditionalRecords.Count);

                Question respondedResponseQuestion = respondedEvent.Response.Questions[0];

                Assert.Equal(RecordType.A, respondedResponseQuestion.Type);
                Assert.Equal("google.com", respondedResponseQuestion.Name.ToString());

                IResourceRecord respondedResponseRecord = respondedEvent.Response.AnswerRecords[0];

                Assert.Equal("google.com", respondedResponseRecord.Name.ToString());
                Assert.Equal(Helper.GetArray <byte>(192, 168, 0, 1), respondedResponseRecord.Data);
                Assert.Equal(RecordType.A, respondedResponseRecord.Type);

                Assert.Null(erroredEvent);
            });
        }