示例#1
0
        public void DHCPv6LeaseExpiredEvent()
        {
            Random random = new Random();

            DHCPv6LeaseExpiredEvent expected = new DHCPv6LeaseExpiredEvent
            {
                EntityId  = random.NextGuid(),
                ScopeId   = random.NextGuid(),
                Timestamp = DateTime.UtcNow,
            };

            var actual = SerializeAndDeserialze(expected);

            Assert.Equal(expected.EntityId, actual.EntityId);
            Assert.Equal(expected.ScopeId, actual.ScopeId);
            Assert.Equal(expected.Timestamp, actual.Timestamp);
        }
示例#2
0
        public void CanBeExtended()
        {
            Random          random    = new Random(1345);
            DHCPv6RootScope rootScope = GetRootScope();

            Guid scopeId = Guid.NewGuid();

            rootScope.Load(new[] {
                new DHCPv6ScopeAddedEvent(new DHCPv6ScopeCreateInstruction
                {
                    Id = scopeId,
                }),
            });

            Int32 leaseAmount = random.Next(10, 30);
            Dictionary <DHCPv6Lease, Boolean> expectedResults = new();

            for (int i = 0; i < leaseAmount; i++)
            {
                Guid leaseId = Guid.NewGuid();

                rootScope.Load(new[] { new DHCPv6LeaseCreatedEvent
                                       {
                                           ScopeId          = scopeId,
                                           EntityId         = leaseId,
                                           Address          = random.GetIPv6Address(),
                                           ClientIdentifier = new UUIDDUID(random.NextGuid()),
                                       } });

                DHCPv6Lease lease = rootScope.GetRootScopes().First().Leases.GetLeaseById(leaseId);

                Boolean     shouldBeExtentable = random.NextBoolean();
                DomainEvent @event             = null;
                if (shouldBeExtentable == true)
                {
                    Int32 nextValue = random.Next(0, 4);
                    switch (nextValue)
                    {
                    case 0:
                        @event = new DHCPv6LeaseActivatedEvent(leaseId);
                        break;

                    case 1:
                        @event = new DHCPv6LeaseReleasedEvent(leaseId, false);
                        break;

                    case 2:
                        @event = new DHCPv6LeaseRenewedEvent(leaseId, DateTime.UtcNow.AddHours(3), TimeSpan.FromHours(1), TimeSpan.FromHours(2), false, false);
                        break;

                    case 3:
                        @event = new DHCPv6LeaseExpiredEvent(leaseId);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    Int32 nextValue = random.Next(0, 3);
                    switch (nextValue)
                    {
                    case 0:
                        @event = new DHCPv6LeaseCanceledEvent(leaseId);
                        break;

                    case 1:
                        @event = new DHCPv6LeaseRevokedEvent(leaseId);
                        break;

                    case 2:
                        @event = new DHCPv6AddressSuspendedEvent(leaseId, random.GetIPv6Address(), DateTime.UtcNow.AddHours(3));
                        break;

                    default:
                        break;
                    }
                }

                rootScope.Load(new[] { @event });

                expectedResults.Add(lease, shouldBeExtentable);
            }

            foreach (var item in expectedResults)
            {
                DHCPv6Lease lease  = item.Key;
                Boolean     actual = lease.CanBeExtended();
                Assert.Equal(item.Value, actual);
            }
        }