コード例 #1
0
ファイル: ScenarioSpec.cs プロジェクト: wmadzha/NBehave
        public void Should_include_examples_when_converting_to_string()
        {
            var feature  = new Feature("featureTitle", "", "source", 1);
            var scenario = new Scenario("scenarioTitle", "source", feature, 3);

            scenario.AddStep(new StringStep("Given", "a [foo]", "source, 4"));
            scenario.AddStep(new StringStep("And", "[bar]", "source, 5"));
            var columnNames = new ExampleColumns {
                new ExampleColumn("foo"), new ExampleColumn("bar")
            };

            scenario.AddExamples(new[]
            {
                new Example(columnNames, new Dictionary <string, string> {
                    { "foo", "1" }, { "bar", "2" }
                }),
                new Example(columnNames, new Dictionary <string, string> {
                    { "foo", "11" }, { "bar", "22" }
                })
            });
            var    scenarioAsString = scenario.ToString();
            string expected         = string.Format("Scenario: scenarioTitle{0}  Given a [foo]{0}  And [bar]{0}", Environment.NewLine);

            expected += "Examples:" + Environment.NewLine +
                        "     | foo | bar |" + Environment.NewLine +
                        "     | 1 | 2 |" + Environment.NewLine +
                        "     | 11 | 22 |";
            Assert.AreEqual(expected, scenarioAsString);
        }
コード例 #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);
            }
コード例 #3
0
ファイル: StepBuilder.cs プロジェクト: wmadzha/NBehave
        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));
            }
        }
コード例 #4
0
        private void ExtractExamplesFromTable(IList <IList <Token> > table)
        {
            if (!listenToParsedTable)
            {
                return;
            }

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

            foreach (var list in table.Skip(1))
            {
                var example = list.Select(token => token.Content);
                var row     = new Dictionary <string, string>();

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

                scenario.AddExamples(new List <Example> {
                    new Example(exampleColumns, row)
                });
            }
            listenToParsedTable = false;
        }
コード例 #5
0
 public void ShouldBeSerializable()
 {
     var e = new ExampleColumns(new[] { "a", "b" });
     var ser = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     using (var ms = new MemoryStream())
         ser.Serialize(ms, e);
     Assert.IsTrue(true, "Serialization succeded");
 }
コード例 #6
0
ファイル: ExampleBuilder.cs プロジェクト: AngelPortal/NBehave
 private static ExampleColumns BuildColumnNames(string[] cols)
 {
     var theMiddle = cols.Length / 2;
     var columnNames = new ExampleColumns();
     for (int i = 0; i < theMiddle; i++)
         columnNames.Add(new ExampleColumn(cols[i].Trim()));
     return columnNames;
 }
コード例 #7
0
ファイル: ExampleColumnsSpec.cs プロジェクト: wmadzha/NBehave
        public void ShouldBeSerializable()
        {
            var e   = new ExampleColumns(new[] { "a", "b" });
            var ser = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            using (var ms = new MemoryStream())
                ser.Serialize(ms, e);
            Assert.IsTrue(true, "Serialization succeded");
        }
コード例 #8
0
ファイル: ExampleBuilder.cs プロジェクト: AngelPortal/NBehave
 private static Dictionary<string, string> BuildColumnValues(ExampleColumns columnNames, string[] cols)
 {
     var theMiddle = cols.Length / 2;
     var columnValues = new Dictionary<string, string>();
     for (int i = 0; i < theMiddle; i++)
     {
         string value = cols[1 + i + theMiddle].Trim();
         columnValues.Add(columnNames[i].Name, value);
     }
     return columnValues;
 }
コード例 #9
0
ファイル: ExampleSpec.cs プロジェクト: smhabdoli/NBehave
 public void EstablishContext()
 {
     const string colName = "colName";
     const string colValue = "a really wide column value";
     var columnNames = new ExampleColumns { new ExampleColumn(colName) };
     var columnValues = new Dictionary<string, string>
     {
         { "colName" , colValue }
     };
     _row = new Example(columnNames, columnValues);
 }
コード例 #10
0
        public void Should_create_table_instance_from_string()
        {
            var columnNames = new ExampleColumns(new[] { new ExampleColumn("colA"), new ExampleColumn("colB"), });
            var columnValues = new Dictionary<string, string> { { "colA", "A" }, { "colB", "B" } };
            var example = new Example(columnNames, columnValues);

            var str = example.ToString();
            var exampleFromString = ExampleBuilder.BuildFromString(str);

            CollectionAssert.AreEqual(exampleFromString.ColumnNames, example.ColumnNames);
            CollectionAssert.AreEqual(exampleFromString.ColumnValues, example.ColumnValues);
        }
コード例 #11
0
ファイル: XmlOutputWriter.cs プロジェクト: gpolunin/NBehave
        private void WriteColumnNames(ExampleColumns columnNames)
        {
            Writer.WriteStartElement("columnNames");

            foreach (var columnName in columnNames)
            {
                Writer.WriteStartElement("columnName");
                Writer.WriteString(columnName.Name);
                Writer.WriteEndElement();
            }

            Writer.WriteEndElement();
        }
コード例 #12
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");
        }
コード例 #13
0
ファイル: ExampleSpec.cs プロジェクト: wmadzha/NBehave
        public void EstablishContext()
        {
            const string colName     = "colName";
            const string colValue    = "a really wide column value";
            var          columnNames = new ExampleColumns {
                new ExampleColumn(colName)
            };
            var columnValues = new Dictionary <string, string>
            {
                { "colName", colValue }
            };

            _row = new Example(columnNames, columnValues);
        }
コード例 #14
0
        public void Should_create_table_instance_from_string()
        {
            var columnNames  = new ExampleColumns(new[] { new ExampleColumn("colA"), new ExampleColumn("colB"), });
            var columnValues = new Dictionary <string, string> {
                { "colA", "A" }, { "colB", "B" }
            };
            var example = new Example(columnNames, columnValues);

            var str = example.ToString();
            var exampleFromString = ExampleBuilder.BuildFromString(str);

            CollectionAssert.AreEqual(exampleFromString.ColumnNames, example.ColumnNames);
            CollectionAssert.AreEqual(exampleFromString.ColumnValues, example.ColumnValues);
        }
コード例 #15
0
 public void SetUp()
 {
     const string colC = "A really long column name";
     var columnNames = new ExampleColumns
                           {
                               new ExampleColumn("A"),
                               new ExampleColumn("B"),
                               new ExampleColumn(colC)
                           };
     examples = new List<Example>
                        {
                            new Example(columnNames, new Dictionary<string, string> {{"A", "12345"}, {"B", "b"}, {colC, "c"}}),
                            new Example(columnNames, new Dictionary<string, string> {{"A", "a"}, {"B", "123456"}, {colC, "c"}}),
                        };
     exampleTableFormatter = new ExampleTableFormatter();            
 }
コード例 #16
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");
        }
コード例 #17
0
        private void ExtractExamplesFromTable(IList<IList<Token>> table)
        {
            if (!listenToParsedTable)
                return;

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

            foreach (var list in table.Skip(1))
            {
                var example = list.Select(token => token.Content);
                var row = new Dictionary<string, string>();

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

                scenario.AddExamples(new List<Example> { new Example(exampleColumns, row) });
            }
            listenToParsedTable = false;
        }
コード例 #18
0
ファイル: ScenarioSpec.cs プロジェクト: smhabdoli/NBehave
 public void Should_include_examples_when_converting_to_string()
 {
     var feature = new Feature("featureTitle", "", "source", 1);
     var scenario = new Scenario("scenarioTitle", "source", feature, 3);
     scenario.AddStep(new StringStep("Given a [foo]", "source, 4"));
     scenario.AddStep(new StringStep("And [bar]", "source, 5"));
     var columnNames = new ExampleColumns { new ExampleColumn("foo"), new ExampleColumn("bar") };
     scenario.AddExamples(new[]
                              {
                                new Example(columnNames, new Dictionary<string, string>{ {"foo", "1"}, {"bar", "2"}}),
                                new Example(columnNames, new Dictionary<string, string>{ {"foo", "11"}, {"bar", "22"}})
                              });
     var scenarioAsString = scenario.ToString();
     string expected = string.Format("Scenario: scenarioTitle{0}  Given a [foo]{0}  And [bar]{0}", Environment.NewLine);
     expected += "Examples:" + Environment.NewLine +
                 "     | foo | bar |" + Environment.NewLine +
                 "     | 1 | 2 |" + Environment.NewLine +
                 "     | 11 | 22 |";
     Assert.AreEqual(expected, scenarioAsString);
 }
コード例 #19
0
        public void SetUp()
        {
            const string colC        = "A really long column name";
            var          columnNames = new ExampleColumns
            {
                new ExampleColumn("A"),
                new ExampleColumn("B"),
                new ExampleColumn(colC)
            };

            examples = new List <Example>
            {
                new Example(columnNames, new Dictionary <string, string> {
                    { "A", "12345" }, { "B", "b" }, { colC, "c" }
                }),
                new Example(columnNames, new Dictionary <string, string> {
                    { "A", "a" }, { "B", "123456" }, { colC, "c" }
                }),
            };
            exampleTableFormatter = new ExampleTableFormatter();
        }
コード例 #20
0
ファイル: Example.cs プロジェクト: smhabdoli/NBehave
 public Example(ExampleColumns columnNames, Dictionary<string, string> columnValues)
 {
     ColumnNames = columnNames;
     ColumnValues = new ColumnValues(columnValues);
 }
コード例 #21
0
ファイル: StepBuilder.cs プロジェクト: AngelPortal/NBehave
        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));
            }
        }
コード例 #22
0
        private void WriteColumnNames(ExampleColumns columnNames)
        {
            Writer.WriteStartElement("columnNames");

            foreach (var columnName in columnNames)
            {
                Writer.WriteStartElement("columnName");
                Writer.WriteString(columnName.Name);
                Writer.WriteEndElement();
            }

            Writer.WriteEndElement();
        }
コード例 #23
0
ファイル: StringTableStep.cs プロジェクト: smhabdoli/NBehave
 private void CloneTableSteps(StringTableStep clone)
 {
     foreach (var tableStep in TableSteps)
     {
         var clonedValues = tableStep.ColumnValues.ToDictionary(pair => pair.Key, pair => pair.Value);
         var clonedNames = new ExampleColumns(tableStep.ColumnNames);
         var clonedRow = new Example(clonedNames, clonedValues);
         clone.AddTableStep(clonedRow);
     }
 }