public void CommandReturnsProperException(string message) { // Arrange using var busContext = new RabbitMqContextBuilder() .WithExchange("TestExchange") .WithConnectionString("amqp://*****:*****@localhost") .CreateContext(); using var host = new MicroserviceHostBuilder() .WithBusContext(busContext) .WithQueueName("QueueName2") .AddEventListener <ErrorEventListener>() .CreateHost(); host.Start(); var command = new DummyCommand(message); var publisher = new CommandPublisher(busContext); // Act Task <DummyCommand> Act() => publisher.PublishAsync <DummyCommand>(command); // Arrange var exception = Assert.ThrowsExceptionAsync <DestinationQueueException>(Act); Assert.AreEqual("Received error command from queue Test.Command.Listener", exception.Result.Message); }
public async Task <DummyCommand> GetDummyCommand() { DummyCommand myCmd = new DummyCommand(); var bUrl = "https://localhost:5001/"; var httpClientHandler = new HttpClientHandler(); // Bypass SSL validation httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => { return(true); }; var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(bUrl) }; httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await httpClient.GetAsync("api/dummycommand"); HttpContent content = response.Content; string jsonContent = content.ReadAsStringAsync().Result; myCmd = JsonConvert.DeserializeObject <DummyCommand>(jsonContent); return(myCmd); }
public ContentViewModel(IMessanger messanger) { //logger.Info("asd"); messanger.Subscribe <string>(OnMessageArrived).ExecuteOn(MessageProcessingThread.Dispatcher); Button = new DummyCommand(this, messanger); }
public void 커맨드_일정시간_기다리기_테스트() { // Arrange (데이터 정렬) var listCommand = Create_DummyCommands(); CommandManager <DummyCommand> pCommandManager = new CommandManager <DummyCommand>(); DummyCommand pRandomCommand = listCommand[0]; float fRandomWait = UnityEngine.Random.Range(0.1f, 0.3f); pRandomCommand.DoSet_WaitForSecond(fRandomWait); Stopwatch pTimer = new Stopwatch(); // Act (기능 실행) pTimer.Start(); Task.Run(async() => { // https://forum.unity.com/threads/async-await-in-unittests.513857/ await pCommandManager.DoExecuteCommand(pRandomCommand); }).GetAwaiter().GetResult(); pTimer.Stop(); // Assert (맞는지 체크) Assert.AreNotEqual(pRandomCommand.iExecutedIndex, 0); Assert.IsTrue(Math.Abs(pTimer.Elapsed.TotalSeconds - fRandomWait) < 0.02f); }
private static List <IToolbarCommand> BuildFunctionsOrConstantsCommands(string key, ITextProvider expressionTextProvider, IScriptProvider scriptingTextProvider, IScriptProvider customFunctionsTextProvider, ISharedViewState sharedViewState, IAutocompleteProvider autocompleteProvider, IClickedMouseButtonsProvider mouseButtonsProvider, IShowFunctionDetails showFunctionDetails) { var dict = new Dictionary <string, IToolbarCommand>(); foreach (var f in autocompleteProvider.ExpressionAutocompleteItems) { if (f.Details.IsNullOrEmpty() || f.Details.Type != key) { continue; } //TODO: remove this code when made sure it does nothing: if (f.Details.Category == "") { f.Details.Category = "_empty_"; } if (!dict.ContainsKey(f.Details.Category)) { //var cat = new ToolStripMenuItem(f.Value.Category) { Name = f.Value.Category }; var command = new DummyCommand(f.Details.Category) { ChildrenCommands = new List <IToolbarCommand>() }; dict.Add(f.Details.Category, command); } (dict[f.Details.Category].ChildrenCommands as List <IToolbarCommand>).Add( new FunctionOrConstantCommand(f, expressionTextProvider, scriptingTextProvider, customFunctionsTextProvider, sharedViewState, mouseButtonsProvider, showFunctionDetails)); } return(dict.Values.ToList()); }
/// <summary> /// Executes the commands associated with all keyboard inputs received /// since this method was last called. /// </summary> public override void UpdateAndExecuteInputs() { KeyboardState currentState = Keyboard.GetState(); foreach (Keys key in lastState.GetPressedKeys()) { ICommand command = null; if (currentState.IsKeyUp(key)) { if ((command == null) && ReleasedInputToCommandMap.TryGetValue((int)key, out command)) { command.InvokeCommand(); } } } foreach (Keys key in currentState.GetPressedKeys()) { ICommand command = null; if (lastState.IsKeyUp(key)) { foreach (Modifier mod in Enum.GetValues(typeof(Modifier))) { if (currentState.IsKeyDown((Keys)mod)) { //if a modifier is being held, it should block other kinds of commands //this guarantees that the null check fails when it tries to run a regular command command = new DummyCommand(new DummyClass()); if (inputChordToCommandMap.TryGetValue((int)mod, out Dictionary <int, ICommand> temp)) { if (temp.TryGetValue((int)key, out command)) { command.InvokeCommand(); break; } else { //needs to be set here too, if it makes it in here but trygetvalue fails, because //trygetvalue will set it back to null; command = new DummyCommand(new DummyClass()); } } } } if ((command == null) && InputToCommandMap.TryGetValue((int)key, out command)) { command.InvokeCommand(); } } if ((command == null) && HeldInputToCommandMap.TryGetValue((int)key, out command)) { command.InvokeCommand(); } } lastState = currentState; }
public void TestContinuationTasks_DoNotCauseDeadlocks() { var dummyCommand = new DummyCommand(new HystrixCommandOptions() { GroupKey = HystrixCommandGroupKeyDefault.AsKey("foobar") }); var options = new HystrixThreadPoolOptions() { CoreSize = 2, MaxQueueSize = 2, QueueSizeRejectionThreshold = 2, AllowMaximumSizeToDivergeFromCoreSize = false, }; // Scheduler to test var scheduler = new HystrixQueuedTaskScheduler(options); TaskActionClass tc1 = new TaskActionClass(output, 1); TaskActionClass tc2 = new TaskActionClass(output, 2); TaskActionClass tc3 = new TaskActionClass(output, 3); TaskActionClass tc4 = new TaskActionClass(output, 4); Task <int> t1 = new Task <int>((o) => tc1.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t2 = new Task <int>((o) => tc2.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t3 = new Task <int>((o) => tc3.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t4 = new Task <int>((o) => tc4.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); // Fill up to CoreSize t1.Start(scheduler); t2.Start(scheduler); // Make sure they are running Thread.Sleep(500); // Fill up queue t3.Start(scheduler); t4.Start(scheduler); // Allow all tasks to finish and cause continuation tasks to be queued tc1.Stop = true; tc2.Stop = true; tc3.Stop = true; tc4.Stop = true; Thread.Sleep(1000); Assert.True(t1.IsCompleted); Assert.Equal(1, t1.Result); Assert.True(t2.IsCompleted); Assert.Equal(2, t2.Result); Assert.True(t3.IsCompleted); Assert.Equal(3, t3.Result); Assert.True(t4.IsCompleted); Assert.Equal(4, t4.Result); }
public ContentViewModel(IMessanger messanger) { //logger.Info("asd"); messanger.Subscribe <string>(OnMessageArrived).ExecuteOn(MessageProcessingThread.Dispatcher); Button = new DummyCommand(this, messanger); base.Title = "asd"; Items = new ObservableCollection <string>(new[] { "-- All --", "Anna", "annie", "cookie", "lolo test" }); Reset = new ResetKey(); }
public void When_executing_it_it_should_call_the_executor_given_via_ctor() { var theCommand = new DummyCommand(); var theExecutor = MockRepository.GenerateMock <ICommandExecutor <DummyCommand> >(); var theWrapper = new TransactionalCommandExecutorWrapper <DummyCommand>(theExecutor); theWrapper.Execute(theCommand); theExecutor.AssertWasCalled((e) => e.Execute(theCommand)); }
public void When_executing_it_it_should_call_the_executor_given_via_ctor() { var theCommand = new DummyCommand(); var theExecutor = MockRepository.GenerateMock<ICommandExecutor<DummyCommand>>(); var theWrapper = new TransactionalCommandExecutorWrapper<DummyCommand>(theExecutor); theWrapper.Execute(theCommand); theExecutor.AssertWasCalled((e) => e.Execute(theCommand)); }
public void WithAdditionalArgument_CorrectInputs_GetsAddedToAdditionalArguments() { var cmd = new DummyCommand(); cmd.WithAdditionalArgument("--argument123"); CollectionAssert.AreEqual( cmd.AdditionalArguments, new[] { "--argument123", }); }
public void WithConfigurationOverride_CorrectInputs_GetsAddedToAdditionalArguments() { var cmd = new DummyCommand(); cmd.WithConfigurationOverride("section123", "name456", "value789"); CollectionAssert.AreEqual( cmd.AdditionalArguments, new[] { "--config", "section123.name456=\"value789\"", }); }
public void Dispatching_command_with_single_handler_invokes_that_handler() { var handler = Substitute.For<IHandleCommands<DummyCommand>>(); _dispatcher.RegisterHandler(handler); var expectedCommand = new DummyCommand(); _dispatcher.Dispatch(expectedCommand); handler.Received().Handle(expectedCommand); }
public RemoteControl() { executedCommands = new Stack <ICommand>(); onCommands = new ICommand[SLOTS_COUNT]; offCommands = new ICommand[SLOTS_COUNT]; for (var i = 0; i < SLOTS_COUNT; i++) { onCommands[i] = new DummyCommand(); offCommands[i] = new DummyCommand(); } }
private static List <DummyCommand> Create_DummyCommands() { DummyCommand.DoReset_ExecutedIndex(); System.Collections.Generic.List <DummyCommand> listCommand = new System.Collections.Generic.List <DummyCommand>(); for (int i = 0; i < 10; i++) { listCommand.Add(new DummyCommand(i)); } listCommand.ForEach(p => Assert.AreEqual(p.iExecutedIndex, 0)); return(listCommand); }
public async Task ObjectIsCreated() { var first = "test"; var second = 5; var command = new DummyCommand { FirstParameter = first, SecondParameter = second, }; var result = await command.Execute(this.commandService); //Assert.Equal(first + second, result); }
private static List <IToolbarCommand> BuildFunctionsOrConstantsCommands(string key, ITextProvider expressionTextProvider, ITextProvider scriptingTextProvider, ITextProvider customFunctionsTextProvider) { var dict = new Dictionary <string, IToolbarCommand>(); var functions = FunctionsDetails.Details.ToArray(); foreach (var f in functions) { if (f.Value.Type != key) { continue; } if (f.Value.Category == "") { f.Value.Category = "_empty_"; } if (!dict.ContainsKey(f.Value.Category)) { //var cat = new ToolStripMenuItem(f.Value.Category) { Name = f.Value.Category }; var command = new DummyCommand(f.Value.Category) { ChildrenCommands = new List <IToolbarCommand>() }; dict.Add(f.Value.Category, command); } (dict[f.Value.Category].ChildrenCommands as List <IToolbarCommand>).Add( new FunctionOrConstantCommand(f.Value.Signature, f.Value.Title, expressionTextProvider, scriptingTextProvider, customFunctionsTextProvider)); /*var item = new ToolStripMenuItem * { * Text = f.Value.Signature, * ToolTipText = f.Value.Title * }; * //item.Click += Item_Click; * item.MouseDown += Item_Click; * * (dict[f.Value.Type].DropDownItems[f.Value.Category] as ToolStripMenuItem) * .DropDownItems.Add(item);*/ } return(dict.Values.ToList()); }
public void Dispatching_command_with_multiple_handlers_invokes_all_those_handlers() { var handler1 = Substitute.For<IHandleCommands<DummyCommand>>(); var handler2 = Substitute.For<IHandleCommands<DummyCommand>>(); _dispatcher.RegisterHandler(handler1); _dispatcher.RegisterHandler(handler2); var expectedCommand = new DummyCommand(); _dispatcher.Dispatch(expectedCommand); handler1.Received().Handle(expectedCommand); handler2.Received().Handle(expectedCommand); }
public HomeViewModel(/*UserProfile userProfile*/ object owner) { dummyCmd = new DummyCommand(this); dummy2Cmd = new Dummy2Command(this); this.UserProfile = (UserProfile)owner; HomeUserControlViewModel = new HomeUserControlViewModel(this); UserProfileUserControlViewModel = new UserProfileUserControlViewModel(this); DashboardUserControlViewModel = new DashboardUserControlViewModel(this); HistoryUserControlViewModel = new HistoryUserControlViewModel(this); ContractorUserControlViewModel = new ContractorUserControlViewModel(this); homeUserControlViewModel.SubscribeMeToThis(this); userProfileUserControlViewModel.SubscribeMeToThis(this); dashboardUserControlViewModel.SubscribeMeToThis(this); historyUserControlViewModel.SubscribeMeToThis(this); contractorUserControlViewModel.SubscribeMeToThis(this); }
public UndoRedoManager(Presentation pres) { mPresentation = pres; mUndoStack = new Stack <Command>(); mRedoStack = new Stack <Command>(); mActiveTransactions = new Stack <CompositeCommand>(); m_DirtyMarkerDummyCommand = new DummyCommand(); m_DirtyMarkerCommand = m_DirtyMarkerDummyCommand; //TransactionStarted += this_transactionStarted; //TransactionEnded += this_transactionEnded; //TransactionCancelled += this_transactionCancelled; //CommandDone += this_commandDone; //CommandUnDone += this_commandUnDone; //CommandReDone += this_commandReDone; }
public void Dispatching_command_when_handlers_are_registered_for_multiple_different_types_only_invokes_handlers_for_current_command_type() { var handler1 = Substitute.For<IHandleCommands<DummyCommand>>(); var handler2 = Substitute.For<IHandleCommands<DummyCommand>>(); var otherHandler1 = Substitute.For<IHandleCommands<OtherDummyCommand>>(); var otherHandler2 = Substitute.For<IHandleCommands<OtherDummyCommand>>(); _dispatcher.RegisterHandler(handler1); _dispatcher.RegisterHandler(otherHandler1); _dispatcher.RegisterHandler(handler2); _dispatcher.RegisterHandler(otherHandler2); var expectedCommand = new DummyCommand(); _dispatcher.Dispatch(expectedCommand); handler1.Received().Handle(expectedCommand); handler2.Received().Handle(expectedCommand); }
public void 커맨드를_하나만_실행할수있는지() { // Arrange (데이터 정렬) var listCommand = Create_DummyCommands(); CommandManager <DummyCommand> pCommandManager = new CommandManager <DummyCommand>(); for (int i = 0; i < listCommand.Count; i++) { DummyCommand pCommand = listCommand[i]; Assert.AreEqual(pCommand.iExecutedIndex, 0); // Act (기능 실행) _ = pCommandManager.DoExecuteCommand(pCommand); // Assert (맞는지 체크) Assert.AreEqual(pCommand.iExecutedIndex, i + 1); } }
public void TestContinuationTasks_DoNotCauseDeadlocks() { var dummyCommand = new DummyCommand(new HystrixCommandOptions() { GroupKey = HystrixCommandGroupKeyDefault.AsKey("foobar") }); var options = new HystrixThreadPoolOptions() { CoreSize = 2, }; // Scheduler to test var scheduler = new HystrixSyncTaskScheduler(options); TaskActionClass tc1 = new TaskActionClass(output, 1); TaskActionClass tc2 = new TaskActionClass(output, 2); Task <int> t1 = new Task <int>((o) => tc1.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t2 = new Task <int>((o) => tc2.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); // Fill up to CoreSize t1.Start(scheduler); t2.Start(scheduler); // Make sure they are running Thread.Sleep(500); // Allow t1 task to finish and cause continuation task to be queued tc1.Stop = true; Thread.Sleep(1000); Assert.True(t1.IsCompleted); Assert.Equal(1, t1.Result); tc2.Stop = true; Thread.Sleep(1000); Assert.True(t2.IsCompleted); Assert.Equal(2, t2.Result); }
private static List <IToolbarCommand> BuildFunctionsOrConstantsCommands(string key, ITextProvider expressionTextProvider, IScriptProvider scriptingTextProvider, IScriptProvider customFunctionsTextProvider, ISharedViewState sharedViewState, IFunctionsDetails functionsDetails, IClickedMouseButtonsProvider mouseButtonsProvider, IShowFunctionDetails showFunctionDetails) { var dict = new Dictionary <string, IToolbarCommand>(); var functions = functionsDetails.ToArray(); foreach (var f in functions) { if (f.Value.Type != key) { continue; } if (f.Value.Category == "") { f.Value.Category = "_empty_"; } if (!dict.ContainsKey(f.Value.Category)) { //var cat = new ToolStripMenuItem(f.Value.Category) { Name = f.Value.Category }; var command = new DummyCommand(f.Value.Category) { ChildrenCommands = new List <IToolbarCommand>() }; dict.Add(f.Value.Category, command); } (dict[f.Value.Category].ChildrenCommands as List <IToolbarCommand>).Add( new FunctionOrConstantCommand(f.Value.Signature, f.Value.Title, expressionTextProvider, scriptingTextProvider, customFunctionsTextProvider, sharedViewState, functionsDetails, mouseButtonsProvider, showFunctionDetails)); } return(dict.Values.ToList()); }
public DummyCommand Handles(DummyCommand command) { return(null); }
public int Handle(DummyCommand command) { return(5); }
public void ThereAreNoDefaultContinuations() { var command = new DummyCommand(); Assert.Empty(command.Continuations(null !, null !)); }
public void HasEmptyName() { var command = new DummyCommand(); Assert.Empty(command.Name); }
public DummyCommand Handle(DummyCommand eventCommand) { HandlesResult = eventCommand; return(eventCommand); }
public void Constructor_ProducesEmptyAdditionalArguments() { var cmd = new DummyCommand(); Assert.That(cmd.AdditionalArguments.Count, Is.EqualTo(0)); }
public void WithConfigurationOverride_NullOrEmptySectionName_ThrowsArgumentNullException(string input) { var cmd = new DummyCommand(); Assert.Throws<ArgumentNullException>(() => cmd.WithConfigurationOverride(input, "name", "value")); }
public void WithAdditionalArgument_NullOrEmptyArguments_ThrowsArgumentNullException(string input) { var cmd = new DummyCommand(); Assert.Throws<ArgumentNullException>(() => cmd.WithAdditionalArgument(input)); }
public DummyCommand Handles(DummyCommand command) { throw new Exception(command.ExceptionMessage); }
public void WithConfigurationOverride_NullValue_ThrowsArgumentNullException() { var cmd = new DummyCommand(); Assert.Throws<ArgumentNullException>(() => cmd.WithConfigurationOverride("section", "name", null)); }
public Task <BodyResponse <DummyInfo> > Handle(DummyCommand request, CancellationToken cancellationToken) { BodyResponse <DummyInfo> response = new BodyResponse <DummyInfo>(StatusCodeDefines.LoginError, null, null); return(Task.FromResult(response)); }
public void Execute_NullOrEmptyRepositoryPath_ThrowsArgumentNullException(string input) { var command = new DummyCommand(); Assert.Throws<ArgumentNullException>(() => NonPersistentClient.Execute(input, command)); }
public void Post([FromBody] DummyCommand command) { _bus.Send(command); }