예제 #1
0
        public void ApplyValues()
        {
            Random rand = new Random();

            Guid deviceId = rand.NextGuid();

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

            serializerMock.Setup(x => x.Deserialze <Guid>(deviceId.ToString())).Returns(deviceId).Verifiable();

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

            resolver.ApplyValues(new Dictionary <String, String> {
                { "DeviceId", deviceId.ToString() },
            }, serializerMock.Object);

            Assert.Equal(deviceId, resolver.DeviceId);
            serializerMock.Verify();

            var values = resolver.GetValues();

            Dictionary <String, String> expectedValues = new Dictionary <string, string>
            {
                { "DeviceId", deviceId.ToString() }
            };

            Assert.Equal(expectedValues.ToArray(), values.ToArray());
        }
예제 #2
0
        public void GetDescription()
        {
            var expected = new ScopeResolverDescription("DeviceBasedDHCPv6ClientDUIDResolver", new[] {
                new ScopeResolverPropertyDescription("DeviceId", ScopeResolverPropertyDescription.ScopeResolverPropertyValueTypes.Device),
            });

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

            Assert.Equal(expected, actual);
        }
예제 #3
0
        public void ArePropertiesAndValuesValid(String deviceId, Boolean shouldBeValid)
        {
            Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict);

            serializerMock.Setup(x => x.Deserialze <String>(deviceId)).Returns(deviceId);

            var     resolver = new DeviceBasedDHCPv6ClientDUIDResolver(Mock.Of <IDeviceService>(MockBehavior.Strict));
            Boolean actual   = resolver.ArePropertiesAndValuesValid(new Dictionary <String, String> {
                { "DeviceId", deviceId },
            }, serializerMock.Object);

            Assert.Equal(shouldBeValid, actual);

            serializerMock.Verify();
        }
예제 #4
0
        public void ArePropertiesAndValuesValid_KeyIsMissing()
        {
            var input = new[] {
                new  Dictionary <String, String> {
                    { "DeviceId2", "someVaue" }
                },
            };

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

            foreach (var item in input)
            {
                Boolean actual = resolver.ArePropertiesAndValuesValid(item, Mock.Of <ISerializer>(MockBehavior.Strict));
                Assert.False(actual);
            }
        }
예제 #5
0
        public void GetUniqueIdentifier()
        {
            LinkLayerAddressDUID duid = new LinkLayerAddressDUID(
                LinkLayerAddressDUID.DUIDLinkLayerTypes.Ethernet,
                new Byte[] { 0x5c, 0xa6, 0x2d, 0xd9, 0x88, 0x00 });

            Random random = new Random();

            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, IPv6Address.FromString("2004::1"), IPv6Address.FromString("fe80::1"), new DHCPv6PacketOption[]
            {
            }, DHCPv6Packet.AsInner(random.NextUInt16(), DHCPv6PacketTypes.Solicit, new[] { new DHCPv6PacketIdentifierOption(DHCPv6PacketOptionTypes.ClientIdentifier, duid) })));

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

            Assert.Equal(duid.GetAsByteStream(), resolver.GetUniqueIdentifier(packet));
        }
예제 #6
0
        public void PacketMeetsCondition(Boolean shouldMeetCondition)
        {
            Random random = new Random();

            Guid deviceId = random.NextGuid();

            LinkLayerAddressDUID duid = new LinkLayerAddressDUID(
                LinkLayerAddressDUID.DUIDLinkLayerTypes.Ethernet,
                new Byte[] { 0x5c, 0xa6, 0x2d, 0xd9, 0x88, 0x00 });

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

            serializerMock.Setup(x => x.Deserialze <Guid>(deviceId.ToString())).Returns(deviceId).Verifiable();

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

            deviceServiceMock.Setup(x => x.GetDuidFromDevice(deviceId)).Returns(duid).Verifiable();

            var resolver = new DeviceBasedDHCPv6ClientDUIDResolver(deviceServiceMock.Object);

            resolver.ApplyValues(new Dictionary <String, String> {
                { "DeviceId", deviceId.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, IPv6Address.FromString("2004::1"), IPv6Address.FromString("fe80::1"), new DHCPv6PacketOption[]
            {
            }, DHCPv6Packet.AsInner(random.NextUInt16(), DHCPv6PacketTypes.Solicit, new[] { new DHCPv6PacketIdentifierOption(DHCPv6PacketOptionTypes.ClientIdentifier, shouldMeetCondition == true ? (DUID)duid : new UUIDDUID(random.NextGuid())) })));

            Boolean result = resolver.PacketMeetsCondition(packet);

            Assert.Equal(shouldMeetCondition, result);

            serializerMock.Verify();
            deviceServiceMock.Verify();
        }
예제 #7
0
        public void HasUniqueIdentifier()
        {
            var resolver = new DeviceBasedDHCPv6ClientDUIDResolver(Mock.Of <IDeviceService>());

            Assert.True(resolver.HasUniqueIdentifier);
        }