Commit 981b531d authored by Brickner_cp's avatar Brickner_cp

Code Coverage 96.19%

parent 953fe462
using System;
using System.Net.NetworkInformation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Core.Extensions;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for NetworkInterfaceExtensionsTests.
/// </summary>
[TestClass]
public class NetworkInterfaceExtensionsTests
{
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext { get; set; }
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void GetLivePacketDeviceNull()
{
NetworkInterface networkInterface = null;
Assert.IsNull(networkInterface.GetLivePacketDevice());
Assert.Fail();
}
}
}
\ No newline at end of file
...@@ -316,7 +316,7 @@ namespace PcapDotNet.Core.Test ...@@ -316,7 +316,7 @@ namespace PcapDotNet.Core.Test
} }
} }
Assert.IsTrue(File.Exists(DumpFilename), "File " + DumpFilename, " doesn't exist"); Assert.IsTrue(File.Exists(DumpFilename), string.Format("File {0} doesn't exist", DumpFilename));
} }
// TODO: Add this test once Dumping to files with Unicode filenames is supported. See http://www.winpcap.org/pipermail/winpcap-users/2011-February/004273.html // TODO: Add this test once Dumping to files with Unicode filenames is supported. See http://www.winpcap.org/pipermail/winpcap-users/2011-February/004273.html
...@@ -356,7 +356,20 @@ namespace PcapDotNet.Core.Test ...@@ -356,7 +356,20 @@ namespace PcapDotNet.Core.Test
} }
} }
Assert.IsTrue(File.Exists(ReadUnicodeFilename), "File " + ReadUnicodeFilename, " doesn't exist"); Assert.IsTrue(File.Exists(ReadUnicodeFilename), string.Format("File {0} doesn't exist", ReadUnicodeFilename));
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
public void ReadNonExistingUnicodeFilenameTest()
{
const string ReadUnicodeFilename = "abc_non_existing_\u00F9_\u05D0\u05D1\u05D2.pcap";
OfflinePacketDevice device = new OfflinePacketDevice(ReadUnicodeFilename);
using (PacketCommunicator communicator = device.Open())
{
Assert.Fail();
}
} }
private static void TestGetSomePackets(int numPacketsToSend, int numPacketsToGet, int numPacketsToBreakLoop, private static void TestGetSomePackets(int numPacketsToSend, int numPacketsToGet, int numPacketsToBreakLoop,
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
<Compile Include="LivePacketDeviceTests.cs" /> <Compile Include="LivePacketDeviceTests.cs" />
<Compile Include="MarshalingServicesTests.cs" /> <Compile Include="MarshalingServicesTests.cs" />
<Compile Include="IpV4OptionExtensions.cs" /> <Compile Include="IpV4OptionExtensions.cs" />
<Compile Include="NetworkInterfaceExtensionsTests.cs" />
<Compile Include="PacketTimestampTests.cs" /> <Compile Include="PacketTimestampTests.cs" />
<Compile Include="TcpOptionExtensions.cs" /> <Compile Include="TcpOptionExtensions.cs" />
<Compile Include="WiresharkDatagramComparer.cs" /> <Compile Include="WiresharkDatagramComparer.cs" />
......
...@@ -86,5 +86,23 @@ namespace PcapDotNet.Packets.Test ...@@ -86,5 +86,23 @@ namespace PcapDotNet.Packets.Test
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new TcpLayer()); Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new TcpLayer());
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
} }
[TestMethod]
public void NoPayloadByEtherType()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
new EthernetLayer
{
EtherType = EthernetType.AppleTalk
},
new PayloadLayer
{
Data = new Datagram(new byte[100])
});
Assert.IsTrue(packet.IsValid);
Assert.IsNull(packet.Ethernet.TrailerWithFrameCheckSequence);
Assert.IsNull(packet.Ethernet.Trailer);
Assert.IsNull(packet.Ethernet.FrameCheckSequence);
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment