Ejemplo n.º 1
0
        public void RegisterCommandHandler_HandlerIsNull_ThrowsArgumentNullException()
        {
            var    command = (Command) new Random().Next(1, Enum.GetValues(typeof(Command)).Length);
            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 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.º 4
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();
        }