Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency NUnit to v4 #493

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Test/ArpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void TestArp()
var arp = new ARP(d);

// timeout should not be null
Assert.IsNotNull(arp.Timeout);
Assert.That(arp.Timeout.Ticks, Is.Not.Zero);

// and we can set a timeout
arp.Timeout = new TimeSpan(0, 0, 2);
Expand Down
4 changes: 2 additions & 2 deletions Test/CaptureDeviceListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CaptureDeviceListTest
public void CaptureDeviceListNew()
{
var deviceList = CaptureDeviceList.New();
Assert.IsNotNull(deviceList);
Assert.IsNotEmpty(deviceList);
Assert.That(deviceList, Is.Not.Null);
Assert.That(deviceList, Is.Not.Empty);
}
}
}
26 changes: 13 additions & 13 deletions Test/CaptureFileReaderDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void CaptureTimestampResolution(TimestampResolution resolution, string ti
TimestampResolution = resolution
};
device.Open(configuration);
Assert.AreEqual(resolution, device.TimestampResolution);
Assert.That(device.TimestampResolution, Is.EqualTo(resolution));
device.GetNextPacket(out var packet);
Assert.AreEqual(timeval, packet.Header.Timeval.ToString());
Assert.That(packet.Header.Timeval.ToString(), Is.EqualTo(timeval));
}

[Test]
Expand All @@ -46,7 +46,7 @@ public void CaptureProperties()
var filename = "ipv6_http.pcap";
using var device = new CaptureFileReaderDevice(TestHelper.GetFile(filename));
device.Open();
Assert.IsNotEmpty(device.Description);
Assert.That(device.Description, Is.Not.Empty);
}

/// <summary>
Expand All @@ -62,15 +62,15 @@ public void CaptureInfinite()
device.OnPacketArrival += HandleDeviceOnPacketArrival;
device.Open();
var ipv6FilesizeInBytes = 3451;
Assert.AreEqual(ipv6FilesizeInBytes, device.FileSize);
Assert.AreEqual(fileToOpen, device.Name);
Assert.AreEqual(filename, device.FileName);
Assert.That(device.FileSize, Is.EqualTo(ipv6FilesizeInBytes));
Assert.That(device.Name, Is.EqualTo(fileToOpen));
Assert.That(device.FileName, Is.EqualTo(filename));

var expectedPackets = 10;
capturedPackets = 0;
device.Capture();

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

/// <summary>
Expand All @@ -88,7 +88,7 @@ public void CaptureFinite()
capturedPackets = 0;
device.Capture(expectedPackets);

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

void HandleDeviceOnPacketArrival(object sender, PacketCapture e)
Expand All @@ -107,7 +107,7 @@ public void StatisticsUnsupported()
using (var device = new CaptureFileReaderDevice(TestHelper.GetFile("ipv6_http.pcap")))
{
device.Open();
Assert.IsNull(device.Statistics);
Assert.That(device.Statistics, Is.Null);
}
}

Expand All @@ -131,14 +131,14 @@ public void SetFilter()
rawPacket = e.GetPacket();
Packet p = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
var udpPacket = p.Extract<UdpPacket>();
Assert.IsNotNull(udpPacket);
Assert.That(udpPacket, Is.Not.Null);
int dnsPort = 53;
Assert.AreEqual(dnsPort, udpPacket.DestinationPort);
Assert.That(udpPacket.DestinationPort, Is.EqualTo(dnsPort));
count++;
}
} while (retval == GetPacketStatus.PacketRead);

Assert.AreEqual(1, count);
Assert.That(count, Is.EqualTo(1));
}

[Test]
Expand All @@ -159,7 +159,7 @@ public void StringMarshalling()

using var device = new CaptureFileReaderDevice(file);
device.Open();
Assert.AreEqual(GetPacketStatus.PacketRead, device.GetNextPacket(out var _));
Assert.That(device.GetNextPacket(out var _), Is.EqualTo(GetPacketStatus.PacketRead));
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions Test/CaptureFileWriterDeviceTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using NUnit.Framework;
using SharpPcap;
using SharpPcap.LibPcap;
Expand All @@ -8,7 +9,7 @@ namespace Test
[TestFixture]
public class CaptureFileWriterDeviceTest
{
static string filename = @"abc.pcap";
static string filename = "abc.pcap";

public CaptureFileWriterDeviceTest()
{
Expand All @@ -24,8 +25,8 @@ public void TestFileCreationAndDeletion()
using (var wd = new CaptureFileWriterDevice(filename))
{
wd.Open();
Assert.AreEqual(filename, wd.Name);
Assert.IsNotEmpty(wd.Description);
Assert.That(wd.Name, Is.EqualTo(filename));
Assert.That(wd.Description, Is.Not.Empty);
var bytes = new byte[] { 1, 2, 3, 4 };
wd.Write(bytes);

Expand Down Expand Up @@ -100,7 +101,7 @@ public void StatisticsUnsupported()
using (var wd = new CaptureFileWriterDevice(filename))
{
wd.Open();
Assert.IsNull(wd.Statistics);
Assert.That(wd.Statistics, Is.Null);
}
}

Expand All @@ -110,8 +111,8 @@ public void TestInjectable()
using (var wd = new CaptureFileWriterDevice(filename))
{
wd.Open();
Assert.AreEqual(filename, wd.Name);
Assert.IsNotEmpty(wd.Description);
Assert.That(wd.Name, Is.EqualTo(filename));
Assert.That(wd.Description, Is.Not.Empty);

var bytes = new byte[] { 1, 2, 3, 4 };

Expand All @@ -123,7 +124,7 @@ public void TestInjectable()
var span = new ReadOnlySpan<byte>(bytes, 0, bytes.Length);
injectionDevice.SendPacket(span);
}
System.IO.File.Delete(@"abc.pcap");
File.Delete(filename);
}

}
Expand Down
26 changes: 13 additions & 13 deletions Test/CaptureHandleReaderDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ public void CaptureTimestampResolution(TimestampResolution resolution, string ti
TimestampResolution = resolution
};
device.Open(configuration);
Assert.AreEqual(resolution, device.TimestampResolution);
Assert.That(device.TimestampResolution, Is.EqualTo(resolution));
device.GetNextPacket(out var packet);
Assert.AreEqual(timeval, packet.Header.Timeval.ToString());
Assert.That(packet.Header.Timeval.ToString(), Is.EqualTo(timeval));
}

[Test]
public void FileHandleInvalidUponClose()
{
const string filename = "ipv6_http.pcap";
using var handle = GetTestFileHandle(filename);
Assert.IsFalse(handle.IsInvalid);
Assert.IsFalse(handle.IsClosed);
Assert.That(handle.IsInvalid, Is.False);
Assert.That(handle.IsClosed, Is.False);
{
using var device = new CaptureHandleReaderDevice(handle);
device.Open();
}
Assert.IsTrue(handle.IsClosed);
Assert.That(handle.IsClosed, Is.True);
}

[Test]
Expand All @@ -69,8 +69,8 @@ public void CaptureProperties()
using var handle = GetTestFileHandle(filename);
using var device = new CaptureHandleReaderDevice(handle);
device.Open();
Assert.IsNotEmpty(device.Description);
Assert.AreEqual(handle, device.FileHandle);
Assert.That(device.Description, Is.Not.Empty);
Assert.That(device.FileHandle, Is.EqualTo(handle));
}

/// <summary>
Expand All @@ -90,7 +90,7 @@ public void CaptureInfinite()
capturedPackets = 0;
device.Capture();

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

/// <summary>
Expand All @@ -110,7 +110,7 @@ public void CaptureFinite()
capturedPackets = 0;
device.Capture(expectedPackets);

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

void HandleDeviceOnPacketArrival(object sender, PacketCapture e)
Expand All @@ -130,7 +130,7 @@ public void StatisticsUnsupported()
using var handle = GetTestFileHandle(filename);
using var device = new CaptureHandleReaderDevice(handle);
device.Open();
Assert.IsNull(device.Statistics);
Assert.That(device.Statistics, Is.Null);
}

[Test]
Expand All @@ -155,14 +155,14 @@ public void SetFilter()
rawPacket = e.GetPacket();
Packet p = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
var udpPacket = p.Extract<UdpPacket>();
Assert.IsNotNull(udpPacket);
Assert.That(udpPacket, Is.Not.Null);
int dnsPort = 53;
Assert.AreEqual(dnsPort, udpPacket.DestinationPort);
Assert.That(udpPacket.DestinationPort, Is.EqualTo(dnsPort));
count++;
}
} while (retval == GetPacketStatus.PacketRead);

Assert.AreEqual(1, count);
Assert.That(count, Is.EqualTo(1));
}
}

Expand Down
26 changes: 13 additions & 13 deletions Test/CheckFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class CheckFilterTest
public void TestFilters()
{
// test a known failing filter
Assert.IsFalse(LibPcapLiveDevice.CheckFilter("some bogus filter", out string errorString));
Assert.IsNotNull(errorString);
Assert.IsNotEmpty(errorString);
Assert.That(LibPcapLiveDevice.CheckFilter("some bogus filter", out string errorString), Is.False);
Assert.That(errorString, Is.Not.Null);
Assert.That(errorString, Is.Not.Empty);

// test a known working filter
Assert.IsTrue(LibPcapLiveDevice.CheckFilter("port 23", out errorString));
Assert.IsNull(errorString);
Assert.That(LibPcapLiveDevice.CheckFilter("port 23", out errorString), Is.True);
Assert.That(errorString, Is.Null);
}

/// <summary>
Expand All @@ -34,10 +34,10 @@ public void BpfProgramMatches()
var f = "(dst host 192.168.42.1) and (arp or tcp dst port 40499)";
// Make filter work with or without VLAN
using var bpfProgram = BpfProgram.Create(LinkLayers.Ethernet, $"({f}) or (vlan and ({f}))");
Assert.IsFalse(bpfProgram.IsInvalid);
Assert.That(bpfProgram.IsInvalid, Is.False);

device.GetNextPacket(out var packet);
Assert.IsTrue(bpfProgram.Matches(packet.Data));
Assert.That(bpfProgram.Matches(packet.Data), Is.True);
}
/// <summary>
/// Test BpfProgram.Matches() when creating BpfProgram without device
Expand All @@ -49,10 +49,10 @@ public void BpfProgramNoDeviceMatches()
device.Open();

using var bpfProgram = BpfProgram.Create(device.Handle, "tcp");
Assert.IsFalse(bpfProgram.IsInvalid);
Assert.That(bpfProgram.IsInvalid, Is.False);

device.GetNextPacket(out var packet);
Assert.IsTrue(bpfProgram.Matches(packet.Data));
Assert.That(bpfProgram.Matches(packet.Data), Is.True);
}

/// <summary>
Expand All @@ -66,7 +66,7 @@ public void FilterMethods()

var filterExpression = "arp";
using var bpfProgram = BpfProgram.Create(device.Handle, filterExpression);
Assert.IsFalse(bpfProgram.IsInvalid);
Assert.That(bpfProgram.IsInvalid, Is.False);

var arp = new ARP(device);
var destinationIP = new System.Net.IPAddress(new byte[] { 8, 8, 8, 8 });
Expand All @@ -93,8 +93,8 @@ public void FilterMethods()
{
packetsToTry--;

Assert.AreNotEqual(IntPtr.Zero, header);
Assert.AreNotEqual(IntPtr.Zero, data);
Assert.That(header, Is.Not.EqualTo(IntPtr.Zero));
Assert.That(data, Is.Not.EqualTo(IntPtr.Zero));

// and test it against the bpf filter to confirm an exception is not thrown
Assert.DoesNotThrow(() =>
Expand All @@ -109,7 +109,7 @@ public void FilterMethods()
}
}

Assert.IsTrue(foundBpfMatch);
Assert.That(foundBpfMatch, Is.True);
}
}
}
2 changes: 1 addition & 1 deletion Test/DeviceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static IEnumerable<ILiveDevice> GetDevices()
};
foreach (var list in lists)
{
Assert.IsNotEmpty(list.Value, "{0} should not be empty", list.Key);
Assert.That(list.Value, Is.Not.Empty, $"{list.Key} should not be empty");
}
return lists.SelectMany(l => l.Value)
// The bluetooth-monitor break the tests on circleci
Expand Down
14 changes: 7 additions & 7 deletions Test/LibPcapLiveDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class LibPcapLiveDeviceTest
public void LibPcapLiveDeviceProperties()
{
var d = LibPcapLiveDeviceList.Instance[0];
Assert.IsNotNull(d);
Assert.That(d, Is.Not.Null);

Assert.IsNotNull(d.Addresses);
Assert.That(d.Addresses, Is.Not.Null);
Console.WriteLine("Flags: {0}", d.Flags);
Console.WriteLine("Loopback: {0}", d.Loopback);
}
Expand All @@ -35,7 +35,7 @@ public void DeviceOpenWithTimestampType([CaptureDevices] DeviceFixture fixture)

var timestampTypes = liveDevice.Interface.TimestampsSupported;

Assert.IsNotEmpty(timestampTypes);
Assert.That(timestampTypes, Is.Not.Empty);

// open the device with each of its supported timestamp types
foreach (var pcapClock in timestampTypes)
Expand All @@ -44,7 +44,7 @@ public void DeviceOpenWithTimestampType([CaptureDevices] DeviceFixture fixture)
configuration.TimestampType = pcapClock.TimestampType;
liveDevice.Open(configuration);

Assert.IsNotNull(liveDevice.Interface.TimestampsSupported);
Assert.That(liveDevice.Interface.TimestampsSupported, Is.Not.Null);

liveDevice.Close();
}
Expand All @@ -54,7 +54,7 @@ public void DeviceOpenWithTimestampType([CaptureDevices] DeviceFixture fixture)
public void NonBlockingMode()
{
using var d = LibPcapLiveDeviceList.Instance[0];
Assert.IsNotNull(d);
Assert.That(d, Is.Not.Null);

// assert that setting and getting non blocking mode
// with a closed device
Expand All @@ -64,9 +64,9 @@ public void NonBlockingMode()
// test that we can set the blocking mode on an open device
d.Open();
d.NonBlockingMode = true;
Assert.IsTrue(d.NonBlockingMode);
Assert.That(d.NonBlockingMode, Is.True);
d.NonBlockingMode = false;
Assert.IsFalse(d.NonBlockingMode);
Assert.That(d.NonBlockingMode, Is.False);
}
}
}
2 changes: 1 addition & 1 deletion Test/LivePcapDeviceListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void ListTest()
// test that we can look up devices by name
foreach (var d in dl)
{
Assert.IsNotNull(dl[d.Name]);
Assert.That(dl[d.Name], Is.Not.Null);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Test/LivePcapDeviceSetFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void SimpleFilter([CaptureDevices] DeviceFixture fixture)
}
var filter = "tcp port 80";
device.Filter = filter;
Assert.AreEqual(filter, device.Filter);
Assert.That(device.Filter, Is.EqualTo(filter));
}

/// <summary>
Expand Down
Loading
Loading