public void DeregisterCommandHandler_CommandIsNull_ThrowsArgumentNullException()
        {
            var keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.DeregisterCommandHandler(null);

            invoke.Should().Throw <ArgumentNullException>();
        }
        public void SendCommand_CommandIsToggleWindow_ShouldNotThrow()
        {
            var command = nameof(Command.ToggleWindow);
            var keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.SendCommand(command);

            invoke.Should().NotThrow();
        }
        public void SendCommand_CommandIsNotRegisted_KeyNotFoundExceptionIsThrown()
        {
            var command = ((Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
            var keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.SendCommand(command);

            invoke.Should().Throw <KeyNotFoundException>();
        }
        public void DeregisterCommandHandler_CommandNotRegistered_ShouldNotThrow()
        {
            var command = ((Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
            var keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.DeregisterCommandHandler(command);

            invoke.Should().NotThrow();
        }
Ejemplo n.º 5
0
        public void SendCommand_CommandIsNotRegisted_KeyNotFoundExceptionIsThrown()
        {
            var command = _fixture.Create <Command>();
            var keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.SendCommand(command);

            invoke.Should().Throw <KeyNotFoundException>();
        }
        public void RegisterCommandHandler_HandlerIsNull_ThrowsArgumentNullException()
        {
            var    command = ((Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
            Action handler = null;
            var    keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.RegisterCommandHandler(command, handler);

            invoke.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("handler");
        }
Ejemplo n.º 7
0
        public void RegisterCommandHandler_HandlerIsNull_ThrowsArgumentNullException()
        {
            var    command = _fixture.Create <Command>();
            Action handler = null;
            var    keyboardCommandService = new KeyboardCommandService();

            Action invoke = () => keyboardCommandService.RegisterCommandHandler(command, handler);

            invoke.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("handler");
        }
        public void SendCommand_CommandIsRegistered_HandlerGetsInvoked()
        {
            var command                = ((Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
            var handlerCalled          = false;
            var keyboardCommandService = new KeyboardCommandService();

            keyboardCommandService.RegisterCommandHandler(command, () => handlerCalled = true);

            keyboardCommandService.SendCommand(command);

            handlerCalled.Should().BeTrue();
        }
        public void RegisterCommandHandler_CommandAlreadyRegisted_ThrowsInvalidOperationException()
        {
            var command = ((Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
            var handler = _fixture.Create <Action>();
            var keyboardCommandService = new KeyboardCommandService();

            keyboardCommandService.RegisterCommandHandler(command, handler);

            Action invoke = () => keyboardCommandService.RegisterCommandHandler(command, handler);

            invoke.Should().Throw <InvalidOperationException>();
        }
        public void DeregisterCommandHandler_CommandRegistered_HandlerGetsRemoved()
        {
            var command = ((Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length)).ToString();
            var handler = _fixture.Create <Action>();
            var keyboardCommandService = new KeyboardCommandService();

            keyboardCommandService.RegisterCommandHandler(command, handler);

            Action invoke = () => keyboardCommandService.DeregisterCommandHandler(command);

            invoke.Should().NotThrow();
        }
Ejemplo n.º 11
0
        public void SendCommand_CommandIsRegistered_HandlerGetsInvoked()
        {
            var command                = _fixture.Create <Command>();
            var handlerCalled          = false;
            var keyboardCommandService = new KeyboardCommandService();

            keyboardCommandService.RegisterCommandHandler(command, () => handlerCalled = true);

            keyboardCommandService.SendCommand(command);

            handlerCalled.Should().BeTrue();
        }
Ejemplo n.º 12
0
        public void RegisterCommandHandler_CommandAlreadyRegisted_ThrowsInvalidOperationException()
        {
            var command = _fixture.Create <Command>();
            var handler = _fixture.Create <Action>();
            var keyboardCommandService = new KeyboardCommandService();

            keyboardCommandService.RegisterCommandHandler(command, handler);

            Action invoke = () => keyboardCommandService.RegisterCommandHandler(command, handler);

            invoke.Should().Throw <InvalidOperationException>();
        }