public override void Specify()
        {
            when("repeatedly dispatching a command", delegate
            {
                var trace = new StringWriter();

                arrange(delegate
                {
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter());
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter());
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter());
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter());
                });

                then("all parameters are evaluated independently", delegate
                {
                    Expect.That(trace.ToString()).ContainsInOrder(
                        "You walk to 1, 2 and find a maze of twisty little passages, all alike.",
                        "You walk to 3, 0 and find a maze of twisty little passages, all alike.",
                        "You walk to 0, 4 and find a maze of twisty little passages, all alike.",
                        "You walk to 0, 0 and find a maze of twisty little passages, all alike."
                        );
                });
            });
        }
示例#2
0
        public void RepeatedlyDispatchingCommand()
        {
            var trace = new StringWriter();

            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter());
            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter());
            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter());
            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter());

            // all parameters are evaluated independently
            MyStringAssert.ContainsInOrder(trace.ToString(),
                                           "You walk to 1, 2 and find a maze of twisty little passages, all alike.",
                                           "You walk to 3, 0 and find a maze of twisty little passages, all alike.",
                                           "You walk to 0, 4 and find a maze of twisty little passages, all alike.",
                                           "You walk to 0, 0 and find a maze of twisty little passages, all alike."
                                           );
        }
        public void MultipleDispatch_ShouldNotInterferWithEachOther()
        {
            var trace = new StringWriter();
            var expectedTraceParts = new []
            {
                "You walk to 1, 2 and find a maze of twisty little passages, all alike.",
                "You walk to 3, 0 and find a maze of twisty little passages, all alike.",
                "You walk to 0, 4 and find a maze of twisty little passages, all alike.",
                "You walk to 0, 0 and find a maze of twisty little passages, all alike.",
            };

            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter());
            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter());
            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter());
            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter());

            trace.ToString().AssertContainsInOrder(expectedTraceParts);
        }