public void RemoveDisposesCommandAndUnplugsCommandAdapters() { TestableRootWorkItem parent = new TestableRootWorkItem(); Command cmd = parent.Commands["TestCommand"]; ICommandAdapterMapService mapService = parent.Services.Get <ICommandAdapterMapService>(); mapService.Register(typeof(MockInvokerA), typeof(EventCommandAdapter <MockInvokerA>)); MockInvokerA invoker = new MockInvokerA(); cmd.AddInvoker(invoker, "Event"); Assert.AreEqual(1, parent.Commands["TestCommand"].Adapters.Count); InstanceHandlerClass instance = new InstanceHandlerClass(); parent.Items.Add(instance); invoker.DoInvokeEvent(); Assert.AreEqual(1, instance.counter); parent.Commands.Remove(parent.Commands["TestCommand"]); GC.Collect(0); GC.WaitForPendingFinalizers(); invoker.DoInvokeEvent(); Assert.AreEqual(0, parent.Commands["TestCommand"].Adapters.Count); // Returns 2 Assert.AreEqual(1, instance.counter); }
public void InvokerDoesNotCauseExecuteOnUnavailableCommand() { MockInvokerA invoker = new MockInvokerA(); bool executed = false; command.ExecuteAction += delegate { executed = true; }; EventCommandAdapter <MockInvokerA> adapter = new EventCommandAdapter <MockInvokerA>(invoker, "Event"); command.AddCommandAdapter(adapter); command.Status = CommandStatus.Unavailable; invoker.DoInvokeEvent(); Assert.IsFalse(executed); }
public void CanRemoveInvokerWithMultipleAdapters() { Command command = new Command(); MockInvokerA invokerA = new MockInvokerA(); MockInvokerB invokerB = new MockInvokerB(); EventCommandAdapter <MockInvokerA> adapterA = new EventCommandAdapter <MockInvokerA>(invokerA, "Event"); EventCommandAdapter <MockInvokerB> adapterB = new EventCommandAdapter <MockInvokerB>(invokerB, "Event"); command.AddCommandAdapter(adapterA); command.AddCommandAdapter(adapterB); command.RemoveInvoker(invokerA, "Event"); Assert.AreEqual(1, adapterB.Invokers.Count); Assert.AreEqual(0, adapterA.Invokers.Count); }
public void RemovingAllInvokersFromAdapterRemovesAdapterFromCommand() { TestableRootWorkItem workItem = new TestableRootWorkItem(); ICommandAdapterMapService svc = workItem.Services.Get <ICommandAdapterMapService>(); svc.Register(typeof(MockInvokerA), typeof(MockAdapter)); Command command = new Command(); workItem.Commands.Add(command); MockInvokerA invoker = new MockInvokerA(); command.AddInvoker(invoker, "Event"); Assert.AreEqual(1, command.Adapters.Count); command.RemoveInvoker(invoker, "Event"); Assert.AreEqual(0, command.Adapters.Count); }