コード例 #1
0
        protected static DHCPv4Lease CheckLease(
            Int32 index, Int32 expectedAmount, IPv4Address expectedAdress,
            Guid scopeId, DHCPv4RootScope rootScope, DateTime expectedCreationData, Boolean checkExpires = true,
            Byte[] uniqueIdentifier = null, Boolean shouldBePending = true)
        {
            DHCPv4Scope scope  = rootScope.GetScopeById(scopeId);
            var         leases = scope.Leases.GetAllLeases();

            Assert.Equal(expectedAmount, leases.Count());

            DHCPv4Lease lease = leases.ElementAt(index);

            Assert.NotNull(lease);
            Assert.Equal(expectedAdress, lease.Address);
            if (checkExpires == true)
            {
                Int32 expiresInMinutes = (Int32)(lease.End - DateTime.UtcNow).TotalMinutes;
                Assert.True(expiresInMinutes >= 60 * 24 - 4 && expiresInMinutes <= 60 * 24);
            }

            Assert.True((expectedCreationData - lease.Start).TotalMinutes < 2);
            Assert.Equal(shouldBePending, lease.IsPending());
            if (uniqueIdentifier == null)
            {
                Assert.Empty(lease.UniqueIdentifier);
            }
            else
            {
                Assert.NotNull(lease.UniqueIdentifier);
                Assert.Equal(uniqueIdentifier, lease.UniqueIdentifier);
            }

            return(lease);
        }
コード例 #2
0
        public void DHCPv4Lease_IsPending()
        {
            Random          random    = new Random();
            DHCPv4RootScope rootScope = GetRootScope();

            Guid scopeId = Guid.NewGuid();

            List <DomainEvent> events = new List <DomainEvent>
            {
                new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
                {
                    Id = scopeId,
                }),
            };

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

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

                events.Add(new DHCPv4LeaseCreatedEvent
                {
                    ScopeId        = scopeId,
                    EntityId       = leaseId,
                    Address        = random.GetIPv4Address(),
                    ClientIdenfier = DHCPv4ClientIdentifier.FromHwAddress(random.NextBytes(6)).GetBytes(),
                });

                Boolean addressIsInPending = random.NextDouble() > 0.5;
                if (addressIsInPending == false)
                {
                    events.Add(new DHCPv4LeaseActivatedEvent(leaseId));
                }

                expectedResults.Add(leaseId, addressIsInPending);
            }

            rootScope.Load(events);

            DHCPv4Scope scope = rootScope.GetRootScopes().First();

            foreach (var item in expectedResults)
            {
                DHCPv4Lease lease  = scope.Leases.GetLeaseById(item.Key);
                Boolean     actual = lease.IsPending();
                Assert.Equal(item.Value, actual);
            }
        }