public void WhenNoAsyncHandlerRegistereded_ThenInvokesOnThreadPoolAndPersistsToStore() { var command = new FooCommand { Id = 5 }; var handler = new Mock <ICommandHandler <FooCommand> >(); handler.Setup(x => x.IsAsync).Returns(true); var handlerCalled = false; handler.Setup(x => x.Handle(It.IsAny <FooCommand>(), It.IsAny <IDictionary <string, object> >())) .Callback <FooCommand, IDictionary <string, object> >((c, h) => handlerCalled = true); var store = new Mock <IMessageStore <IDomainCommand> >(); var bus = new CommandRegistry <IDomainCommand>(store.Object, new[] { handler.Object }); bus.Execute(command); while (!handlerCalled) { System.Threading.Thread.Sleep(10); } handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >())); store.Verify(x => x.Save(command, It.IsAny <IDictionary <string, object> >())); }
public void WhenAsyncHandlerRegisteredForBaseType_ThenThrowsForExecuteWithDerivedClass() { var command = new FooCommand { Id = 5 }; var handler = Mock.Of <ICommandHandler <BaseCommand> >(); var bus = new CommandRegistry <IDomainCommand>(new[] { handler }, action => action()); Assert.Throws <InvalidOperationException>(() => bus.Execute(command)); }
public void WhenNoStoreSpecifiedAndMatchingHandlerRegistered_ThenExecuteSucceeds() { var command = new FooCommand { Id = 5 }; var handler = Mock.Of <ICommandHandler <FooCommand> >(x => x.IsAsync == true); var bus = new CommandRegistry <IDomainCommand>(new[] { handler }); bus.Execute(command); }
public void WhenHandlerRegisteredForSpecificType_ThenPersistsToStore() { var command = new FooCommand { Id = 5 }; var handler = Mock.Of <ICommandHandler <FooCommand> >(); var store = new Mock <IMessageStore <IDomainCommand> >(); var bus = new CommandRegistry <IDomainCommand>(store.Object, new[] { handler }); bus.Execute(command); store.Verify(x => x.Save(command, It.IsAny <IDictionary <string, object> >())); }
public void WhenHandlerRegisteredForSpecificType_ThenHandlesOnExecute() { var command = new FooCommand { Id = 5 }; var handler = new Mock <CommandHandler <FooCommand> > { CallBase = true }; var bus = new CommandRegistry <IDomainCommand>(new[] { handler.Object }); bus.Execute(command); handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >())); }
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if (null == m_plugin || null == m_commandRegistry) { return; } if (executeOption != vsCommandExecOption.vsCommandExecOptionDoDefault) { return; } handled = m_commandRegistry.Execute(commandName); }
public void WhenExecutedCommandThrows_ThenSavesExceptionAsHeader() { var headers = new Dictionary <string, object>(); headers.Add("IP", "localhost"); var handler = new Mock <ICommandHandler <FooCommand> >(); var store = new Mock <IMessageStore <IDomainCommand> >(); var registry = new CommandRegistry <IDomainCommand>(store.Object, new[] { handler.Object }); handler.Setup(x => x.Handle(It.IsAny <FooCommand>(), headers)) .Throws(new ArgumentException("foo")); registry.Execute(new FooCommand(), headers); Assert.True(headers.ContainsKey("Exception")); }
public void WhenAsyncHandlerRegisteredForSpecificType_ThenInvokesAsyncRunner() { var command = new FooCommand { Id = 5 }; var handler = new Mock <CommandHandler <FooCommand> > { CallBase = true }; handler.Setup(x => x.IsAsync).Returns(true); var asyncCalled = false; Action <Action> asyncRunner = action => asyncCalled = true; var bus = new CommandRegistry <IDomainCommand>(new[] { handler.Object }, asyncRunner); bus.Execute(command); handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >()), Times.Never()); Assert.True(asyncCalled); }
public void WhenAsyncHandlerRegisteredForSpecificType_ThenCanUseDefaultAsyncRunner() { var command = new FooCommand { Id = 5 }; var handlerCalled = false; var handler = new Mock <ICommandHandler <FooCommand> >(); handler.Setup(x => x.IsAsync).Returns(true); handler.Setup(x => x.Handle(It.IsAny <FooCommand>(), It.IsAny <IDictionary <string, object> >())) .Callback <FooCommand, IDictionary <string, object> >((c, h) => handlerCalled = true); var bus = new CommandRegistry <IDomainCommand>(new[] { handler.Object }); bus.Execute(command); while (!handlerCalled) { System.Threading.Thread.Sleep(10); } handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >())); }
private void Update() { phase = Mathf.Clamp01(phase + speed * Time.deltaTime); if (GetComponent <CanvasGroup>().alpha != phase) { GetComponent <CanvasGroup>().alpha = phase; if (phase > 0f != receivedUI.activeSelf) { receivedUI.SetActive(phase > 0f); } } allowChat = (MenuSystem.instance.activeMenu == null || MenuSystem.instance.activeMenu is MultiplayerLobbyMenu); if (!NetGame.isNetStarted && !string.IsNullOrEmpty(contents)) { contents = string.Empty; CropContents(); } if (!NetGame.isNetStarted || !allowChat) { if (visible) { Show(showMessages: false, showType: false); } return; } if (!typing && visible && dismissIn > 0f) { dismissIn -= Time.deltaTime; if (dismissIn <= 0f) { Show(showMessages: false, showType: false); } } if (MenuSystem.keyboardState != 0 && MenuSystem.keyboardState != KeyboardState.NetChat) { return; } if (Input.GetKeyDown(KeyCode.T) && !typing) { Show(showMessages: true, showType: true); } else if (Input.GetKeyDown(KeyCode.Return) && typing) { string text = input.text.Trim(); if (string.IsNullOrEmpty(text)) { input.text = string.Empty; input.DeactivateInputField(); Show(showMessages: false, showType: false); return; } if (text.StartsWith("/")) { if (NetGame.isServer) { serverCommands.Execute(text.Substring(1)); } else { clientCommands.Execute(text.Substring(1)); } } else { Send(text); } input.text = string.Empty; Show(showMessages: true, showType: false); } else if (Input.GetKeyDown(KeyCode.Escape) && typing) { input.text = string.Empty; input.DeactivateInputField(); Show(showMessages: false, showType: false); } }
private void Update() { if (lostDevice) { reloadSkins = true; lostDevice = false; } else if (reloadSkins) { reloadSkins = (lostDevice = false); for (int i = 0; i < NetGame.instance.players.Count; i++) { NetGame.instance.players[i].ReapplySkin(); } } if (MenuSystem.keyboardState != 0 && MenuSystem.keyboardState != KeyboardState.Shell) { return; } if (Game.GetKeyDown(KeyCode.BackQuote) || Game.GetKeyDown(KeyCode.F1)) { visible = !visible; ui.SetActive(visible); MenuSystem.keyboardState = (visible ? KeyboardState.Shell : KeyboardState.None); if (visible) { MenuSystem.instance.FocusOnMouseOver(enable: false); input.ActivateInputField(); } else { input.DeactivateInputField(); if (input.text.EndsWith("`")) { input.text = input.text.Substring(0, input.text.Length - 1); } } } if (!visible || !(EventSystem.current.currentSelectedGameObject == input.gameObject)) { return; } if (Game.GetKeyDown(KeyCode.Escape)) { if (!string.IsNullOrEmpty(input.text)) { input.text = string.Empty; } else { visible = false; ui.SetActive(value: false); MenuSystem.keyboardState = KeyboardState.None; input.DeactivateInputField(); } } if (Game.GetKeyDown(KeyCode.Return)) { string text = input.text.Trim(); Print("> " + text); commands.Execute(text.ToLowerInvariant()); input.text = string.Empty; input.ActivateInputField(); } }