public void DHCPv6LeaseCreatedEvent() { Random random = new Random(); DHCPv6LeaseCreatedEvent expected = new DHCPv6LeaseCreatedEvent { EntityId = random.NextGuid(), ScopeId = random.NextGuid(), Timestamp = DateTime.UtcNow, Address = random.GetIPv6Address(), ClientIdentifier = new UUIDDUID(random.NextGuid()), IdentityAssocationId = random.NextUInt32(), StartedAt = DateTime.UtcNow, UniqueIdentiifer = random.NextBytes(20), ValidUntil = DateTime.UtcNow.AddDays(3) }; var actual = SerializeAndDeserialze(expected); Assert.Equal(expected.EntityId, actual.EntityId); Assert.Equal(expected.ScopeId, actual.ScopeId); Assert.Equal(expected.Timestamp, actual.Timestamp); Assert.Equal(expected.Address, actual.Address); Assert.Equal(expected.ClientIdentifier, actual.ClientIdentifier); Assert.Equal(expected.IdentityAssocationId, actual.IdentityAssocationId); Assert.Equal(expected.StartedAt, actual.StartedAt); Assert.Equal(expected.UniqueIdentiifer, actual.UniqueIdentiifer); Assert.Equal(expected.ValidUntil, actual.ValidUntil); }
protected static void CheckLeaseCreatedEvent( Int32 index, DUID clientDuid, UInt32 iaId, Guid scopeId, DHCPv6RootScope rootScope, IPv6Address expectedAdress, DHCPv6Lease lease, Byte[] uniqueIdentifier = null, Guid?ancestorId = null, Boolean checkLeaseTimes = true ) { IEnumerable <DomainEvent> changes = rootScope.GetChanges(); Assert.NotNull(changes); Assert.IsAssignableFrom <DHCPv6LeaseCreatedEvent>(changes.ElementAt(index)); DHCPv6LeaseCreatedEvent createdEvent = (DHCPv6LeaseCreatedEvent)changes.ElementAt(index); Assert.NotNull(createdEvent); Assert.Equal(scopeId, createdEvent.ScopeId); Assert.Equal(expectedAdress, createdEvent.Address); Assert.Equal(clientDuid, createdEvent.ClientIdentifier); Assert.Equal(iaId, createdEvent.IdentityAssocationId); Assert.Equal(lease.Id, createdEvent.EntityId); Assert.Equal(ancestorId, createdEvent.AncestorId); if (uniqueIdentifier == null) { Assert.Null(createdEvent.UniqueIdentiifer); } else { Assert.Equal(uniqueIdentifier, createdEvent.UniqueIdentiifer); } Assert.Equal(lease.Start, createdEvent.StartedAt); Assert.Equal(lease.End, createdEvent.ValidUntil); var addressProperties = rootScope.GetScopeById(scopeId).AddressRelatedProperties; if (checkLeaseTimes == true) { Assert.Equal(addressProperties.T1.Value * addressProperties.ValidLeaseTime.Value, createdEvent.RenewalTime); Assert.Equal(addressProperties.T2.Value * addressProperties.ValidLeaseTime.Value, createdEvent.PreferredLifetime); } if (lease.PrefixDelegation == DHCPv6PrefixDelegation.None) { Assert.Equal(IPv6Address.Empty, createdEvent.DelegatedNetworkAddress); Assert.Equal(0, createdEvent.PrefixLength); Assert.False(createdEvent.HasPrefixDelegation); } }