Esempio n. 1
0
        public void ApplyValues()
        {
            String ipAddress = "fe80::";

            IPv6Address address = IPv6Address.FromString(ipAddress);

            Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict);

            serializerMock.Setup(x => x.Deserialze <IPv6Address>(ipAddress)).Returns(address).Verifiable();

            var resolver = new DHCPv6RelayAgentResolver();

            resolver.ApplyValues(new Dictionary <String, String> {
                { "RelayAgentAddress", ipAddress },
            }, serializerMock.Object);

            Assert.Equal(address, resolver.RelayAgentAddress);

            serializerMock.Verify();

            Dictionary <String, String> expectedValues = new Dictionary <String, String>
            {
                { "RelayAgentAddress", ipAddress },
            };

            Assert.Equal(expectedValues.ToArray(), resolver.GetValues().ToArray());
        }
Esempio n. 2
0
        public void PacketMeetsCondition(Boolean shouldMeetCondition)
        {
            Random random = new Random();

            String ipAddress = "fe80::1";

            IPv6Address address = IPv6Address.FromString(ipAddress);

            Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict);

            serializerMock.Setup(x => x.Deserialze <IPv6Address>(ipAddress)).Returns(address).Verifiable();

            var resolver = new DHCPv6RelayAgentResolver();

            resolver.ApplyValues(new Dictionary <String, String> {
                { "RelayAgentAddress", ipAddress },
            }, 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, shouldMeetCondition == true ? IPv6Address.FromString(ipAddress) : 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(shouldMeetCondition, result);

            serializerMock.Verify();
        }