public void Should_get_parameter_value_for_action_with_parameter_of_List_of_complex_type()
            {
                List <UserClass>           actual = null;
                Action <List <UserClass> > action = _ => { actual = _; };

                actionCatalog.Add(new ActionMethodInfo(new Regex(@"some users:"), action, action.Method, "Given"));
                var tableStep = new StringTableStep("Given some users:", "");

                tableStep.AddTableStep(new Example(new ExampleColumns {
                    new ExampleColumn("age"), new ExampleColumn("name")
                }, new Dictionary <string, string> {
                    { "age", "42" }, { "name", "Morgan" }
                }));
                tableStep.AddTableStep(new Example(new ExampleColumns {
                    new ExampleColumn("age"), new ExampleColumn("name")
                }, new Dictionary <string, string> {
                    { "age", "666" }, { "name", "Lucifer" }
                }));
                runner.Run(tableStep);
                Assert.That(actual, Is.Not.Null);
                Assert.That(actual.Count, Is.EqualTo(2));
                Assert.That(actual[0].Name, Is.EqualTo("Morgan"));
                Assert.That(actual[0].Age, Is.EqualTo(42));
                Assert.That(actual[1].Name, Is.EqualTo("Lucifer"));
                Assert.That(actual[1].Age, Is.EqualTo(666));
            }
Ejemplo n.º 2
0
            public void Should_get_a_list_of_complex_types()
            {
                Action <List <Book> > actionStep = p => { };

                _actionCatalog.Add(new ActionMethodInfo(new Regex(@"a list of books:$"), actionStep, actionStep.Method, "Given"));
                const string actionString = "a list of books:";
                var          stringStep   = new StringTableStep("Given", actionString, "");
                var          columnNames  = new ExampleColumns {
                    new ExampleColumn("name"), new ExampleColumn("author"), new ExampleColumn("isbn")
                };
                var stepValues1 = new Dictionary <string, string> {
                    { "name", "n1" }, { "author", "a1" }, { "isbn", "1" }
                };

                stringStep.AddTableStep(new Example(columnNames, stepValues1));
                var stepValues2 = new Dictionary <string, string> {
                    { "name", "n2" }, { "aUthOr", "a2" }, { "isbn", "2" }
                };

                stringStep.AddTableStep(new Example(columnNames, stepValues2));
                var values = _parameterConverter.GetParametersForStep(stringStep);
                var value  = values[0];

                Assert.That(value, Is.TypeOf(typeof(List <Book>)));
                var books = (List <Book>)value;

                Assert.AreEqual(2, books.Count);
                Assert.AreEqual(1, books[0].ISBN);
                Assert.AreEqual(2, books[1].ISBN);
            }
Ejemplo n.º 3
0
 private Scenario CreateScenarioWithTable(Feature feature)
 {
     var scenario = new Scenario("title", "", feature);
     var givenStep = new StringTableStep("Given name [x]", "");
     givenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("x") }), new Dictionary<string, string> { { "x", "Nisse" } }));
     givenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("x") }), new Dictionary<string, string> { { "x", "Kalle" } }));
     scenario.AddStep(givenStep);
     scenario.AddStep(new StringStep("When greeted", ""));
     var thenStep = new StringTableStep("Then Hello [y]", "");
     thenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("y"), }), new Dictionary<string, string> { { "y", "Nisse" } }));
     thenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("y"), }), new Dictionary<string, string> { { "y", "Kålle" } }));
     scenario.AddStep(thenStep);
     return scenario;
 }
Ejemplo n.º 4
0
        private void HandleTableEvent(IList <IList <Token> > content)
        {
            if (previousStep == null)
            {
                return;
            }
            var stringTableStep = new StringTableStep(previousStep.Token, previousStep.MatchableStep, scenario.Source, previousStep.SourceLine);

            scenario.AddStep(stringTableStep);

            var columns        = content.First().Select(token => new ExampleColumn(token.Content));
            var exampleColumns = new ExampleColumns(columns);

            foreach (var list in content.Skip(1))
            {
                var example = list.Select(token => token.Content).ToList();

                var row = new Dictionary <string, string>();

                for (int i = 0; i < example.Count(); i++)
                {
                    row.Add(exampleColumns[i].Name, example.ElementAt(i));
                }

                stringTableStep.AddTableStep(new Example(exampleColumns, row));
            }
        }
Ejemplo n.º 5
0
            protected override void Because_of()
            {
                var result          = new ScenarioResult(feature, ScenarioTitle);
                var stringTableStep = new StringTableStep("Given something", Source);

                stringTableStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("A"), new ExampleColumn("B"), }),
                                                         new Dictionary <string, string> {
                    { "A", "aaa" }, { "B", "bb" }
                }));
                result.AddActionStepResult(new StepResult(stringTableStep, new Passed()));
                resultPublisher.Notify(result);
            }
Ejemplo n.º 6
0
        public void Should_be_able_to_serialize_binary()
        {
            var s = new StringTableStep("Given x", "source");
            var columns = new ExampleColumns(new[] { new ExampleColumn("a") });
            var values = new Dictionary<string, string> { { "a", "value" } };
            var row = new Example(columns, values);
            s.AddTableStep(row);

            var b = new BinaryFormatter();
            using (Stream stream = new MemoryStream())
                b.Serialize(stream, s);
            Assert.Pass("Should not throw exception");
        }
Ejemplo n.º 7
0
            private Scenario CreateScenarioWithTable(Feature feature)
            {
                var scenario  = new Scenario("title", "", feature);
                var givenStep = new StringTableStep("Given name [x]", "");

                givenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("x") }), new Dictionary <string, string> {
                    { "x", "Nisse" }
                }));
                givenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("x") }), new Dictionary <string, string> {
                    { "x", "Kalle" }
                }));
                scenario.AddStep(givenStep);
                scenario.AddStep(new StringStep("When greeted", ""));
                var thenStep = new StringTableStep("Then Hello [y]", "");

                thenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("y"), }), new Dictionary <string, string> {
                    { "y", "Nisse" }
                }));
                thenStep.AddTableStep(new Example(new ExampleColumns(new[] { new ExampleColumn("y"), }), new Dictionary <string, string> {
                    { "y", "Kålle" }
                }));
                scenario.AddStep(thenStep);
                return(scenario);
            }
Ejemplo n.º 8
0
        public void Should_be_able_to_serialize_binary()
        {
            var s       = new StringTableStep("Given", "x", "source");
            var columns = new ExampleColumns(new[] { new ExampleColumn("a") });
            var values  = new Dictionary <string, string> {
                { "a", "value" }
            };
            var row = new Example(columns, values);

            s.AddTableStep(row);

            var b = new BinaryFormatter();

            using (Stream stream = new MemoryStream())
                b.Serialize(stream, s);
            Assert.Pass("Should not throw exception");
        }
Ejemplo n.º 9
0
 public void Should_get_parameter_value_for_action_with_parameter_of_List_of_complex_type()
 {
     List<UserClass> actual = null;
     Action<List<UserClass>> action = _ => { actual = _; };
     actionCatalog.Add(new ActionMethodInfo(new Regex(@"some users:"), action, action.Method, "Given"));
     var tableStep = new StringTableStep("Given some users:", "");
     tableStep.AddTableStep(new Example(new ExampleColumns { new ExampleColumn("age"), new ExampleColumn("name") }, new Dictionary<string, string> { { "age", "42" }, { "name", "Morgan" } }));
     tableStep.AddTableStep(new Example(new ExampleColumns { new ExampleColumn("age"), new ExampleColumn("name") }, new Dictionary<string, string> { { "age", "666" }, { "name", "Lucifer" } }));
     runner.Run(tableStep);
     Assert.That(actual, Is.Not.Null);
     Assert.That(actual.Count, Is.EqualTo(2));
     Assert.That(actual[0].Name, Is.EqualTo("Morgan"));
     Assert.That(actual[0].Age, Is.EqualTo(42));
     Assert.That(actual[1].Name, Is.EqualTo("Lucifer"));
     Assert.That(actual[1].Age, Is.EqualTo(666));
 }
Ejemplo n.º 10
0
        private void HandleTableEvent(IList<IList<Token>> content)
        {
            if (previousStep == null)
                return;
            var stringTableStep = new StringTableStep(previousStep.Step, scenario.Source, previousStep.SourceLine);
            scenario.AddStep(stringTableStep);

            var columns = content.First().Select(token => new ExampleColumn(token.Content));
            var exampleColumns = new ExampleColumns(columns);

            foreach (var list in content.Skip(1))
            {
                var example = list.Select(token => token.Content).ToList();

                var row = new Dictionary<string, string>();

                for (int i = 0; i < example.Count(); i++)
                    row.Add(exampleColumns[i].Name, example.ElementAt(i));

                stringTableStep.AddTableStep(new Example(exampleColumns, row));
            }
        }