Пример #1
0
        public void CancelCommandGroup_CancelAGroup_AllCommandsInGroupAreCancelled()
        {
            int[] commandsCanceled  = { 0 };
            var   fakeFilterManager = A.Fake <IFilterManager>();

            A.CallTo(() => fakeFilterManager.Process(A <CommandBase> .Ignored)).Returns(false);

            var processor = new CommandProcessor(null, fakeFilterManager);
            var commands  = new[]
            {
                new TestCommand(CommandState.New, groupId: "GroupA"),
                new TestCommand(CommandState.New, groupId: "GroupB"),
                new TestCommand(CommandState.New, groupId: "GroupA"),
                new TestCommand(CommandState.New, groupId: "GroupA"),
                new TestCommand(CommandState.New, groupId: "GroupB"),
                new TestCommand(CommandState.New, groupId: "GroupA"),
                new TestCommand(CommandState.New, groupId: "GroupC"),
            };

            foreach (var command in commands)
            {
                command.RegisterForStateChange(Observer.Create <IObservedChange <CommandBase, CommandState> >(b =>
                {
                    if (b.Value == CommandState.Canceled)
                    {
                        commandsCanceled[0]++;
                    }
                }));
                processor.PublishCommand(command);
            }

            processor.CancelCommandGroup("GroupA");

            Assert.AreEqual(4, commandsCanceled[0]);
        }
        public void CancelCommandGroup_CancelAGroup_AllCommandsInGroupAreCancelled()
        {
            int[] commandsCanceled = {0};
            var fakeFilterManager = A.Fake<IFilterManager>();
            A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(false);

            var processor = new CommandProcessor(null, fakeFilterManager);
            var commands = new[]
                           {
                               new TestCommand(CommandState.New, groupId: "GroupA"),
                               new TestCommand(CommandState.New, groupId: "GroupB"),
                               new TestCommand(CommandState.New, groupId: "GroupA"),
                               new TestCommand(CommandState.New, groupId: "GroupA"),
                               new TestCommand(CommandState.New, groupId: "GroupB"),
                               new TestCommand(CommandState.New, groupId: "GroupA"),
                               new TestCommand(CommandState.New, groupId: "GroupC"),

                           };
            foreach (var command in commands)
            {
                command.RegisterForStateChange(Observer.Create<CommandState>(b =>
                {
                    if (b == CommandState.Canceled)
                    {
                        commandsCanceled[0]++;
                    }
                }));

                processor.PublishCommand(command);
            }

            processor.CancelCommandGroup("GroupA");

            Assert.AreEqual(4, commandsCanceled[0]);
        }