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 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.º 4
0
 private void ForEachOverStep(StringTableStep actionStep, ActionMethodInfo info)
 {
     foreach (var example in actionStep.TableSteps)
     {
         RunStep(info, () => ParameterConverter.GetParametersForStep(actionStep, example));
     }
 }
Ejemplo n.º 5
0
 private void GetValuesFromTableStep(StringTableStep stringStep, Func<Example, string, string> getValues, MethodInfo addMethodOnList, object values, ActionMethodInfo method)
 {
     List<string> paramNames = (stringStep.TableSteps.FirstOrDefault() ?? Example.EmptyExample).ColumnNames.Select(_ => _.Name).ToList();
     foreach (var example in (stringStep).TableSteps)
     {
         var value = GetParametersForStep(method, paramNames, _ => getValues(example, _))[0];
         addMethodOnList.Invoke(values, new[] { value });
     }
 }
Ejemplo n.º 6
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.º 7
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.º 8
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.º 9
0
 private void DoStringTableStep(StringTableStep stringTableStep)
 {
     if (!stringTableStep.TableSteps.Any())
     {
         return;
     }
     Writer.WriteStartElement("table");
     WriteColumnNames(stringTableStep.TableSteps.First().ColumnNames);
     foreach (var tableStep in stringTableStep.TableSteps)
     {
         Writer.WriteStartElement("row");
         WriteExampleRow(tableStep);
         Writer.WriteEndElement();
     }
     Writer.WriteEndElement();
 }
Ejemplo n.º 10
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.º 11
0
            public void Scenario()
            {
                var scenario =
                    "Scenario: A scenario with an inline table" + Environment.NewLine +
                    "  Given the following people exists:" + Environment.NewLine +
                    "  |Name          |Country|" + Environment.NewLine +
                    "  |Morgan Persson|Sweden |" + Environment.NewLine +
                    "  |Jimmy Nilsson |Sweden |" + Environment.NewLine +
                    "  |Jimmy bogard  |USA    |" + Environment.NewLine +
                    "  When I search for people in sweden" + Environment.NewLine +
                    "  Then I should get:" + Environment.NewLine +
                    "  |Name          |" + Environment.NewLine +
                    "  |Morgan Persson|" + Environment.NewLine +
                    "  |Jimmy Nilsson |";

                Parse(scenario);
                givenStep = scenarios.First().Steps.First() as StringTableStep;
                thenStep  = scenarios.First().Steps.Last() as StringTableStep;
            }
Ejemplo n.º 12
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));
            }
        }
Ejemplo n.º 13
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.º 14
0
            public void Scenario()
            {
                var scenario =
                    "Scenario: A scenario with an inline table" + Environment.NewLine +
                    "  Given the following people exists:" + Environment.NewLine +
                    "  |Name          |Country|" + Environment.NewLine +
                    "  |Morgan Persson|Sweden |" + Environment.NewLine +
                    "  |Jimmy Nilsson |Sweden |" + Environment.NewLine +
                    "  |Jimmy bogard  |USA    |" + Environment.NewLine +
                    "  When I search for people in sweden" + Environment.NewLine +
                    "  Then I should get:" + Environment.NewLine +
                    "  |Name          |" + Environment.NewLine +
                    "  |Morgan Persson|" + Environment.NewLine +
                    "  |Jimmy Nilsson |";

                Parse(scenario);
                givenStep = scenarios.First().Steps.First() as StringTableStep;
                thenStep = scenarios.First().Steps.Last() as StringTableStep;
            }
Ejemplo n.º 15
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.º 16
0
 private void ForEachOverStep(StringTableStep actionStep, ActionMethodInfo info)
 {
     foreach (var example in actionStep.TableSteps)
         RunStep(info, () => ParameterConverter.GetParametersForStep(actionStep, example));
 }
Ejemplo n.º 17
0
 private void GetValuesFromTableStep(StringTableStep stringStep, Func<Example, string, string> getValues, MethodInfo addMethodOnList, object values, ActionMethodInfo method)
 {
     List<string> paramNames = (stringStep.TableSteps.FirstOrDefault() ?? Example.EmptyExample).ColumnNames.Select(_ => _.Name).ToList();
     foreach (var example in (stringStep).TableSteps)
     {
         var value = GetParametersForStep(method, paramNames, _ => getValues(example, _))[0];
         addMethodOnList.Invoke(values, new[] { value });
     }
 }
Ejemplo n.º 18
0
 private void DoStringTableStep(StringTableStep stringTableStep)
 {
     if (!stringTableStep.TableSteps.Any())
         return;
     Writer.WriteStartElement("table");
     WriteColumnNames(stringTableStep.TableSteps.First().ColumnNames);
     foreach (var tableStep in stringTableStep.TableSteps)
     {
         Writer.WriteStartElement("row");
         WriteExampleRow(tableStep);
         Writer.WriteEndElement();
     }
     Writer.WriteEndElement();
 }