public void Constructor( ) { var srcMac = new NetMacAddress(1LU); var dstMac = new NetMacAddress(2LU); var srcInterf = new Abstract.Fakes.StubINetHwInterface( ); srcInterf.HardwareAddressGet = ( ) => srcMac; var dstInterf = new Abstract.Fakes.StubINetHwInterface( ); dstInterf.HardwareAddressGet = ( ) => dstMac; var srcAddress = new NetAddress( new NetIpAddress(182, 95, 34, 147), new NetIpAddress(255, 254, 11, 201), new NetIpAddress(182, 94, 0, 0)); var dstAddress = new NetAddress( new NetIpAddress(214, 21, 157, 193), new NetIpAddress(255, 255, 192, 0), new NetIpAddress(214, 21, 0, 0)); var netPacket = new SUTest( ((INetHwInterface)srcInterf).HardwareAddress, ((INetHwInterface)dstInterf).HardwareAddress, srcAddress, dstAddress); Assert.AreEqual(srcMac, netPacket.SourceHardwareAddress); Assert.AreEqual(dstMac, netPacket.DestinationHardwareAddress); Assert.AreEqual(srcAddress, netPacket.SourceAddress); Assert.AreEqual(dstAddress, netPacket.DestinationAddress); Assert.AreEqual(30, netPacket.TTL); }
public void Equals( ) { var ipAddressByte = new SUTest(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }); var ipAddressUint = new SUTest(ulong.MinValue); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressByte)); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); ipAddressByte = new SUTest(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }); Assert.AreEqual(false, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(false, ipAddressUint.Equals(ipAddressByte)); ipAddressUint = new SUTest(ulong.MaxValue); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); ipAddressByte = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 64, 32 }); Assert.AreEqual(false, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(false, ipAddressUint.Equals(ipAddressByte)); ipAddressUint = new SUTest(4286595104u); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); ipAddressByte = new SUTest(new byte[] { 0, 0, 0, 0, 0, 128, 64, 32 }); Assert.AreEqual(false, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(false, ipAddressUint.Equals(ipAddressByte)); ipAddressUint = new SUTest(8405024u); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); ipAddressByte = new SUTest(new byte[] { 0, 0, 0, 0, 255, 0, 64, 32 }); Assert.AreEqual(false, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(false, ipAddressUint.Equals(ipAddressByte)); ipAddressUint = new SUTest(4278206496u); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); ipAddressByte = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 0, 32 }); Assert.AreEqual(false, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(false, ipAddressUint.Equals(ipAddressByte)); ipAddressUint = new SUTest(4286578720u); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); ipAddressByte = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 64, 0 }); Assert.AreEqual(false, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(false, ipAddressUint.Equals(ipAddressByte)); ipAddressUint = new SUTest(4286595072u); Assert.AreEqual(true, ipAddressByte.Equals(ipAddressUint)); Assert.AreEqual(true, ipAddressUint.Equals(ipAddressByte)); }
public bool Equals(NetMacAddress other) { var thisBytes = Bytes; var otherBytes = other.Bytes; if (thisBytes == null) thisBytes = Zero.Bytes; if (otherBytes == null) otherBytes = Zero.Bytes; return thisBytes.Length == otherBytes.Length && thisBytes.SequenceEqual(otherBytes); }
public void Constructor_UintEmpty( ) { var ipAddress = new SUTest(ulong.MinValue); CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, ipAddress.Bytes); ipAddress = new SUTest(ulong.MaxValue); CollectionAssert.AreEqual(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }, ipAddress.Bytes); ipAddress = new SUTest(4286595104u); CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 0, 255, 128, 64, 32 }, ipAddress.Bytes); }
public void GetUlongRepresentation_FromUint( ) { var ipAddress = new SUTest(uint.MinValue); Assert.AreEqual(uint.MinValue, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(uint.MaxValue); Assert.AreEqual(uint.MaxValue, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(4286595104u); Assert.AreEqual(4286595104u, ipAddress.GetUlongRepresentation( )); }
private bool disposedValue = false; // To detect redundant calls #endregion Fields #region Constructors internal NetHwInterface(INetDevice parent, string name) { unchecked { n++; } if (parent == null) throw new ArgumentNullException("parent"); if (name == null) throw new ArgumentNullException("name"); if (name == string.Empty) throw new ArgumentException("name can not be empty"); this.parent = parent; this.name = name; this.hardwareAddress = new NetMacAddress(((ulong)DateTime.Now.Ticks << 8) + n); }
public bool Equals(NetMacAddress other) { var thisBytes = Bytes; var otherBytes = other.Bytes; if (thisBytes == null) { thisBytes = Zero.Bytes; } if (otherBytes == null) { otherBytes = Zero.Bytes; } return(thisBytes.Length == otherBytes.Length && thisBytes.SequenceEqual(otherBytes)); }
internal NetHwInterface(INetDevice parent, string name) { unchecked { n++; } if (parent == null) { throw new ArgumentNullException("parent"); } if (name == null) { throw new ArgumentNullException("name"); } if (name == string.Empty) { throw new ArgumentException("name can not be empty"); } this.parent = parent; this.name = name; this.hardwareAddress = new NetMacAddress(((ulong)DateTime.Now.Ticks << 8) + n); }
public void GetUlongRepresentation_FromByteArray( ) { var ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }); Assert.AreEqual(uint.MinValue, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 255, 255, 255 }); Assert.AreEqual(uint.MaxValue, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 64, 32 }); Assert.AreEqual(4286595104u, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 0, 128, 64, 32 }); Assert.AreEqual(8405024u, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 0, 64, 32 }); Assert.AreEqual(4278206496u, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 0, 32 }); Assert.AreEqual(4286578720u, ipAddress.GetUlongRepresentation( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 64, 0 }); Assert.AreEqual(4286595072u, ipAddress.GetUlongRepresentation( )); }
public void ToString_ValidInput( ) { var ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }); Assert.AreEqual("00-00-00-00-00-00-00-00", ipAddress.ToString( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 255, 255, 255 }); Assert.AreEqual("00-00-00-00-FF-FF-FF-FF", ipAddress.ToString( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 64, 32 }); Assert.AreEqual("00-00-00-00-FF-80-40-20", ipAddress.ToString( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 0, 128, 64, 32 }); Assert.AreEqual("00-00-00-00-00-80-40-20", ipAddress.ToString( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 0, 64, 32 }); Assert.AreEqual("00-00-00-00-FF-00-40-20", ipAddress.ToString( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 0, 32 }); Assert.AreEqual("00-00-00-00-FF-80-00-20", ipAddress.ToString( )); ipAddress = new SUTest(new byte[] { 0, 0, 0, 0, 255, 128, 64, 0 }); Assert.AreEqual("00-00-00-00-FF-80-40-00", ipAddress.ToString( )); }
public void Constructor_Empty( ) { var ipAddress = new SUTest( ); CollectionAssert.AreEqual(null, ipAddress.Bytes); }
public void Constructor_ByteArray( ) { var ipAddress = new SUTest(new byte[] { 247, 30, 63, 161, 142, 231, 21, 32 }); CollectionAssert.AreEqual(new byte[] { 247, 30, 63, 161, 142, 231, 21, 32 }, ipAddress.Bytes); }
internal NetPacket(NetMacAddress sourceHardwareAddress, NetMacAddress destinationHardwareAddress, NetAddress?sourceAddress, NetAddress?destinationAddress) : this(sourceHardwareAddress, destinationHardwareAddress) { this.sourceAddress = sourceAddress; this.destinationAddress = destinationAddress; }
public void Constructor_NullAddress( ) { var srcMac = new NetMacAddress(1LU); var dstMac = new NetMacAddress(2LU); var srcInterf = new Abstract.Fakes.StubINetHwInterface( ); srcInterf.HardwareAddressGet = ( ) => srcMac; var dstInterf = new Abstract.Fakes.StubINetHwInterface( ); dstInterf.HardwareAddressGet = ( ) => dstMac; var netPacket = new SUTest( ((INetHwInterface)srcInterf).HardwareAddress, ((INetHwInterface)dstInterf).HardwareAddress, null, null); Assert.AreEqual(srcMac, netPacket.SourceHardwareAddress); Assert.AreEqual(dstMac, netPacket.DestinationHardwareAddress); Assert.AreEqual(null, netPacket.SourceAddress); Assert.AreEqual(null, netPacket.DestinationAddress); Assert.AreEqual(30, netPacket.TTL); }
internal NetPacket(NetMacAddress sourceHardwareAddress, NetMacAddress destinationHardwareAddress, NetAddress? sourceAddress, NetAddress? destinationAddress) : this(sourceHardwareAddress, destinationHardwareAddress) { this.sourceAddress = sourceAddress; this.destinationAddress = destinationAddress; }
internal NetPacket(NetMacAddress sourceHardwareAddress, NetMacAddress destinationHardwareAddress) { this.sourceMacAddress = sourceHardwareAddress; this.destinationMacAddress = destinationHardwareAddress; TTL = 30; }