/*
* Copyright 2004-2006 Luke Quinane and Daniel Frampton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Net;
using NUnit.Framework;
using NDns;
using NDns.Message;
using NDns.Message.Records;
using NDns.Configuration;
namespace NDns.UnitTests{
/// <summary>
/// Unit tests for the DNS cache.
/// </summary>
[TestFixture]
public class DNSCacheTests {
#region TestData
/// <summary>
/// The list of domains used during testing.
/// </summary>
/// <remarks>roughly ordered by google</remarks>
public string[] testDomains = new string[]
{
"www.anu.edu.au",
"www.usyd.edu.au",
"www.uq.edu.au",
"www.unimelb.edu.au",
"www.monash.edu.au",
"www.adelaide.edu.au",
"www.mq.edu.au",
"www.gu.edu.au",
"www.uow.edu.au",
"www.latrobe.edu.au",
"www.newcastle.edu.au",
"www.deakin.edu.au",
"www.utas.edu.au",
"www.unsw.edu.au",
"www.uwa.edu.au",
"www.curtin.edu.au",
"www.murdoch.edu.au",
"www.flinders.edu.au",
"www.uts.edu.au",
"www.canberra.edu.au",
"www.qut.edu.au",
"www.rmit.edu.au",
"www.unisa.edu.au",
"www.bond.edu.au",
"www.csu.edu.au",
"www.jcu.edu.au",
"www.une.edu.au",
"www.swin.edu.au",
"www.ballarat.edu.au",
"www.cqu.edu.au"
};
#endregion
private DnsCache cache;
/// <summary>
/// Sets the DNS server to use during testing.
/// </summary>
[TestFixtureSetUp]
public void SetDNSServer() {
IPAddress[] dnsServers = { IPAddress.Parse("192.168.1.1") };
NDnsConfiguration config = new NDnsConfiguration(
dnsServers,
10,
10,
10);
this.cache = new DnsCache(config);
}
#region Domain Tests
/// <summary>
/// Tests the lookup of an PTR record.
/// </summary>
[Test]
public void LookUpPTRRecords() {
PTRRecord[] records = cache.GetPTRRecords(IPAddress.Parse("150.203.99.8"));
Assert.IsTrue(records[0].Name.Equals("www.anu.edu.au"),
"records[0].Name.Equals(\"www.anu.edu.au\"))");
}
#endregion
#region Address Tests
/// <summary>
/// Tests the lookup of an A record.
/// </summary>
[Test]
public void LookUpARecords() {
ARecord[] records = cache.GetARecords("www.anu.edu.au");
Assert.IsTrue(records[0].Address.Equals(IPAddress.Parse("150.203.99.8")),
"records[0].Address.Equals(IPAddress.Parse(\"150.203.99.8\")");
}
/// <summary>
/// Stress tests looking up A records.
/// </summary>
[Test]
public void StressARecords() {
foreach (string d in this.testDomains) {
try {
ARecord[] records = cache.GetARecords(d);
Assert.IsTrue(records.Length > 0, "records.Length > 0:" + d);
} catch (Exception e) {
Console.Error.WriteLine("Failed at domain:" + d);
throw new ApplicationException("Failed at domain:" + d, e);
}
}
}
#endregion
#region MX Tests
/// <summary>
/// Tests the lookup of an MX record.
/// </summary>
[Test]
public void LookUpMXRecords() {
MXRecord[] records = cache.GetMXRecords("www.anu.edu.au");
Assert.IsTrue(records[0].MX.Equals("mail.anu.edu.au"),
"records[0].MX.Equals(\"mail.anu.edu.au\"))");
}
/// <summary>
/// Stress tests looking up MX records.
/// </summary>
[Test]
public void StressMXRecords() {
foreach (string d in this.testDomains) {
try {
MXRecord[] records = cache.GetMXRecords(d);
Assert.IsTrue(records.Length > 0, "records.Length > 0:" + d);
} catch (Exception e) {
Console.Error.WriteLine("Failed at domain:" + d);
throw new ApplicationException("Failed at domain:" + d, e);
}
}
}
#endregion
}
}
|