public void PacketMeetsCondition(Boolean isInSubnet) { Random random = new Random(); String ipAddress = "fe80::0"; Byte subnetmaskLength = 32; IPv6Address address = IPv6Address.FromString(ipAddress); IPv6SubnetMask mask = new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(subnetmaskLength)); Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict); serializerMock.Setup(x => x.Deserialze <IPv6Address>(ipAddress)).Returns(address).Verifiable(); serializerMock.Setup(x => x.Deserialze <IPv6SubnetMask>(subnetmaskLength.ToString())).Returns(mask).Verifiable(); DHCPv6RelayAgentSubnetResolver resolver = new DHCPv6RelayAgentSubnetResolver(); resolver.ApplyValues(new Dictionary <String, String> { { "NetworkAddress", ipAddress }, { "SubnetMask", subnetmaskLength.ToString() }, }, serializerMock.Object); var packet = DHCPv6RelayPacket.AsOuterRelay(new IPv6HeaderInformation(IPv6Address.FromString("fe80::1"), IPv6Address.FromString("fe80::2")), true, 1, random.GetIPv6Address(), random.GetIPv6Address(), Array.Empty <DHCPv6PacketOption>(), DHCPv6RelayPacket.AsInnerRelay( true, 0, isInSubnet == true ? IPv6Address.FromString("fe80::1") : IPv6Address.FromString("2004::1"), IPv6Address.FromString("fe80::1"), new DHCPv6PacketOption[] { }, DHCPv6Packet.AsInner(random.NextUInt16(), DHCPv6PacketTypes.Solicit, Array.Empty <DHCPv6PacketOption>()))); Boolean result = resolver.PacketMeetsCondition(packet); Assert.Equal(isInSubnet, result); serializerMock.Verify(); }
public void ApplyValues() { String ipAddress = "fe80::"; Byte subnetmaskLength = 32; IPv6Address address = IPv6Address.FromString(ipAddress); IPv6SubnetMask mask = new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(subnetmaskLength)); Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict); serializerMock.Setup(x => x.Deserialze <IPv6Address>(ipAddress)).Returns(address).Verifiable(); serializerMock.Setup(x => x.Deserialze <IPv6SubnetMask>(subnetmaskLength.ToString())).Returns(mask).Verifiable(); var resolver = new DHCPv6RelayAgentSubnetResolver(); resolver.ApplyValues(new Dictionary <String, String> { { "NetworkAddress", ipAddress }, { "SubnetMask", subnetmaskLength.ToString() }, }, serializerMock.Object); Assert.Equal(address, resolver.NetworkAddress); Assert.Equal(mask, resolver.SubnetMask); serializerMock.Verify(); var expectedValues = new Dictionary <String, String> { { "NetworkAddress", ipAddress }, { "SubnetMask", subnetmaskLength.ToString() }, }; Assert.Equal(expectedValues.ToArray(), resolver.GetValues().ToArray()); }
public void GetDescription() { var expected = new ScopeResolverDescription("DHCPv6RelayAgentSubnetResolver", new[] { new ScopeResolverPropertyDescription("NetworkAddress", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.IPv6NetworkAddress), new ScopeResolverPropertyDescription("SubnetMask", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.IPv6Subnet), }); var resolver = new DHCPv6RelayAgentSubnetResolver(); var actual = resolver.GetDescription(); Assert.Equal(expected, actual); }
public void ArePropertiesAndValuesValid_KeyIsMissing() { var input = new[] { new Dictionary <String, String> { { "NetworkAddress", "someVaue" }, { "SubnetMask2", "ohter" } }, new Dictionary <String, String> { { "SubnetMask", "someVaue" }, { "NetworkAddress2", "ohter" } }, }; var resolver = new DHCPv6RelayAgentSubnetResolver(); foreach (var item in input) { Boolean actual = resolver.ArePropertiesAndValuesValid(item, Mock.Of <ISerializer>(MockBehavior.Strict)); Assert.False(actual); } }
public void ArePropertiesAndValuesValid(String ipAddress, Byte subnetmaskLength, Boolean shouldBeValid) { IPv6Address address = IPv6Address.FromString(ipAddress); IPv6SubnetMask mask = new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(subnetmaskLength)); Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict); serializerMock.Setup(x => x.Deserialze <IPv6Address>(ipAddress)).Returns(address).Verifiable(); serializerMock.Setup(x => x.Deserialze <IPv6SubnetMask>(subnetmaskLength.ToString())).Returns(mask).Verifiable(); var resolver = new DHCPv6RelayAgentSubnetResolver(); Boolean actual = resolver.ArePropertiesAndValuesValid(new Dictionary <String, String> { { "NetworkAddress", ipAddress }, { "SubnetMask", subnetmaskLength.ToString() }, }, serializerMock.Object); Assert.Equal(shouldBeValid, actual); serializerMock.Verify(); }
public void GetUniqueIdentifier() { var resolver = new DHCPv6RelayAgentSubnetResolver(); Assert.ThrowsAny <Exception>(() => resolver.GetUniqueIdentifier(null)); }
public void HasUniqueIdentifier() { var resolver = new DHCPv6RelayAgentSubnetResolver(); Assert.False(resolver.HasUniqueIdentifier); }