コード例 #1
0
                public static Action <string>[] GetExpectedHistory(string expectedCommand, string expectedCommandName)
                {
                    switch (expectedCommand)
                    {
                    case BasicCommand:
                        return(new Action <string>[] {
                            x => AssertForVisitor.CalledVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.BasicCommand()}", x),
                            x => AssertForVisitor.CalledPostVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.BasicCommand()}", x)
                        });

                    case DerivedCommand:
                        return(new Action <string>[] {
                            x => AssertForVisitor.CalledVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.DerivedCommand()}", x),
                            x => AssertForVisitor.CalledPostVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.DerivedCommand()}", x)
                        });

                    case DerivedCommandV2:
                        return(new Action <string>[] {
                            x => AssertForVisitor.CalledVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.DerivedCommandV2()}", x),
                            x => AssertForVisitor.CalledPostVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.DerivedCommandV2()}", x)
                        });

                    case UnrelatedCommand:
                        return(new Action <string>[] {
                            x => AssertForVisitor.CalledVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.UnrelatedCommand()}", x),
                            x => AssertForVisitor.CalledPostVisitCommand(StageName.VisitorA, $"{expectedCommandName}:{CallWith.CommandValue.UnrelatedCommand()}", x)
                        });
                    }
                    return(new Action <string> [0]);
                }
        public void WhenCallingRunCommandWithNullCommandName_ThenVisitCommandCalledInExpectedStageCommandOrder()
        {
            using (var pipeline = PipelineConfig.CreatePipeline())
            {
                pipeline.RunCommand(null, "Test");
            }

            Assert.Equal(4, HistoryOfVisits.Count);

            Assert.Collection(HistoryOfVisits,
                              x => AssertForVisitor.CalledVisitCommand(VisitorA, "Test", x),
                              x => AssertForVisitor.CalledVisitCommand(VisitorB, "Test", x),
                              x => AssertForVisitor.CalledPostVisitCommand(VisitorB, "Test", x),
                              x => AssertForVisitor.CalledPostVisitCommand(VisitorA, "Test", x));
        }
        public void WhenCallingRunCommandWithGivenCommandName_ThenDefaultVisitCommandCalledInExpectedStageCommandOrder()
        {
            using (var pipeline = PipelineConfig.CreatePipeline())
            {
                // because the Visitor was defined without specifying command name, it will apply to any command run on pipeline, as long as it matches the command TPayload type
                pipeline.RunCommand(CommandName, "Test");
            }

            Assert.Equal(4, HistoryOfVisits.Count);

            Assert.Collection(HistoryOfVisits,
                              x => AssertForVisitor.CalledVisitCommand(VisitorA, "Test", x),
                              x => AssertForVisitor.CalledVisitCommand(VisitorB, "Test", x),
                              x => AssertForVisitor.CalledPostVisitCommand(VisitorB, "Test", x),
                              x => AssertForVisitor.CalledPostVisitCommand(VisitorA, "Test", x));
        }