Пример #1
0
        public async Task Handle_InterfaceNotFound()
        {
            Random random        = new Random();
            String interfaceName = random.GetAlphanumericString();

            var possibleListeners = GetPossibleListeners();

            var selectedListener = possibleListeners.ElementAt(1);
            var command          = new CreateDHCPv4InterfaceListenerCommand(
                selectedListener.PhysicalInterfaceId,
                random.GetIPv4Address().ToString(), interfaceName);

            Mock <IDHCPv4InterfaceEngine> interfaceEngineMock = new Mock <IDHCPv4InterfaceEngine>(MockBehavior.Strict);

            interfaceEngineMock.Setup(x => x.GetPossibleListeners()).Returns(possibleListeners).Verifiable();

            var commandHandler = new CreateDHCPv4InterfaceListenerCommandHandler(
                interfaceEngineMock.Object, Mock.Of <IDHCPv4StorageEngine>(MockBehavior.Strict),
                Mock.Of <ILogger <CreateDHCPv4InterfaceListenerCommandHandler> >());

            Guid?result = await commandHandler.Handle(command, CancellationToken.None);

            Assert.False(result.HasValue);

            interfaceEngineMock.Verify();
        }
Пример #2
0
        public async Task Handle_Failed_StorageEngine()
        {
            Random random        = new Random();
            String interfaceName = random.GetAlphanumericString();

            var possibleListeners = GetPossibleListeners();

            var selectedListener = possibleListeners.ElementAt(1);
            var command          = new CreateDHCPv4InterfaceListenerCommand(
                selectedListener.PhysicalInterfaceId,
                selectedListener.Address.ToString(), interfaceName);

            Mock <IDHCPv4InterfaceEngine> interfaceEngineMock = new Mock <IDHCPv4InterfaceEngine>(MockBehavior.Strict);

            interfaceEngineMock.Setup(x => x.GetPossibleListeners()).Returns(possibleListeners).Verifiable();
            interfaceEngineMock.Setup(x => x.GetActiveListeners()).ReturnsAsync(possibleListeners.Take(1)).Verifiable();

            Mock <IDHCPv4StorageEngine> storageEngineMock = new Mock <IDHCPv4StorageEngine>(MockBehavior.Strict);

            storageEngineMock.Setup(x => x.Save(It.Is <DHCPv4Listener>(y =>
                                                                       y.Name == interfaceName && y.PhysicalInterfaceId == command.NicId &&
                                                                       y.Address == IPv4Address.FromString(command.IPv4Addres)
                                                                       ))).ReturnsAsync(false).Verifiable();

            var commandHandler = new CreateDHCPv4InterfaceListenerCommandHandler(
                interfaceEngineMock.Object, storageEngineMock.Object,
                Mock.Of <ILogger <CreateDHCPv4InterfaceListenerCommandHandler> >());

            Guid?result = await commandHandler.Handle(command, CancellationToken.None);

            Assert.False(result.HasValue);

            interfaceEngineMock.Verify();
            storageEngineMock.Verify();
        }