Ejemplo n.º 1
0
        public void GetUniqueIdentifier()
        {
            Random random   = new Random();
            var    resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));

            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]);
            }
        }
Ejemplo n.º 2
0
        private static (UInt16 slotId, UInt16 portId) GetValidResolver(Random random, UInt16 index, out Guid deviceId, out Mock <ISerializer> serializerMock, out Mock <IDeviceService> deviceServiceMock, out DeviceBasedDHCPv6SimpleZyxelIESResolver resolver)
        {
            UInt16 slotId = (UInt16)random.Next(0, 10);
            UInt16 portId = (UInt16)random.Next(0, 10);

            Guid realDeviceId = random.NextGuid();

            deviceId = realDeviceId;

            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 <Guid>(realDeviceId.ToString())).Returns(deviceId).Verifiable();

            deviceServiceMock = new Mock <IDeviceService>(MockBehavior.Strict);

            resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(deviceServiceMock.Object);
            resolver.ApplyValues(new Dictionary <String, String> {
                { "Index", index.ToString() },
                { "SlotId", slotId.ToString() },
                { "PortId", portId.ToString() },
                { "DeviceId", realDeviceId.ToString() },
            }, serializerMock.Object);

            serializerMock.Verify();

            return(slotId, portId);
        }
Ejemplo n.º 3
0
        public void ArePropertiesAndValuesValid_KeyIsMissing()
        {
            var input = new[] {
                new  Dictionary <String, String> {
                    { "Index1", "0" },
                    { "SlotId", "0" },
                    { "PortId", "0" },
                    { "DeviceId", "0" },
                },
                new  Dictionary <String, String> {
                    { "Index", "0" },
                    { "SlotId1", "0" },
                    { "PortId", "0" },
                    { "DeviceId", "0" },
                },
                new  Dictionary <String, String> {
                    { "Index", "0" },
                    { "SlotId", "0" },
                    { "PortId1", "0" },
                    { "DeviceId", "0" },
                },
                new  Dictionary <String, String> {
                    { "Index", "0" },
                    { "SlotId", "0" },
                    { "PortId", "0" },
                    { "DeviceId1", "0" },
                },
                new  Dictionary <String, String> {
                    { "SlotId", "0" },
                    { "PortId", "0" },
                    { "DeviceId", "0" },
                },
                new  Dictionary <String, String> {
                    { "Index", "0" },
                    { "PortId", "0" },
                    { "DeviceId", "0" },
                },
                new  Dictionary <String, String> {
                    { "Index", "0" },
                    { "SlotId", "0" },
                    { "DeviceId", "0" },
                },
                new  Dictionary <String, String> {
                    { "Index", "0" },
                    { "SlotId", "0" },
                    { "PortId", "0" },
                },
            };

            var resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));

            foreach (var item in input)
            {
                Boolean actual = resolver.ArePropertiesAndValuesValid(item, Mock.Of <ISerializer>(MockBehavior.Strict));
                Assert.False(actual);
            }
        }
Ejemplo n.º 4
0
        public void GetDescription()
        {
            var expected = new ScopeResolverDescription("DeviceBasedDHCPv6SimpleZyxelIESResolver", new[] {
                new ScopeResolverPropertyDescription("Index", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.UInt32),
                new ScopeResolverPropertyDescription("SlotId", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.UInt32),
                new ScopeResolverPropertyDescription("PortId", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.UInt32),
                new ScopeResolverPropertyDescription("DeviceId", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.Device),
            });

            var resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));
            var actual   = resolver.GetDescription();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
        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);

            Guid deviceId = random.NextGuid();

            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 <Guid>(deviceId.ToString())).Returns(deviceId).Verifiable();

            var resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));

            resolver.ApplyValues(new Dictionary <String, String> {
                { "Index", index.ToString() },
                { "SlotId", slotId.ToString() },
                { "PortId", portId.ToString() },
                { "DeviceId", deviceId.ToString() },
            }, serializerMock.Object);

            Assert.Equal(index, resolver.Index);
            Assert.Equal(slotId, resolver.SlotId);
            Assert.Equal(portId, resolver.PortId);
            Assert.Equal(deviceId, resolver.DeviceId);

            serializerMock.Verify();

            Dictionary <String, String> expectedValues = new Dictionary <string, string>
            {
                { "Index", index.ToString() },
                { "SlotId", slotId.ToString() },
                { "PortId", portId.ToString() },
                { "DeviceId", deviceId.ToString() },
            };

            Assert.Equal(expectedValues.ToArray(), resolver.GetValues().ToArray());
            Assert.Equal(expectedValues, resolver.GetValues(), new NonStrictDictionaryComparer <String, String>());
        }
Ejemplo n.º 6
0
        public void ArePropertiesAndValuesValid(String index, String slotId, String portId, String deviceId, 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>(deviceId)).Returns(deviceId).Verifiable();

            var     resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));
            Boolean actual   = resolver.ArePropertiesAndValuesValid(new Dictionary <String, String> {
                { "Index", index },
                { "SlotId", slotId },
                { "PortId", portId },
                { "DeviceId", deviceId },
            }, serializerMock.Object);

            Assert.Equal(shouldBeValid, actual);
        }
Ejemplo n.º 7
0
        public void PacketMeetsCondition_False_NotRelay()
        {
            Random random = new Random();

            Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict);
            DeviceBasedDHCPv6SimpleZyxelIESResolver resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));

            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();
        }
Ejemplo n.º 8
0
        public void HasUniqueIdentifier()
        {
            var resolver = new DeviceBasedDHCPv6SimpleZyxelIESResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));

            Assert.True(resolver.HasUniqueIdentifier);
        }