protected static DHCPv6Lease CheckLease( Int32 index, Int32 expectedAmount, IPv6Address expectedAdress, Guid scopeId, DHCPv6RootScope rootScope, DateTime expectedCreationData, DUID clientDuid, UInt32 iaId, Boolean shouldBePending, Boolean shouldHavePrefix, Byte[] uniqueIdentifier = null, Boolean checkExpire = true) { DHCPv6Scope scope = rootScope.GetScopeById(scopeId); var leases = scope.Leases.GetAllLeases(); Assert.Equal(expectedAmount, leases.Count()); DHCPv6Lease lease = leases.ElementAt(index); Assert.NotNull(lease); Assert.Equal(expectedAdress, lease.Address); if (checkExpire == 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); if (shouldBePending == true) { Assert.True(lease.IsPending()); } else { Assert.True(lease.IsActive()); } Assert.Equal(clientDuid, lease.ClientDUID); Assert.Equal(iaId, lease.IdentityAssocicationId); if (uniqueIdentifier == null) { Assert.Empty(lease.UniqueIdentifier); } else { Assert.NotNull(lease.UniqueIdentifier); Assert.Equal(uniqueIdentifier, lease.UniqueIdentifier); } if (shouldHavePrefix == false) { Assert.Equal(DHCPv6PrefixDelegation.None, lease.PrefixDelegation); } return(lease); }
public void IsPending() { Random random = new Random(); DHCPv6RootScope rootScope = GetRootScope(); Guid scopeId = Guid.NewGuid(); List <DomainEvent> events = new List <DomainEvent> { new DHCPv6ScopeAddedEvent(new DHCPv6ScopeCreateInstruction { 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 DHCPv6LeaseCreatedEvent { ScopeId = scopeId, EntityId = leaseId, Address = random.GetIPv6Address(), ClientIdentifier = new UUIDDUID(random.NextGuid()), }); Boolean addressIsInPending = random.NextDouble() > 0.5; if (addressIsInPending == false) { events.Add(new DHCPv6LeaseActivatedEvent(leaseId)); } expectedResults.Add(leaseId, addressIsInPending); } rootScope.Load(events); DHCPv6Scope scope = rootScope.GetRootScopes().First(); foreach (var item in expectedResults) { DHCPv6Lease lease = scope.Leases.GetLeaseById(item.Key); Boolean actual = lease.IsPending(); Assert.Equal(item.Value, actual); } }
protected static DHCPv6Lease CheckLeaseForPrefix( Int32 index, Int32 expectedAmount, IPv6Address minAddress, IPv6Address maxAddress, Guid scopeId, DHCPv6RootScope rootScope, DUID clientDuid, UInt32 prefixIaId, Byte prefixLength, Boolean shouldBePending, Byte[] uniqueIdentifier = null) { DHCPv6Scope scope = rootScope.GetScopeById(scopeId); var leases = scope.Leases.GetAllLeases(); Assert.Equal(expectedAmount, leases.Count()); DHCPv6Lease lease = leases.ElementAt(index); Assert.Equal(clientDuid, lease.ClientDUID); Assert.NotNull(lease); Assert.NotEqual(DHCPv6PrefixDelegation.None, lease.PrefixDelegation); Assert.Equal(prefixIaId, lease.PrefixDelegation.IdentityAssociation); Assert.Equal(prefixLength, lease.PrefixDelegation.Mask.Identifier); Assert.True((new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength))).IsIPv6AdressANetworkAddress(lease.PrefixDelegation.NetworkAddress)); Assert.True(lease.PrefixDelegation.NetworkAddress.IsBetween(minAddress, maxAddress)); if (shouldBePending == true) { Assert.True(lease.IsPending()); } else { Assert.True(lease.IsActive()); } if (uniqueIdentifier == null) { Assert.Empty(lease.UniqueIdentifier); } else { Assert.NotNull(lease.UniqueIdentifier); Assert.Equal(uniqueIdentifier, lease.UniqueIdentifier); } return(lease); }