public void GetUniqueIdentifier() { Random random = new Random(); var resolver = new DHCPv6SimpleZyxelIESResolver(); Byte[] macAddress = random.NextBytes(6); Int32 slotId = random.NextByte(); Int32 portId = random.NextByte(); DHCPv6Packet packet = GetPacket(random, macAddress, slotId, portId); Byte[] actual = resolver.GetUniqueIdentifier(packet); for (int i = 0; i < 4; i++) { Assert.Equal(0, actual[i]); } for (int i = 0; i < macAddress.Length; i++) { Assert.Equal(macAddress[i], actual[i + 4]); } Byte[] expectedInterfaceValue = GetExpectedByteSequence(slotId, portId); for (int i = 0; i < expectedInterfaceValue.Length; i++) { Assert.Equal(expectedInterfaceValue[i], actual[i + macAddress.Length + 4]); } }
private static (UInt16 slotId, UInt16 portId) GetValidResolver(Random random, UInt16 index, out byte[] macAddress, out Mock <ISerializer> serializerMock, out DHCPv6SimpleZyxelIESResolver resolver) { UInt16 slotId = (UInt16)random.Next(0, 10); UInt16 portId = (UInt16)random.Next(0, 10); macAddress = random.NextBytes(6); String macAddressInput = ByteHelper.ToString(macAddress, false); String value = random.GetAlphanumericString(); serializerMock = new Mock <ISerializer>(MockBehavior.Strict); serializerMock.Setup(x => x.Deserialze <UInt16>(index.ToString())).Returns(index).Verifiable(); serializerMock.Setup(x => x.Deserialze <UInt16>(slotId.ToString())).Returns(slotId).Verifiable(); serializerMock.Setup(x => x.Deserialze <UInt16>(portId.ToString())).Returns(portId).Verifiable(); serializerMock.Setup(x => x.Deserialze <String>(macAddressInput)).Returns(macAddressInput).Verifiable(); resolver = new DHCPv6SimpleZyxelIESResolver(); resolver.ApplyValues(new Dictionary <String, String> { { "Index", index.ToString() }, { "SlotId", slotId.ToString() }, { "PortId", portId.ToString() }, { "DeviceMacAddress", macAddressInput }, }, serializerMock.Object); serializerMock.Verify(); return(slotId, portId); }
public void ArePropertiesAndValuesValid_KeyIsMissing() { var input = new[] { new Dictionary <String, String> { { "Index1", "0" }, { "SlotId", "0" }, { "PortId", "0" }, { "DeviceMacAddress", "0" }, }, new Dictionary <String, String> { { "Index", "0" }, { "SlotId1", "0" }, { "PortId", "0" }, { "DeviceMacAddress", "0" }, }, new Dictionary <String, String> { { "Index", "0" }, { "SlotId", "0" }, { "PortId1", "0" }, { "DeviceMacAddress", "0" }, }, new Dictionary <String, String> { { "Index", "0" }, { "SlotId", "0" }, { "PortId", "0" }, { "DeviceMacAddress1", "0" }, }, new Dictionary <String, String> { { "SlotId", "0" }, { "PortId", "0" }, { "DeviceMacAddress", "0" }, }, new Dictionary <String, String> { { "Index", "0" }, { "PortId", "0" }, { "DeviceMacAddress", "0" }, }, new Dictionary <String, String> { { "Index", "0" }, { "SlotId", "0" }, { "DeviceMacAddress", "0" }, }, new Dictionary <String, String> { { "Index", "0" }, { "SlotId", "0" }, { "PortId", "0" }, }, }; var resolver = new DHCPv6SimpleZyxelIESResolver(); foreach (var item in input) { Boolean actual = resolver.ArePropertiesAndValuesValid(item, Mock.Of <ISerializer>(MockBehavior.Strict)); Assert.False(actual); } }
public void GetDescription() { var expected = new ScopeResolverDescription("DHCPv6SimpleZyxelIESResolver", new[] { new ScopeResolverPropertyDescription("Index", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.UInt32), new ScopeResolverPropertyDescription("SlotId", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.UInt32), new ScopeResolverPropertyDescription("PortId", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.UInt32), new ScopeResolverPropertyDescription("DeviceMacAddress", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.ByteArray), }); var resolver = new DHCPv6SimpleZyxelIESResolver(); var actual = resolver.GetDescription(); Assert.Equal(expected, actual); }
public void ApplyValues() { Random random = new Random(); UInt16 index = (UInt16)random.Next(0, 10); UInt16 slotId = (UInt16)random.Next(0, 10); UInt16 portId = (UInt16)random.Next(0, 10); Byte[] macAddress = random.NextBytes(6); String macAddressInput = ByteHelper.ToString(macAddress, false); Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict); serializerMock.Setup(x => x.Deserialze <UInt16>(index.ToString())).Returns(index).Verifiable(); serializerMock.Setup(x => x.Deserialze <UInt16>(slotId.ToString())).Returns(slotId).Verifiable(); serializerMock.Setup(x => x.Deserialze <UInt16>(portId.ToString())).Returns(portId).Verifiable(); serializerMock.Setup(x => x.Deserialze <String>(macAddressInput)).Returns(macAddressInput).Verifiable(); var resolver = new DHCPv6SimpleZyxelIESResolver(); resolver.ApplyValues(new Dictionary <String, String> { { "Index", index.ToString() }, { "SlotId", slotId.ToString() }, { "PortId", portId.ToString() }, { "DeviceMacAddress", macAddressInput }, }, serializerMock.Object); Assert.Equal(index, resolver.Index); Assert.Equal(slotId, resolver.SlotId); Assert.Equal(portId, resolver.PortId); Assert.Equal(macAddress, resolver.DeviceMacAddress); serializerMock.Verify(); Dictionary <String, String> expectedValues = new Dictionary <string, string> { { "Index", index.ToString() }, { "SlotId", slotId.ToString() }, { "PortId", portId.ToString() }, { "DeviceMacAddress", macAddressInput }, }; Assert.Equal(expectedValues.ToArray(), resolver.GetValues().ToArray()); Assert.Equal(expectedValues, resolver.GetValues(), new NonStrictDictionaryComparer <String, String>()); }
public void ArePropertiesAndValuesValid(String index, String slotId, String portId, String deviceMacAddress, Boolean shouldBeValid) { Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict); serializerMock.Setup(x => x.Deserialze <String>(index)).Returns(index).Verifiable(); serializerMock.Setup(x => x.Deserialze <String>(slotId)).Returns(slotId).Verifiable(); serializerMock.Setup(x => x.Deserialze <String>(portId)).Returns(portId).Verifiable(); serializerMock.Setup(x => x.Deserialze <String>(deviceMacAddress)).Returns(deviceMacAddress).Verifiable(); var resolver = new DHCPv6SimpleZyxelIESResolver(); Boolean actual = resolver.ArePropertiesAndValuesValid(new Dictionary <String, String> { { "Index", index }, { "SlotId", slotId }, { "PortId", portId }, { "DeviceMacAddress", deviceMacAddress }, }, serializerMock.Object); Assert.Equal(shouldBeValid, actual); }
public void PacketMeetsCondition_False_NotRelay() { Random random = new Random(); Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict); DHCPv6SimpleZyxelIESResolver resolver = new DHCPv6SimpleZyxelIESResolver(); IPv6HeaderInformation headerInformation = new IPv6HeaderInformation(IPv6Address.FromString("fe80::1"), IPv6Address.FromString("fe80::2")); var packetOptions = new List <DHCPv6PacketOption> { new DHCPv6PacketTrueOption(DHCPv6PacketOptionTypes.RapitCommit), }; DHCPv6Packet packet = DHCPv6Packet.AsOuter(headerInformation, random.NextUInt16(), DHCPv6PacketTypes.Solicit, packetOptions); Boolean result = resolver.PacketMeetsCondition(packet); Assert.False(result); serializerMock.Verify(); }
public void HasUniqueIdentifier() { var resolver = new DHCPv6SimpleZyxelIESResolver(); Assert.True(resolver.HasUniqueIdentifier); }