public void ReturnsTwoHandlers() { var command = new Command2(); var handler = new TestHandlersLookup().Handler(command); Assert.Equal(2, handler.Count()); }
public void when_receives_message_then_notifies_registered_handler() { var handlerAMock = new Mock <ICommandHandler>(); handlerAMock.As <ICommandHandler <Command1> >(); var handlerBMock = new Mock <ICommandHandler>(); handlerBMock.As <ICommandHandler <Command2> >(); this.processor.Register(handlerAMock.Object); this.processor.Register(handlerBMock.Object); this.processor.Start(); var command1 = new Command1 { Id = Guid.NewGuid() }; var command2 = new Command2 { Id = Guid.NewGuid() }; this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(command1)))); this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(command2)))); handlerAMock.As <ICommandHandler <Command1> >().Verify(h => h.Handle(It.Is <Command1>(e => e.Id == command1.Id))); handlerBMock.As <ICommandHandler <Command2> >().Verify(h => h.Handle(It.Is <Command2>(e => e.Id == command2.Id))); }
public override void SetItem(Command2 command) { ItemCommand itemCommand = command as ItemCommand; if (itemCommand == null) { gameObject.SetActive(false); } else { gameObject.SetActive(true); NguiResource.Reset(gameObject); string name = string.Empty; Texture2D texture = null; string texturePath = itemCommand.template.icon; if (!string.IsNullOrEmpty(texturePath) && texturePath.Length > 1) { texture = Resources.Load(texturePath) as Texture2D; } UITexture buttonTexture = gameObject.GetSingleInChildren<UITexture>(); if (texture != null) { buttonTexture.shader = Shader.Find("Custom/Unlit/AlphaBlend"); buttonTexture.mainTexture = texture; } else { //name = itemCommand.name; } } }
float GetRemainTime(Command2 command) { if (lifes.ContainsKey(command)) { return lifes[command]; } return 0; }
protected override void Remove(Command2 command) { base.Remove(command); if (uiCommandSlot != null) { uiCommandSlot.SetItem(null); } }
public override bool TryAdd(Command2 command) { if (base.TryAdd(command)) { lifes.Add(command, InitLifeTime); return true; } return false; }
public virtual bool TryAdd(Command2 command) { if (queue.Count < capacity) { int index = IndexToInsert(queue, command.priority); queue.Insert(index, command); return true; } return false; }
private async Task Publish2Async() { var q = CreateQueue <Command2>(); for (var i = 0; i < 10; i++) { var cmd = new Command2(200 + i); _logger.LogInformation($"{DateTime.UtcNow:O}: Publish\tCommand2 {cmd.Id}"); await q.EnqueueAsync(cmd); } }
protected override bool Fire(ActionHandler2 firer, Command2 command) { if (base.Fire(firer, command)) { if (consumable) { Remove(command); } return true; } return false; }
public override bool TryAdd(Command2 command) { if (base.TryAdd(command)) { if (uiCommandSlot != null) { uiCommandSlot.SetItem(command); } return true; } return false; }
public MyCoolViewModel() { Command = ReactiveCommand.CreateFromTask <Unit, Unit>(async _ => { runSequentially = false; Console.WriteLine("Start 1"); await Task.Delay(1000); Console.WriteLine("End 1"); return(Unit.Default); }); Command2 = ReactiveCommand.CreateFromTask <Unit, Unit>(async _ => { runSequentially = false; Console.WriteLine("Start 2"); await Task.Delay(1000); Console.WriteLine("End 2"); return(Unit.Default); }); Command3 = ReactiveCommand.CreateFromTask <Unit, Unit>(async _ => { Console.WriteLine("Start 3"); await Task.Delay(1000); Console.WriteLine("End 3"); return(Unit.Default); }); CommandwhoInvokesOtherCommands = ReactiveCommand.CreateFromTask <Unit, Unit>(async _ => { Console.WriteLine("Invoking other commands"); runSequentially = true; await Task.Delay(1000); Console.WriteLine("End"); return(Unit.Default); }); /*Command 1, 2 and 3 only will run if flag is set to true*/ CommandwhoInvokesOtherCommands.Where(_ => runSequentially).InvokeCommand(Command); Command.Where(_ => runSequentially).InvokeCommand(Command2); Command2.Where(_ => runSequentially).InvokeCommand(Command3); //Observable.Return(Unit.Default).InvokeCommand(CommandwhoInvokesOtherCommands);//for test purposes }
protected override bool Fire(ActionHandler2 firer, Command2 command) { if (base.Fire(firer, command)) { if (onChargedAttack != null) { /* if (command is BlockCommand) { BlockCommand blockCommand = command as BlockCommand; if (blockCommand.isChargedAttack) { onChargedAttack(blockCommand.matchGeneration); } } * */ } return true; } return false; }
public void when_receives_message_then_notifies_registered_handler() { var handlerAMock = new Mock<ICommandHandler>(); handlerAMock.As<ICommandHandler<Command1>>(); var handlerBMock = new Mock<ICommandHandler>(); handlerBMock.As<ICommandHandler<Command2>>(); this.processor.Register(handlerAMock.Object); this.processor.Register(handlerBMock.Object); this.processor.Start(); var command1 = new Command1 { Id = Guid.NewGuid() }; var command2 = new Command2 { Id = Guid.NewGuid() }; this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(command1)))); this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(command2)))); handlerAMock.As<ICommandHandler<Command1>>().Verify(h => h.Handle(It.Is<Command1>(e => e.Id == command1.Id))); handlerBMock.As<ICommandHandler<Command2>>().Verify(h => h.Handle(It.Is<Command2>(e => e.Id == command2.Id))); }
public void AddCommand2(Command2 command) { commands2.Add(command); }
protected override void Remove(Command2 command) { base.Remove(command); lifes.Remove(command); }
public void Handle(Command2 c) { }
public void Handle2(Command2 command) { }
public Task Handle(Command2 message, IMessageHandlerContext context) { Console.WriteLine("Received Command2"); return(Task.FromResult(0)); }
/* public void Fire(int index) { if (0 <= index && index < queue.Count) { Fire(queue[index]); } } */ protected virtual bool Fire(ActionHandler2 firer, Command2 command) { if (command != null) { if (command.IsFirable(firer)) { if (pipe != null) { pipe.TryAdd(command); return true; } /* if (command is OnDemandCommand && !(command as OnDemandCommand).HasFirableTarget(owner)) { return true; } */ return command.Fire(firer); } } return false; }
public void Command2Handler(Command2 command) { }
protected virtual void Remove(Command2 command) { removeList.Add(command); }
public virtual void SetItem(Command2 command) { }
public bool TryAddItem(Command2 command) { for (int i = 0; i < 4; i++) { if (GetItemSlot(i).TryAdd(command)) { return true; } } return false; }
protected override bool Fire(ActionHandler2 firer, Command2 command) { if (base.Fire(firer, command)) { /* if (command is ItemCommand) { (command as ItemCommand).PlaySound(owner); } * */ return true; } return false; }