Commit b0b58a33 authored by Brickner_cp's avatar Brickner_cp

Resharper 5.0 inspection fixes.

parent d41fce73
......@@ -5,6 +5,9 @@
<Sharing>SOLUTION</Sharing>
<CSharp>
<FormatSettings>
<ANONYMOUS_METHOD_DECLARATION_BRACES>NEXT_LINE</ANONYMOUS_METHOD_DECLARATION_BRACES>
<CASE_BLOCK_BRACES>NEXT_LINE</CASE_BLOCK_BRACES>
<INITIALIZER_BRACES>NEXT_LINE</INITIALIZER_BRACES>
<MODIFIERS_ORDER IsNull="False">
<Item>public</Item>
<Item>protected</Item>
......@@ -23,6 +26,7 @@
</MODIFIERS_ORDER>
<SPACE_AFTER_TYPECAST_PARENTHESES>False</SPACE_AFTER_TYPECAST_PARENTHESES>
<SPACE_AROUND_MULTIPLICATIVE_OP>True</SPACE_AROUND_MULTIPLICATIVE_OP>
<WRAP_LIMIT>160</WRAP_LIMIT>
</FormatSettings>
<UsingsSettings />
<Naming2>
......@@ -73,14 +77,14 @@
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="LocalConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="LocalConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PublicFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateInstanceFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticFields" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Constants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="StaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="EnumMember" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Other" />
</Naming2>
......
......@@ -9,17 +9,10 @@ namespace PcapDotNet.Base.Test
[TestClass]
public class FuncExtensionsTest
{
public FuncExtensionsTest()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Base.Test
{
......@@ -9,20 +8,15 @@ namespace PcapDotNet.Base.Test
/// Summary description for IEnumerableExtensionsTests
/// </summary>
[TestClass]
// ReSharper disable InconsistentNaming
public class IEnumerableExtensionsTests
// ReSharper restore InconsistentNaming
{
public IEnumerableExtensionsTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
......@@ -9,17 +9,10 @@ namespace PcapDotNet.Base.Test
[TestClass]
public class MemberInfoExtensionsTests
{
public MemberInfoExtensionsTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
......@@ -9,17 +9,10 @@ namespace PcapDotNet.Base.Test
[TestClass]
public class PropertyInfoExtensionsTests
{
public PropertyInfoExtensionsTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
......@@ -11,13 +11,6 @@ namespace PcapDotNet.Base.Test
[TestClass]
public class UInt128Tests
{
public UInt128Tests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
......@@ -58,8 +51,10 @@ namespace PcapDotNet.Base.Test
Assert.AreNotEqual(value, string.Empty);
Assert.AreNotEqual(value, UInt128.MaxValue);
Assert.AreNotEqual(value, UInt128.Zero);
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
// ReSharper restore EqualExpressionComparison
Assert.IsNotNull(value.GetHashCode());
Assert.AreEqual(value, UInt128.Parse(value.ToString("X32"), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
Assert.AreEqual(value >> 64, UInt128.Parse(((ulong)(value >> 64)).ToString("X16"), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
......@@ -69,13 +64,13 @@ namespace PcapDotNet.Base.Test
[TestMethod]
public void ShiftRightTest()
{
const string valueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture), value);
const string ValueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(ValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(UInt128.Parse(ValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture), value);
for (int i = 0; i <= 124; i += 4)
{
string expectedValueString = new string('0', i / 4) + valueString.Substring(0, valueString.Length - i / 4);
string expectedValueString = new string('0', i / 4) + ValueString.Substring(0, ValueString.Length - i / 4);
UInt128 expectedValue = UInt128.Parse(expectedValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(expectedValue, value >> i, i.ToString());
Assert.AreEqual(expectedValue, value >> (i / 2) >> (i / 2), i.ToString());
......@@ -86,15 +81,15 @@ namespace PcapDotNet.Base.Test
[TestMethod]
public void BitwiseAndTest()
{
const string valueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture), value);
const string ValueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(ValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(UInt128.Parse(ValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture), value);
for (int i = 0; i <= 32; ++i)
{
string andValueString = new string('0', i) + new string('F', valueString.Length - i);
string andValueString = new string('0', i) + new string('F', ValueString.Length - i);
UInt128 andValue = UInt128.Parse(andValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
string expectedValueString = new string('0', i) + valueString.Substring(i, valueString.Length - i);
string expectedValueString = new string('0', i) + ValueString.Substring(i, ValueString.Length - i);
UInt128 expectedValue = UInt128.Parse(expectedValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
UInt128 actualValue = value & andValue;
Assert.AreEqual(expectedValue, actualValue, i.ToString());
......@@ -112,9 +107,9 @@ namespace PcapDotNet.Base.Test
[TestMethod]
public void ToStringTest()
{
const string valueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(valueString, value.ToString("X32"));
const string ValueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(ValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(ValueString, value.ToString("X32"));
}
}
}
\ No newline at end of file
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
......@@ -11,18 +10,11 @@ namespace PcapDotNet.Base.Test
[TestClass]
public class UInt24Tests
{
public UInt24Tests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -55,11 +47,13 @@ namespace PcapDotNet.Base.Test
UInt24 value = random.NextUInt24();
Assert.AreEqual(value, value);
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
// ReSharper restore EqualExpressionComparison
Assert.AreNotEqual(value, "string");
Assert.AreNotEqual(value, (UInt24)(((value & 0x00FFFF) + 1)| value & 0xFF0000));
Assert.AreNotEqual(value, (UInt24)((value & 0x00FFFF)| ((value & 0xFF0000) + 0x010000)));
Assert.AreNotEqual(value, (UInt24)(((value & 0x00FFFF) + 1) | value & 0xFF0000));
Assert.AreNotEqual(value, (UInt24)((value & 0x00FFFF) | ((value & 0xFF0000) + 0x010000)));
Assert.IsNotNull(value.GetHashCode());
Assert.AreEqual(((int)value).ToString(), value.ToString());
}
......
using System;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
......@@ -14,18 +11,11 @@ namespace PcapDotNet.Base.Test
[TestClass]
public class UInt48Tests
{
public UInt48Tests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -97,8 +87,10 @@ namespace PcapDotNet.Base.Test
Assert.AreEqual(value, value);
Assert.AreNotEqual(value, "1");
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
// ReSharper restore EqualExpressionComparison
Assert.IsNotNull(value.GetHashCode());
if (value < uint.MaxValue)
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace PcapDotNet.Base
{
......
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
......@@ -11,7 +9,9 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for IEnumerable of type T.
/// </summary>
// ReSharper disable InconsistentNaming
public static class IEnumerableExtensions
// ReSharper restore InconsistentNaming
{
/// <summary>
/// True iff the sequence has no elements.
......
......@@ -6,7 +6,9 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for IList of type T.
/// </summary>
// ReSharper disable InconsistentNaming
public static class IListExtensions
// ReSharper restore InconsistentNaming
{
/// <summary>
/// Wraps a list with a ReadOnlyCollection.
......
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace PcapDotNet.Base
{
......
......@@ -78,7 +78,7 @@ namespace PcapDotNet.Base
throw new NotSupportedException("Only " + NumberStyles.HexNumber + " style is supported");
ulong mostSignficantLong = 0;
ulong leastSignficantLong = 0;
ulong leastSignficantLong;
if (value.Length > 16)
{
leastSignficantLong = ulong.Parse(value.Substring(value.Length - 16, 16), style, provider);
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
namespace PcapDotNet.Base
{
......
......@@ -481,7 +481,7 @@ namespace PcapDotNet.Base
/// <returns>The 8 bit value converted from the 48 bit value.</returns>
public static explicit operator byte(UInt48 value)
{
return (byte)value.ToByte();
return value.ToByte();
}
/// <summary>
......
using System;
using System.Linq;
using System.Net.NetworkInformation;
using PcapDotNet.Base;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Ethernet;
......@@ -24,13 +24,7 @@ namespace PcapDotNet.Core.Extensions
if (livePacketDevice == null)
throw new ArgumentNullException("livePacketDevice");
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
if (@"rpcap://\Device\NPF_" + networkInterface.Id == livePacketDevice.Name)
return networkInterface;
}
return null;
return NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(networkInterface => @"rpcap://\Device\NPF_" + networkInterface.Id == livePacketDevice.Name);
}
/// <summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PcapDotNet.Packets;
namespace PcapDotNet.Core.Extensions
......
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
......@@ -11,13 +11,6 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class BerkeleyPacketFilterTests
{
public BerkeleyPacketFilterTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
......@@ -99,23 +92,23 @@ namespace PcapDotNet.Core.Test
{
const string SourceMac = "11:22:33:44:55:66";
const string DestinationMac = "77:88:99:AA:BB:CC";
const int snapshotLength = 500;
const int SnapshotLength = 500;
Random random = new Random();
using (BerkeleyPacketFilter filter = new BerkeleyPacketFilter("ether src " + SourceMac + " and ether dst " + DestinationMac, snapshotLength, DataLinkKind.Ethernet))
using (BerkeleyPacketFilter filter = new BerkeleyPacketFilter("ether src " + SourceMac + " and ether dst " + DestinationMac, SnapshotLength, DataLinkKind.Ethernet))
{
Assert.IsTrue(filter.Test(random.NextEthernetPacket(snapshotLength / 2, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(snapshotLength - 1, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(snapshotLength, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(snapshotLength + 1, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(snapshotLength * 2, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(SnapshotLength / 2, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(SnapshotLength - 1, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(SnapshotLength, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(SnapshotLength + 1, SourceMac, DestinationMac)));
Assert.IsTrue(filter.Test(random.NextEthernetPacket(SnapshotLength * 2, SourceMac, DestinationMac)));
Assert.IsFalse(filter.Test(random.NextEthernetPacket(snapshotLength / 2, DestinationMac, SourceMac)));
Assert.IsFalse(filter.Test(random.NextEthernetPacket(SnapshotLength / 2, DestinationMac, SourceMac)));
int actualSnapshotLength;
Assert.IsTrue(filter.Test(out actualSnapshotLength, random.NextEthernetPacket(snapshotLength / 2, SourceMac, DestinationMac)));
Assert.AreEqual(snapshotLength, actualSnapshotLength);
Assert.IsTrue(filter.Test(out actualSnapshotLength, random.NextEthernetPacket(SnapshotLength / 2, SourceMac, DestinationMac)));
Assert.AreEqual(SnapshotLength, actualSnapshotLength);
}
}
......
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Core.Extensions;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Core.Test
{
......@@ -11,17 +10,10 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class LivePacketDeviceExtensionsTests
{
public LivePacketDeviceExtensionsTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using PcapDotNet.Core.Extensions;
using PcapDotNet.Packets;
......@@ -29,10 +25,10 @@ namespace PcapDotNet.Core.Test
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -152,7 +148,7 @@ namespace PcapDotNet.Core.Test
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend / 2, int.MaxValue, 2, PacketSize, NumPacketsToSend / 2, 0, 0.032);
// Wait for more packets
TestReceivePacketsEnumerable(NumPacketsToSend, -1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.029);
TestReceivePacketsEnumerable(NumPacketsToSend, -1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.031);
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend + 1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.13);
// Break loop
......@@ -682,7 +678,7 @@ namespace PcapDotNet.Core.Test
private static void TestReceiveSomePackets(int numPacketsToSend, int numPacketsToGet, int numPacketsToBreakLoop, int packetSize, bool nonBlocking,
PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets, double expectedMinSeconds, double expectedMaxSeconds)
{
string TestDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToGet=" + numPacketsToGet +
string testDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToGet=" + numPacketsToGet +
". NumPacketsToBreakLoop=" + numPacketsToBreakLoop + ". PacketSize=" + packetSize +
". NonBlocking=" + nonBlocking;
......@@ -711,9 +707,9 @@ namespace PcapDotNet.Core.Test
DateTime finishedWaiting = DateTime.Now;
Assert.AreEqual(expectedResult, result);
Assert.AreEqual(expectedNumPackets, numPacketsGot, "NumPacketsGot. Test: " + TestDescription);
Assert.AreEqual(expectedNumPackets, handler.NumPacketsHandled, "NumPacketsHandled. Test: " + TestDescription);
MoreAssert.IsInRange(expectedMinSeconds, expectedMaxSeconds, (finishedWaiting - startWaiting).TotalSeconds, TestDescription);
Assert.AreEqual(expectedNumPackets, numPacketsGot, "NumPacketsGot. Test: " + testDescription);
Assert.AreEqual(expectedNumPackets, handler.NumPacketsHandled, "NumPacketsHandled. Test: " + testDescription);
MoreAssert.IsInRange(expectedMinSeconds, expectedMaxSeconds, (finishedWaiting - startWaiting).TotalSeconds, testDescription);
}
}
......@@ -721,7 +717,7 @@ namespace PcapDotNet.Core.Test
PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets,
double expectedMinSeconds, double expectedMaxSeconds)
{
string TestDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToWait=" + numPacketsToWait +
string testDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToWait=" + numPacketsToWait +
". NumPacketsToBreakLoop=" + numPacketsToBreakLoop + ". SecondsToWait=" +
secondsToWait + ". PacketSize=" + packetSize;
......@@ -756,7 +752,7 @@ namespace PcapDotNet.Core.Test
thread.Abort();
DateTime finishedWaiting = DateTime.Now;
Assert.AreEqual(expectedResult, result, TestDescription);
Assert.AreEqual(expectedResult, result, testDescription);
Assert.AreEqual(expectedNumPackets, handler.NumPacketsHandled);
MoreAssert.IsInRange(expectedMinSeconds, expectedMaxSeconds, (finishedWaiting - startWaiting).TotalSeconds);
}
......@@ -765,7 +761,7 @@ namespace PcapDotNet.Core.Test
private static void TestReceivePacketsEnumerable(int numPacketsToSend, int numPacketsToWait, int numPacketsToBreakLoop, double secondsToWait,
int packetSize, int expectedNumPackets, double expectedMinSeconds, double expectedMaxSeconds)
{
string TestDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToWait=" + numPacketsToWait +
string testDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToWait=" + numPacketsToWait +
". NumPacketsToBreakLoop=" + numPacketsToBreakLoop + ". SecondsToWait=" +
secondsToWait + ". PacketSize=" + packetSize;
......@@ -806,8 +802,8 @@ namespace PcapDotNet.Core.Test
thread.Abort();
DateTime finishedWaiting = DateTime.Now;
Assert.AreEqual(expectedNumPackets, actualPacketsReceived, TestDescription);
MoreAssert.IsInRange(expectedMinSeconds, expectedMaxSeconds, (finishedWaiting - startWaiting).TotalSeconds, TestDescription);
Assert.AreEqual(expectedNumPackets, actualPacketsReceived, testDescription);
MoreAssert.IsInRange(expectedMinSeconds, expectedMaxSeconds, (finishedWaiting - startWaiting).TotalSeconds, testDescription);
}
}
......@@ -874,6 +870,6 @@ namespace PcapDotNet.Core.Test
}
}
private static Random _random = new Random();
private static readonly Random _random = new Random();
}
}
\ No newline at end of file
......@@ -8,13 +8,6 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class MarshalingServicesTests
{
public MarshalingServicesTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
......
......@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
......@@ -52,10 +51,7 @@ namespace PcapDotNet.Core.Test
StringBuilder quickStartWireshark = new StringBuilder("Quick-Start: ");
if (quickStart.Function == IpV4OptionQuickStartFunction.RateRequest)
quickStartWireshark.Append("Rate request");
else
quickStartWireshark.Append("Rate report");
quickStartWireshark.Append(quickStart.Function == IpV4OptionQuickStartFunction.RateRequest ? "Rate request" : "Rate report");
quickStartWireshark.Append(", ");
......@@ -146,7 +142,9 @@ namespace PcapDotNet.Core.Test
}
break;
// ReSharper disable RedundantCaseLabel
case IpV4OptionType.BasicSecurity:
// ReSharper restore RedundantCaseLabel
default:
if (typeof(IpV4OptionType).GetEnumValues<IpV4OptionType>().Contains(option.OptionType))
throw new InvalidOperationException("Invalid option type " + option.OptionType);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PcapDotNet.Base;
using PcapDotNet.Packets.Transport;
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets;
......@@ -16,18 +14,11 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class OfflinePacketDeviceTests
{
public OfflinePacketDeviceTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -156,7 +147,7 @@ namespace PcapDotNet.Core.Test
[ExpectedException(typeof(InvalidOperationException))]
public void OpenInvalidFileTest()
{
using (PacketCommunicator communicator = new OfflinePacketDevice("myinvalidfile").Open())
using (new OfflinePacketDevice("myinvalidfile").Open())
{
}
}
......@@ -256,7 +247,7 @@ namespace PcapDotNet.Core.Test
PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets,
double expectedMinSeconds, double expectedMaxSeconds)
{
string TestDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToGet=" + numPacketsToGet +
string testDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToGet=" + numPacketsToGet +
". NumPacketsToBreakLoop=" + numPacketsToBreakLoop;
const string SourceMac = "11:22:33:44:55:66";
......@@ -275,8 +266,8 @@ namespace PcapDotNet.Core.Test
int numPacketsGot;
PacketCommunicatorReceiveResult result = communicator.ReceiveSomePackets(out numPacketsGot, numPacketsToGet, handler.Handle);
Assert.AreEqual(expectedResult, result);
Assert.AreEqual(expectedNumPackets, numPacketsGot, "NumPacketsGot. Test: " + TestDescription);
Assert.AreEqual(expectedNumPackets, handler.NumPacketsHandled, "NumPacketsHandled. Test: " + TestDescription);
Assert.AreEqual(expectedNumPackets, numPacketsGot, "NumPacketsGot. Test: " + testDescription);
Assert.AreEqual(expectedNumPackets, handler.NumPacketsHandled, "NumPacketsHandled. Test: " + testDescription);
}
}
......@@ -284,7 +275,7 @@ namespace PcapDotNet.Core.Test
PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets,
double expectedMinSeconds, double expectedMaxSeconds)
{
string TestDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToGet=" + numPacketsToGet +
string testDescription = "NumPacketsToSend=" + numPacketsToSend + ". NumPacketsToGet=" + numPacketsToGet +
". NumPacketsToBreakLoop=" + numPacketsToBreakLoop;
const string SourceMac = "11:22:33:44:55:66";
......@@ -312,7 +303,7 @@ namespace PcapDotNet.Core.Test
thread.Abort();
}
Assert.AreEqual(expectedResult, result, TestDescription);
Assert.AreEqual(expectedResult, result, testDescription);
Assert.AreEqual(expectedNumPackets, handler.NumPacketsHandled);
}
}
......@@ -383,6 +374,6 @@ namespace PcapDotNet.Core.Test
}
}
private static Random _random = new Random();
private static readonly Random _random = new Random();
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Icmp;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Core.Test
{
......@@ -15,18 +12,11 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class PacketDumpFileTests
{
public PacketDumpFileTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
......@@ -13,18 +13,11 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class PacketSendQueueTests
{
public PacketSendQueueTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -153,6 +146,6 @@ namespace PcapDotNet.Core.Test
return queue;
}
private static Random _random = new Random();
private static readonly Random _random = new Random();
}
}
\ No newline at end of file
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets;
namespace PcapDotNet.Core.Test
{
......@@ -10,18 +9,11 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class PcapDataLinkTests
{
public PcapDataLinkTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -109,10 +101,9 @@ namespace PcapDotNet.Core.Test
for (int i = 0; i != 1000; ++i)
{
PcapDataLink dataLink = new PcapDataLink(i);
string dataLinkName;
try
{
dataLinkName = dataLink.Name;
string dataLinkName = dataLink.Name;
Assert.IsNotNull(dataLinkName);
}
catch (InvalidOperationException)
......
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Core.Test
......@@ -13,18 +9,11 @@ namespace PcapDotNet.Core.Test
[TestClass]
public class PcapLibTests
{
public PcapLibTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
......@@ -31,18 +31,11 @@ namespace PcapDotNet.Core.Test
private const string WiresharkDiretory = @"C:\Program Files\Wireshark\";
private const string WiresharkTsharkPath = WiresharkDiretory + @"tshark.exe";
public WiresharkCompareTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -82,8 +75,8 @@ namespace PcapDotNet.Core.Test
[TestMethod]
public void CompareTimestampPacketsToWiresharkTest()
{
const long ticks = 633737178954260865;
DateTime timestamp = new DateTime(ticks).ToUniversalTime().ToLocalTime();
const long Ticks = 633737178954260865;
DateTime timestamp = new DateTime(Ticks).ToUniversalTime().ToLocalTime();
// Create packet
Packet packet = new Packet(new byte[14], timestamp, DataLinkKind.Ethernet);
......@@ -180,19 +173,25 @@ namespace PcapDotNet.Core.Test
{
string pcapFilename = Path.GetTempPath() + "temp." + new Random().NextByte() + ".pcap";
// const bool isRetry = true;
const bool isRetry = false;
if (!isRetry)
const bool IsRetry = false;
#pragma warning disable 162
// ReSharper disable ConditionIsAlwaysTrueOrFalse
// ReSharper disable HeuristicUnreachableCode
if (!IsRetry)
{
PacketDumpFile.Dump(pcapFilename, new PcapDataLink(DataLinkKind.Ethernet), PacketDevice.DefaultSnapshotLength, packets);
}
else
{
const byte retryNumber = 55;
pcapFilename = Path.GetTempPath() + "temp." + retryNumber + ".pcap";
const byte RetryNumber = 55;
pcapFilename = Path.GetTempPath() + "temp." + RetryNumber + ".pcap";
List<Packet> packetsList = new List<Packet>();
new OfflinePacketDevice(pcapFilename).Open().ReceivePackets(1000, packetsList.Add);
packets = packetsList;
}
// ReSharper restore HeuristicUnreachableCode
// ReSharper restore ConditionIsAlwaysTrueOrFalse
#pragma warning restore 162
// Create pdml file
string documentFilename = pcapFilename + ".pdml";
......
......@@ -5,7 +5,6 @@ using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Packets.Test
{
......@@ -15,17 +14,10 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class ArpTests
{
public ArpTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
......@@ -10,17 +10,10 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class ByteArrayExtensionsTests
{
public ByteArrayExtensionsTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
......@@ -8,18 +8,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class DataLinkTests
{
public DataLinkTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -50,8 +43,10 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(DataLink.Ethernet, 2);
Assert.AreEqual(DataLinkKind.Ethernet.ToString(), DataLink.Ethernet.ToString());
Assert.AreEqual(DataLink.Ethernet.GetHashCode(), DataLink.Ethernet.GetHashCode());
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(DataLink.Ethernet == DataLink.Ethernet);
Assert.IsFalse(DataLink.Ethernet != DataLink.Ethernet);
// ReSharper restore EqualExpressionComparison
}
}
}
\ No newline at end of file
......@@ -16,18 +16,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class DatagramTests
{
public DatagramTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
......@@ -9,18 +9,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class EndianitiyTests
{
public EndianitiyTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -119,18 +112,18 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void UIntTest()
{
const uint value = 0x01020304;
const uint Value = 0x01020304;
byte[] buffer = new byte[sizeof(uint)];
buffer.Write(0, value, Endianity.Big);
Assert.AreEqual(value, buffer.ReadUInt(0, Endianity.Big));
buffer.Write(0, Value, Endianity.Big);
Assert.AreEqual(Value, buffer.ReadUInt(0, Endianity.Big));
Assert.AreEqual(0x01, buffer[0]);
Assert.AreEqual(0x02, buffer[1]);
Assert.AreEqual(0x03, buffer[2]);
Assert.AreEqual(0x04, buffer[3]);
buffer.Write(0, value, Endianity.Small);
Assert.AreEqual(value, buffer.ReadUInt(0, Endianity.Small));
buffer.Write(0, Value, Endianity.Small);
Assert.AreEqual(Value, buffer.ReadUInt(0, Endianity.Small));
Assert.AreEqual(0x04, buffer[0]);
Assert.AreEqual(0x03, buffer[1]);
Assert.AreEqual(0x02, buffer[2]);
......
......@@ -13,18 +13,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class EthernetTests
{
public EthernetTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Gre;
using PcapDotNet.Packets.Icmp;
......@@ -19,13 +17,6 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class GreTests
{
public GreTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
......
......@@ -2,10 +2,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Icmp;
using PcapDotNet.Packets.Igmp;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.TestUtils;
......@@ -18,18 +16,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class IcmpTests
{
public IcmpTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext{ get; set;}
public TestContext TestContext { get; set; }
#region Additional test attributes
//
......
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Igmp;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Packets.Test
......@@ -18,18 +16,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class IgmpTests
{
public IgmpTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
......@@ -14,22 +11,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class IpV4AddressTests
{
public IpV4AddressTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get;
set;
}
/// 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
//
......
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
......@@ -17,18 +14,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class IpV4Tests
{
public IpV4Tests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......@@ -90,13 +80,13 @@ namespace PcapDotNet.Packets.Test
{
MacAddress ethernetSource = new MacAddress("00:01:02:03:04:05");
MacAddress ethernetDestination = new MacAddress("A0:A1:A2:A3:A4:A5");
const EthernetType ethernetType = EthernetType.IpV4;
const EthernetType EthernetType = EthernetType.IpV4;
EthernetLayer ethernetLayer = new EthernetLayer
{
Source = ethernetSource,
Destination = ethernetDestination,
EtherType = ethernetType
EtherType = EthernetType
};
Random random = new Random();
......@@ -237,7 +227,7 @@ namespace PcapDotNet.Packets.Test
public void IpV4OptionRoutePointedAddressIndexErrorTest()
{
Random random = new Random();
IpV4Option option = new IpV4OptionRecordRoute(random.NextByte(IpV4OptionRecordRoute.PointedAddressIndexMaxValue + 1, byte.MaxValue + 1));
IpV4Option option = new IpV4OptionRecordRoute(random.NextByte(IpV4OptionRoute.PointedAddressIndexMaxValue + 1, byte.MaxValue + 1));
Assert.IsNotNull(option);
Assert.Fail();
}
......@@ -327,8 +317,10 @@ namespace PcapDotNet.Packets.Test
IpV4TimeOfDay timeSinceMidnight = new IpV4TimeOfDay(timeOfDay);
Assert.AreEqual(timeOfDay, timeSinceMidnight.TimeSinceMidnightUniversalTime);
Assert.AreEqual<object>(timeSinceMidnight, timeSinceMidnight);
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(timeSinceMidnight == timeSinceMidnight);
Assert.IsFalse(timeSinceMidnight != timeSinceMidnight);
// ReSharper restore EqualExpressionComparison
}
[TestMethod]
......
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6;
using PcapDotNet.Packets.TestUtils;
......@@ -12,13 +11,6 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class IpV6AddressTests
{
public IpV6AddressTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
......
......@@ -11,18 +11,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class MacAddressTests
{
public MacAddressTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
......@@ -10,17 +10,10 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class PacketBuilderTests
{
public PacketBuilderTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
......@@ -14,18 +14,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class PacketTests
{
public PacketTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
......@@ -12,17 +12,10 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class PayloadLayerTests
{
public PayloadLayerTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</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
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Packets.Test
{
......@@ -15,18 +13,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class TcpTests
{
public TcpTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
......@@ -4,7 +4,6 @@ using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Packets.Test
{
......@@ -14,18 +13,11 @@ namespace PcapDotNet.Packets.Test
[TestClass]
public class UdpTests
{
public UdpTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext{ get; set;}
/// 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
//
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using PcapDotNet.Base;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Gre;
......@@ -511,11 +508,11 @@ namespace PcapDotNet.Packets.TestUtils
IgmpQueryVersion igmpQueryVersion = IgmpQueryVersion.None;
TimeSpan igmpMaxResponseTime = random.NextTimeSpan(TimeSpan.FromSeconds(0.1), TimeSpan.FromSeconds(256 * 0.1) - TimeSpan.FromTicks(1));
IpV4Address igmpGroupAddress = random.NextIpV4Address();
bool? igmpIsSuppressRouterSideProcessing = null;
byte? igmpQueryRobustnessVariable = null;
TimeSpan? igmpQueryInterval = null;
IpV4Address[] igmpSourceAddresses = null;
IgmpGroupRecord[] igmpGroupRecords = null;
bool? igmpIsSuppressRouterSideProcessing;
byte? igmpQueryRobustnessVariable;
TimeSpan? igmpQueryInterval;
IpV4Address[] igmpSourceAddresses;
IgmpGroupRecord[] igmpGroupRecords;
switch (igmpMessageType)
{
......@@ -870,10 +867,6 @@ namespace PcapDotNet.Packets.TestUtils
icmpPayloadLayers = icmpPayloadLayers.Concat(random.NextIpV4Layer(), random.NextPayloadLayer(IcmpIpV4HeaderPlus64BitsPayloadDatagram.OriginalDatagramPayloadLength));
break;
case IcmpMessageType.ConversionFailed:
IpV4Protocol icmpIpV4Protocol = random.NextBool()
? random.NextValue(new[] {IpV4Protocol.Udp, IpV4Protocol.Tcp})
: random.NextEnum<IpV4Protocol>();
IpV4Layer icmpIpV4Layer = random.NextIpV4Layer();
icmpPayloadLayers = icmpPayloadLayers.Concat(icmpIpV4Layer);
if (icmpLayer.MessageTypeAndCode == IcmpMessageTypeAndCode.ConversionFailedUnsupportedTransportProtocol)
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Serialization;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
namespace PcapDotNet.Packets.Arp
......@@ -13,13 +10,6 @@ namespace PcapDotNet.Packets.Arp
/// </summary>
public class ArpLayer : Layer, IEthernetNextLayer
{
/// <summary>
/// Create an ARP layer.
/// </summary>
public ArpLayer()
{
}
/// <summary>
/// Each protocol is assigned a number used in this field.
/// </summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
......
......@@ -2,7 +2,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
......
......@@ -79,7 +79,7 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary>
public override ILayer ExtractLayer()
{
return new EthernetLayer()
return new EthernetLayer
{
Source = Source,
Destination = Destination,
......@@ -138,13 +138,10 @@ namespace PcapDotNet.Packets.Ethernet
{
get
{
if (_payloadDatagrams == null)
{
_payloadDatagrams = new EthernetPayloadDatagrams(Length >= HeaderLength
? new Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength)
: null);
}
return _payloadDatagrams;
return _payloadDatagrams ?? (_payloadDatagrams = new EthernetPayloadDatagrams(Length >= HeaderLength
? new Datagram(Buffer, StartOffset + HeaderLength,
Length - HeaderLength)
: null));
}
}
......
......@@ -380,14 +380,14 @@ namespace PcapDotNet.Packets.Gre
ReadOnlyCollection<GreSourceRouteEntry> routing, ushort? routingOffset, bool strictSourceRoute)
{
buffer.Write(offset + Offset.ChecksumPresent,
(byte)((checksumPresent ? Mask.ChecksumPresent : (byte)0) |
(routing != null ? Mask.RoutingPresent : (byte)0) |
(key != null ? Mask.KeyPresent : (byte)0) |
(sequenceNumber != null ? Mask.SequenceNumberPresent : (byte)0) |
(strictSourceRoute ? Mask.StrictSourceRoute : (byte)0) |
(byte)((checksumPresent ? Mask.ChecksumPresent : 0) |
(routing != null ? Mask.RoutingPresent : 0) |
(key != null ? Mask.KeyPresent : 0) |
(sequenceNumber != null ? Mask.SequenceNumberPresent : 0) |
(strictSourceRoute ? Mask.StrictSourceRoute : 0) |
(recursionControl & Mask.RecursionControl)));
buffer.Write(offset + Offset.FutureUseBits, (byte)((acknowledgmentSequenceNumber != null ? Mask.AcknowledgmentSequenceNumberPresent : (byte)0) |
buffer.Write(offset + Offset.FutureUseBits, (byte)((acknowledgmentSequenceNumber != null ? Mask.AcknowledgmentSequenceNumberPresent : 0) |
((flags << Shift.FutureUseBits) & Mask.FutureUseBits) |
((byte)version & Mask.Version)));
......@@ -515,13 +515,10 @@ namespace PcapDotNet.Packets.Gre
{
get
{
if (_payloadDatagrams == null)
{
_payloadDatagrams = new EthernetPayloadDatagrams(Length >= HeaderLength
? new Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength)
: null);
}
return _payloadDatagrams;
return _payloadDatagrams ?? (_payloadDatagrams = new EthernetPayloadDatagrams(Length >= HeaderLength
? new Datagram(Buffer, StartOffset + HeaderLength,
Length - HeaderLength)
: null));
}
}
......
......@@ -133,7 +133,7 @@ namespace PcapDotNet.Packets.Gre
{
buffer.Write(offset + Offset.AddressFamily, (ushort)AddressFamily, Endianity.Big);
buffer.Write(offset + Offset.SreOffset, PayloadOffset);
buffer.Write(offset + Offset.SreLength, (byte)PayloadLength);
buffer.Write(offset + Offset.SreLength, PayloadLength);
WritePayload(buffer, offset + HeaderLength);
offset += Length;
}
......
......@@ -4,7 +4,7 @@ namespace PcapDotNet.Packets
/// A factory interface for an unknown option.
/// </summary>
/// <typeparam name="TOptionType">The option type enum type.</typeparam>
public interface IOptionUnknownFactory<TOptionType>
public interface IOptionUnknownFactory<in TOptionType>
{
/// <summary>
/// Creates an unknown option from its type and by reading a buffer for its value.
......
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
......
using System;
using System.Linq;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Icmp
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
using System.Linq;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
......@@ -12,13 +11,6 @@ namespace PcapDotNet.Packets.Icmp
/// </summary>
public class IcmpRouterAdvertisementLayer : IcmpLayer
{
/// <summary>
/// Creates an ICMP layer instance.
/// </summary>
public IcmpRouterAdvertisementLayer()
{
}
/// <summary>
/// The maximum time that the router addresses may be considered valid.
/// </summary>
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
using System.Linq;
using PcapDotNet.Base;
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
......
using System;
using System.Linq;
using PcapDotNet.Base;
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Base;
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Base;
......
using System;
using System.Collections;
using System.Linq;
using System.Text;
using PcapDotNet.Packets.Gre;
using PcapDotNet.Packets.Icmp;
using PcapDotNet.Packets.Igmp;
......@@ -180,12 +177,7 @@ namespace PcapDotNet.Packets.IpV4
/// </summary>
public IpV4Options Options
{
get
{
if (_options == null)
_options = new IpV4Options(Buffer, StartOffset + Offset.Options, RealHeaderLength - HeaderMinimumLength);
return _options;
}
get { return _options ?? (_options = new IpV4Options(Buffer, StartOffset + Offset.Options, RealHeaderLength - HeaderMinimumLength)); }
}
/// <summary>
......
using System;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV4
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace PcapDotNet.Packets.IpV4
{
/// <summary>
......
using System.Collections.Generic;
using System.Collections.ObjectModel;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV4
{
......
using System.Collections.Generic;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV4
{
......
using System.Collections.Generic;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV4
{
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
......
using System;
namespace PcapDotNet.Packets.IpV4
{
/// <summary>
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV4
{
......
using System;
namespace PcapDotNet.Packets
{
/// <summary>
......@@ -7,7 +9,7 @@ namespace PcapDotNet.Packets
/// A packet can be according to a sequence of layers.
/// <seealso cref="PacketBuilder"/>
/// </summary>
public abstract class Layer : ILayer
public abstract class Layer : ILayer, IEquatable<Layer>
{
/// <summary>
/// The number of bytes this layer will take.
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using PcapDotNet.Base;
......@@ -25,7 +24,7 @@ namespace PcapDotNet.Packets
IOptionComplexFactory prototype;
if (!_complexOptions.TryGetValue(optionType, out prototype))
return UnknownFactoryOptionPrototype.CreateInstance(optionType, buffer, ref offset, optionValueLength);
return _unknownFactoryOptionPrototype.CreateInstance(optionType, buffer, ref offset, optionValueLength);
return prototype.CreateInstance(buffer, ref offset, optionValueLength);
}
......@@ -72,6 +71,6 @@ namespace PcapDotNet.Packets
}
private static readonly Dictionary<TOptionType, IOptionComplexFactory> _complexOptions = InitializeComplexOptions();
private static readonly IOptionUnknownFactory<TOptionType> UnknownFactoryOptionPrototype = InitializeUnknownOptionPrototype();
private static readonly IOptionUnknownFactory<TOptionType> _unknownFactoryOptionPrototype = InitializeUnknownOptionPrototype();
}
}
\ No newline at end of file
using System;
using System.Diagnostics;
namespace PcapDotNet.Packets
{
// internal static class OptionComplexFactoryBase
// {
// /// <summary>
// /// The header length in bytes for the option (type and size).
// /// </summary>
// public const int OptionHeaderLength = 2;
//
//// [DebuggerHidden]
//// protected OptionComplexFactoryBase()
//// {
//// throw new NotImplementedException();
//// }
// }
}
\ No newline at end of file
......@@ -252,12 +252,7 @@ namespace PcapDotNet.Packets
/// </summary>
public EthernetDatagram Ethernet
{
get
{
if (_ethernet == null)
_ethernet = new EthernetDatagram(Buffer, 0, Length);
return _ethernet;
}
get { return _ethernet ?? (_ethernet = new EthernetDatagram(Buffer, 0, Length)); }
}
private bool CalculateIsValid()
......
......@@ -223,7 +223,6 @@
<Compile Include="IpV4\IpV4Protocol.cs" />
<Compile Include="ByteArrayExtensions.cs" />
<Compile Include="OptionComplexFactory.cs" />
<Compile Include="OptionComplexFactoryBase.cs" />
<Compile Include="Options.cs" />
<Compile Include="OptionTypeRegistrationAttribute.cs" />
<Compile Include="Packet.cs" />
......
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
......@@ -159,12 +159,7 @@ namespace PcapDotNet.Packets.Transport
/// </summary>
public TcpOptions Options
{
get
{
if (_options == null)
_options = new TcpOptions(Buffer, StartOffset + Offset.Options, RealHeaderLength - HeaderMinimumLength);
return _options;
}
get { return _options ?? (_options = new TcpOptions(Buffer, StartOffset + Offset.Options, RealHeaderLength - HeaderMinimumLength)); }
}
/// <summary>
......
using System;
namespace PcapDotNet.Packets.Transport
{
/// <summary>
/// Represents a block to ack when using the selective ack option.
/// </summary>
public struct TcpOptionSelectiveAcknowledgmentBlock
public struct TcpOptionSelectiveAcknowledgmentBlock : IEquatable<TcpOptionSelectiveAcknowledgmentBlock>
{
/// <summary>
/// The number of bytes this struct take.
......
using System;
using System.Collections.Generic;
namespace PcapDotNet.Packets.Transport
......
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