private void ProcessTestDocument(string document, StoryTestWriter writer)
 {
     try {
         var storyTest = new StoryTest(service, writer)
                         .WithInput(document)
                         .OnAbandonSuite(() => { suiteIsAbandoned = true; });
         reporter.WriteLine(storyTest.Leader);
         if (suiteSetupIdentifier.IsStartOf(storyTest.Leader) || IMaybeProcessingSuiteSetup)
         {
             storyTest.Execute();
         }
         else
         {
             storyTest.Execute(new Service.Service(service));
         }
     }
     catch (Exception e) {
         var testStatus = new TestStatus();
         var parse      = new CellBase(parseError, "div");
         parse.SetAttribute(CellAttribute.Body, parseError);
         testStatus.MarkException(parse, e);
         writer.WriteTable(new CellTree(parse));
         writer.WriteTest(new CellTree().AddBranchValue(parse), testStatus.Counts);
     }
 }
 public override void DoRow(Parse row)
 {
     if (row.Parts.Size != rowWidth)
     {
         TestStatus.MarkException(row.Parts, new RowWidthException(rowWidth));
     }
     else
     {
         try {
             TypedValue result = Processor.ExecuteWithThrow(this, memberNameCells,
                                                            valueCells.GetCells(row.Branches), row.Parts);
             if (result.Type != typeof(bool))
             {
                 throw new InvalidMethodException("Method does not return boolean.");
             }
             if (result.GetValue <bool>() == expectedCondition)
             {
                 TestStatus.MarkRight(row);
             }
             else
             {
                 TestStatus.MarkWrong(row);
             }
         }
         catch (ParseException <Cell> e) {
             TestStatus.MarkException(e.Subject, e.InnerException);
         }
     }
 }
示例#3
0
 private void ProcessTestDocument(string document, Action <string, TestCounts> writer)
 {
     try
     {
         Tree <Cell> result    = service.Compose(new StoryTestString(document));
         var         parse     = result != null ? (Parse)result.Value : null;
         var         storyTest = new StoryTest(parse, (tables, counts) => WriteResults(tables, counts, writer));
         reporter.WriteLine(parse.Leader);
         if (suiteSetupIdentifier.IsStartOf(parse.Leader) || IMaybeProcessingSuiteSetup)
         {
             storyTest.ExecuteOnConfiguration(service.Configuration);
         }
         else
         {
             storyTest.Execute(service.Configuration);
         }
     }
     catch (Exception e)
     {
         var testStatus = new TestStatus();
         var parse      = new CellBase(parseError, "div");
         parse.SetAttribute(CellAttribute.Body, parseError);
         testStatus.MarkException(parse, e);
         WriteResults(new CellTree().AddBranchValue(parse), testStatus.Counts, writer);
     }
 }
示例#4
0
        public override void DoRow(Parse theRow)
        {
            if (theRow.Parts.More.Size != firstRowCells.Size)
            {
                TestStatus.MarkException(theRow.Parts, new RowWidthException(firstRowCells.Size));
                return;
            }
            Parse headerCell = firstRowCells;

            foreach (Parse expectedValueCell in new CellRange(theRow.Parts.More).Cells)
            {
                try {
                    CellOperation.Check(GetTargetObject(), combineMember,
                                        new CellTree(theRow.Parts, headerCell),
                                        expectedValueCell);
                }
                catch (IgnoredException) {
                    TestStatus.MarkIgnore(expectedValueCell);
                }
                catch (Exception e) {
                    TestStatus.MarkException(expectedValueCell, e);
                }
                headerCell = headerCell.More;
            }
        }
示例#5
0
 public override void DoRow(Parse row)
 {
     if (row.Parts.Size != rowWidth)
     {
         TestStatus.MarkException(row.Parts, new RowWidthException(rowWidth));
     }
     else
     {
         try {
             TypedValue result = CellOperation.Invoke(this, memberNameCells,
                                                      valueCells.GetCells(new CellRange(row.Parts).Cells), row.Parts);
             if (result.Type != typeof(bool))
             {
                 throw new InvalidMethodException(string.Format("Method does not return boolean."));
             }
             if (result.GetValue <bool>() == expectedCondition)
             {
                 TestStatus.MarkRight(row);
             }
             else
             {
                 TestStatus.MarkWrong(row);
             }
         }
         catch (ParseException <Cell> e) {
             TestStatus.MarkException(e.Subject, e.InnerException);
         }
     }
 }
示例#6
0
 void ExecuteOptionalMethod(string theMethodName, Parse theCell)
 {
     try {
         Processor.Invoke(this, theMethodName, theCell);
     }
     catch (Exception e) {
         TestStatus.MarkException(theCell, e);
     }
 }
 void ExecuteOptionalMethod(MemberName theMethodName, Parse theCell)
 {
     try {
         Processor.Invoke(this, theMethodName, theCell); //todo: invokewiththrow?
     }
     catch (Exception e) {
         TestStatus.MarkException(theCell, e);
     }
 }
        public override void DoCell(Parse cell, int column)
        {
            Binding binding = ColumnBindings[column];

            try {
                binding.Do(cell);
            }
            catch (Exception e) {
                TestStatus.MarkException(cell, e);
            }
        }
示例#9
0
 public override void DoTable(Parse theTable)
 {
     if (theTable.Parts.More == null)
     {
         TestStatus.MarkException(theTable.Parts.Parts, new ApplicationException("Header row missing."));
     }
     else
     {
         DoRows(theTable.Parts.More);
     }
 }
示例#10
0
 public object ExecuteEmbeddedMethod(Parse theCells)
 {
     try {
         CellRange cells = CellRange.GetMethodCellRange(theCells, 0);
         return
             (CellOperation.Invoke(this, new CellRange(MethodCells(cells)), new CellRange(ParameterCells(cells)), theCells.More).
              Value);
     }
     catch (ParseException <Cell> e) {
         TestStatus.MarkException(e.Subject, e.InnerException);
         throw new IgnoredException();
     }
 }
示例#11
0
        // Traversal ////////////////////////////////

        public override void DoCells(Parse cells)
        {
            this.cells = cells;
            try
            {
                targetObject = this;
                CellOperation.Invoke(this, cells);
                targetObject = actor;
            }
            catch (Exception e)
            {
                TestStatus.MarkException(cells, e);
            }
        }
示例#12
0
        // Traversal ////////////////////////////////

        public override void DoCells(Parse cells)
        {
            this.cells = cells;
            try
            {
                targetObject = this;
                Processor.ExecuteWithThrow(this, cells);
                targetObject = actor;
            }
            catch (Exception e)
            {
                TestStatus.MarkException(cells, e);
            }
        }
 public override void DoRow(Parse row)
 {
     HasExecuted = false;
     try {
         Reset();
         base.DoRow(row);
         if (!HasExecuted)
         {
             Execute();
         }
     }
     catch (Exception e) {
         TestStatus.MarkException(row.Leaf, e);
     }
 }
示例#14
0
 public virtual void DoCells(Parse cells)
 {
     for (int i = 0; cells != null; i++)
     {
         try
         {
             DoCell(cells, i);
         }
         catch (Exception e)
         {
             TestStatus.MarkException(cells, e);
         }
         cells = cells.More;
     }
 }
示例#15
0
 public override void DoRow(Parse theRow)
 {
     try {
         if (theRow.Parts.Size != headerCells.Size)
         {
             throw new FitFailureException(String.Format("Row should be {0} cells wide.", headerCells.Size));
         }
         Processor.ExecuteWithThrow(this, new CellRange(headerCells), new CellRange(theRow.Parts), theRow.Parts);
     }
     catch (MemberMissingException e) {
         TestStatus.MarkException(headerCells, e);
         throw new IgnoredException();
     }
     catch (Exception e) {
         TestStatus.MarkException(theRow.Parts, e);
     }
 }
 public bool FinalCheck(TestStatus testStatus)
 {
     if (myColumnsUsed == null)
     {
         return(true);
     }
     for (int column = 0; column < myHeaderRow.Branches.Count; column++)
     {
         if (myColumnsUsed[column])
         {
             continue;
         }
         testStatus.MarkException(myHeaderRow.Branches[column].Value,
                                  new FitFailureException(String.Format("Column '{0}' not used.", myHeaderRow.Branches[column].Value.Text)));
         return(false);
     }
     return(true);
 }
        private void ProcessCells(Parse cells, Func <Binding, bool> bindingFilter)
        {
            int i = 0;

            for (Parse cell = cells; cell != null && i < ColumnBindings.Length; cell = cell.More, i++)
            {
                if (!bindingFilter(ColumnBindings[i]))
                {
                    continue;
                }
                try {
                    DoCell(cell, i);
                }
                catch (Exception e) {
                    TestStatus.MarkException(cells, e);
                }
            }
        }
示例#18
0
        void ProcessRestOfTable(Interpreter theFixture, Parse theRestOfTheRows)
        {
            var restOfTable = new Parse("table", "", theRestOfTheRows, null);

            theFixture.Processor = Processor;
            var fixture = theFixture as Fixture;

            if (fixture != null)
            {
                fixture.Prepare(this, restOfTable);
            }
            try {
                ExecuteStoryTest.DoTable(restOfTable, theFixture, false);
            }
            catch (Exception e) {
                TestStatus.MarkException(theRestOfTheRows.Parts, e);
            }
        }
示例#19
0
 public override void DoRow(Parse row)
 {
     HasExecuted = false;
     try
     {
         Reset();
         base.DoRow(row);
         if (!HasExecuted)
         {
             var CurrentRow = table.NewRow();
             foreach (DbParameterAccessor accessor in accessors)
             {
                 CurrentRow[accessor.DbParameter.ParameterName] = accessor.DbParameter.Value;
             }
             table.Rows.Add(CurrentRow);
         }
     }
     catch (Exception e)
     {
         TestStatus.MarkException(row.Leaf, e);
     }
 }
示例#20
0
 private void ExamineTableStructure(Parse theHeaderCells)
 {
     expectedCount    = 0;
     IHaveNoteColumns = false;
     try {
         myParameterCount  = CountParameterCells(theHeaderCells);
         methodSuffixCells = new CellRange(theHeaderCells, myParameterCount);
         headerCells       = theHeaderCells.At(myParameterCount + 1);
         foreach (Parse headerCell in new CellRange(theHeaderCells.At(myParameterCount + 1)).Cells)
         {
             if (headerCell.Text.Length == 0)
             {
                 IHaveNoteColumns = true;
                 break;
             }
             expectedCount++;
         }
     }
     catch (Exception e) {
         TestStatus.MarkException(theHeaderCells, e);
     }
 }
示例#21
0
        public override void DoRow(Parse theRow)
        {
            try {
                CheckRowSize(theRow.Parts);

                for (int j = 0; j < expectedCount; j++)
                {
                    var memberCells = new List <Parse> {
                        headerCells.At(j)
                    };
                    foreach (Parse cell in methodSuffixCells.Cells)
                    {
                        memberCells.Add(cell);
                    }

                    Parse expectedCell = theRow.Parts.At(myParameterCount + j + 1);

                    try {
                        CellOperation.Check(GetTargetObject(), new CellRange(memberCells),
                                            myValues.GetCells(new CellRange(theRow.Parts, myParameterCount).Cells),
                                            expectedCell);
                    }
                    catch (MemberMissingException e) {
                        TestStatus.MarkException(headerCells.At(j), e);
                        TestStatus.MarkIgnore(expectedCell);
                    }
                    catch (IgnoredException) {
                        TestStatus.MarkIgnore(expectedCell);
                    }
                    catch (Exception e) {
                        TestStatus.MarkException(expectedCell, e);
                    }
                }
            }
            catch (Exception e) {
                TestStatus.MarkException(theRow.Parts, e);
            }
        }
示例#22
0
        public override void DoRow(Parse theRow)
        {
            try {
                CheckRowSize(theRow.Parts);

                for (int j = 0; j < expectedCount; j++)
                {
                    var memberCells = new CellTree();
                    memberCells.AddBranch(headerCells.At(j));
                    foreach (var suffixCell in methodSuffixCells.Cells)
                    {
                        memberCells.AddBranch(suffixCell);
                    }

                    Parse expectedCell = theRow.Parts.At(myParameterCount + j + 1);

                    try {
                        Processor.Check(GetTargetObject(), memberCells,
                                        myValues.GetCells(theRow.Branches.Take(myParameterCount)),
                                        expectedCell);
                    }
                    catch (MemberMissingException e) {
                        TestStatus.MarkException(headerCells.At(j), e);
                        TestStatus.MarkIgnore(expectedCell);
                    }
                    catch (IgnoredException) {
                        TestStatus.MarkIgnore(expectedCell);
                    }
                    catch (Exception e) {
                        TestStatus.MarkException(expectedCell, e);
                    }
                }
            }
            catch (Exception e) {
                TestStatus.MarkException(theRow.Parts, e);
            }
        }
示例#23
0
 protected void ProcessFlowRow(Parse theCurrentRow)
 {
     try {
         string specialActionName = RuntimeDirect.MakeDirect(
             Processor.ParseTree <Cell, MemberName>(new CellRange(theCurrentRow.Parts, 1)).ToString());
         TypedValue result = Processor.Invoke(new FlowKeywords(this), specialActionName, theCurrentRow.Parts);
         if (!result.IsValid)
         {
             result = Processor.Invoke(this, specialActionName, theCurrentRow.Parts);
         }
         if (!result.IsValid)
         {
             result = CellOperation.TryInvoke(this,
                                              new CellRange(MethodCells(new CellRange(theCurrentRow.Parts))),
                                              new CellRange(ParameterCells(new CellRange(theCurrentRow.Parts))),
                                              theCurrentRow.Parts);
         }
         if (!result.IsValid)
         {
             if (theCurrentRow.Parts.Text.Length > 0)
             {
                 var newFixture = Processor.ParseTree <Cell, Interpreter>(theCurrentRow);
                 var adapter    = newFixture as MutableDomainAdapter;
                 if (adapter != null)
                 {
                     adapter.SetSystemUnderTest(SystemUnderTest);
                 }
                 ProcessRestOfTable(newFixture, theCurrentRow);
                 IHaveFinishedTable = true;
             }
             else
             {
                 result.ThrowExceptionIfNotValid();
             }
         }
         else
         {
             if (TestStatus.IsAbandoned)
             {
                 TestStatus.MarkIgnore(theCurrentRow);
                 return;
             }
             object wrapResult = FixtureResult.Wrap(result.Value);
             if (wrapResult is bool)
             {
                 ColorMethodName(theCurrentRow.Parts, (bool)wrapResult);
             }
             else if (wrapResult is Fixture)
             {
                 ProcessRestOfTable((Fixture)wrapResult, theCurrentRow);
                 IHaveFinishedTable = true;
                 return;
             }
         }
     }
     catch (IgnoredException) {}
     catch (ParseException <Cell> e) {
         TestStatus.MarkException(e.Subject, e);
         IHaveFinishedTable = true;
     }
     catch (Exception e) {
         TestStatus.MarkException(theCurrentRow.Parts, e);
         IHaveFinishedTable = true;
     }
 }
示例#24
0
 public virtual void Exception(Parse cell, Exception exception)
 {
     TestStatus.MarkException(cell, exception);
 }