Exemplo n.º 1
0
        public async Task <IEnumerable <DHCPv6Listener> > GetDHCPv6Listener()
        {
            var result = await DHCPv6Interfaces.AsQueryable()
                         .OrderBy(x => x.Name).ToListAsync();

            List <DHCPv6Listener> listeners = new List <DHCPv6Listener>(result.Count);

            foreach (var item in result)
            {
                DHCPv6Listener listener = new DHCPv6Listener();
                listener.Load(new DomainEvent[]
                {
                    new DHCPv6ListenerCreatedEvent {
                        Id          = item.Id,
                        Name        = item.Name,
                        InterfaceId = item.InterfaceId,
                        Address     = item.IPv6Address,
                    }
                });

                listeners.Add(listener);
            }

            return(listeners);
        }
Exemplo n.º 2
0
        public void Delete()
        {
            Random random = new Random();
            Guid   id     = random.NextGuid();

            DHCPv6Listener listener = new DHCPv6Listener();

            listener.Load(new DomainEvent[] {
                new DHCPv6ListenerCreatedEvent
                {
                    Id      = id,
                    Address = random.GetIPv6Address().ToString(),
                }
            });

            Assert.False(listener.IsDeleted);

            listener.Delete();

            Assert.True(listener.IsDeleted);

            var @event = GetFirstEvent <DHCPListenerDeletedEvent>(listener);

            Assert.Equal(id, @event.Id);
        }
Exemplo n.º 3
0
        public async Task Handle_Failed_NotSaved()
        {
            Random random = new Random();
            Guid   id     = random.NextGuid();

            DHCPv6Listener listener = new DHCPv6Listener();

            listener.Load(new DomainEvent[] {
                new DHCPv6ListenerCreatedEvent
                {
                    Id      = id,
                    Address = random.GetIPv6Address().ToString(),
                }
            });

            var command = new DeleteDHCPv6InterfaceListenerCommand(id);

            Mock <IDHCPv6StorageEngine> storageMock = new Mock <IDHCPv6StorageEngine>(MockBehavior.Strict);

            storageMock.Setup(x => x.CheckIfAggrerootExists <DHCPv6Listener>(id)).ReturnsAsync(true).Verifiable();
            storageMock.Setup(x => x.GetAggregateRoot <DHCPv6Listener>(id)).ReturnsAsync(listener).Verifiable();
            storageMock.Setup(x => x.Save(listener)).ReturnsAsync(false).Verifiable();

            var handler = new DeleteDHCPv6InterfaceListenerCommandHandler(
                Mock.Of <IDHCPv6InterfaceEngine>(MockBehavior.Strict), storageMock.Object, Mock.Of <ILogger <DeleteDHCPv6InterfaceListenerCommandHandler> >());

            Boolean actual = await handler.Handle(command, CancellationToken.None);

            Assert.False(actual);

            storageMock.Verify();
        }