Ejemplo n.º 1
0
        public void DHCPv4RelayAgentResolver_PacketMeetsConditions()
        {
            Random             random    = new Random();
            List <IPv4Address> addresses = random.GetIPv4Addresses();

            String serializedValues = System.Text.Json.JsonSerializer.Serialize(addresses.Select(x => x.ToString()));

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

            serializer.Setup(x => x.Deserialze <IEnumerable <String> >(serializedValues)).Returns(addresses.Select(x => x.ToString()));

            DHCPv4RelayAgentResolver    resolver = new DHCPv4RelayAgentResolver();
            Dictionary <String, String> values   = new Dictionary <String, String>()
            {
                { nameof(DHCPv4RelayAgentResolver.AgentAddresses), serializedValues }
            };

            resolver.ApplyValues(values, serializer.Object);

            foreach (IPv4Address item in addresses)
            {
                Boolean shouldPass = false;

                IPv4Address gwAddress = IPv4Address.Empty;
                if (random.NextDouble() > 0.5)
                {
                    gwAddress  = item;
                    shouldPass = true;
                }
                else
                {
                    if (random.NextDouble() > 0.5)
                    {
                        gwAddress = random.GetIPv4Address();
                    }
                }

                DHCPv4Packet packet = new DHCPv4Packet(
                    new IPv4HeaderInformation(random.GetIPv4Address(), random.GetIPv4Address()),
                    random.NextBytes(6),
                    (UInt32)random.Next(),
                    IPv4Address.Empty,
                    gwAddress,
                    IPv4Address.Empty
                    );

                Boolean actual = resolver.PacketMeetsCondition(packet);
                Assert.Equal(shouldPass, actual);
            }
        }
Ejemplo n.º 2
0
        public void DHCPv4RelayAgentResolver_ApplyValues()
        {
            Random             random           = new Random();
            List <IPv4Address> agentAddresses   = random.GetIPv4Addresses();
            String             serializedValues = System.Text.Json.JsonSerializer.Serialize(agentAddresses.Select(x => x.ToString()));

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

            mock.Setup(x => x.Deserialze <IEnumerable <String> >(serializedValues)).Returns(agentAddresses.Select(x => x.ToString()));

            DHCPv4RelayAgentResolver resolver = new DHCPv4RelayAgentResolver();

            var input = new Dictionary <string, string>()
            {
                { nameof(DHCPv4RelayAgentResolver.AgentAddresses), serializedValues },
            };

            resolver.ApplyValues(input, mock.Object);
            Assert.Equal(agentAddresses, resolver.AgentAddresses);
        }