Navigation Menu

Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestockdale committed Apr 22, 2016
1 parent 703e090 commit 8cab6d1
Show file tree
Hide file tree
Showing 29 changed files with 335 additions and 312 deletions.
11 changes: 5 additions & 6 deletions source/dbfitTest/QueryTest.cs
@@ -1,4 +1,4 @@
// Copyright © 2010 Syterra Software Inc. All rights reserved.
// Copyright © 2016 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.
Expand All @@ -7,7 +7,6 @@
using dbfit.fixture;
using fit;
using fit.Service;
using fitSharp.Fit.Model;
using fitSharp.Machine.Model;
using NUnit.Framework;
using TestStatus=fitSharp.Fit.Model.TestStatus;
Expand Down Expand Up @@ -40,10 +39,10 @@ public class QueryTest {
dataTable.Rows.Add(newRow);
var fixture = new Query(dataTable, false) {Processor = new Service()};

var testTable = new CellBaseTree(
new CellBaseTree("query"),
new CellBaseTree("somekey", headerCellName),
new CellBaseTree("key", "value")
var testTable = new CellTree(
new CellTree("query"),
new CellTree("somekey", headerCellName),
new CellTree("key", "value")
);
Parse parseTable = Parse.CopyFrom(testTable);
fixture.DoTable(parseTable);
Expand Down
12 changes: 6 additions & 6 deletions source/fit/Model/Parse.cs
@@ -1,4 +1,4 @@
// Copyright © 2012 Syterra Software Inc. Includes work by Object Mentor, Inc., © 2002 Cunningham & Cunningham, Inc.
// Copyright © 2016 Syterra Software Inc. Includes work by Object Mentor, Inc., © 2002 Cunningham & Cunningham, Inc.
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -23,7 +23,7 @@ public class Parse: CellBase, Tree<Cell>
}

public static Parse ParseRootFrom(string input) {
return CopyFrom(new HtmlTables().Parse(input));
return (Parse)new HtmlTables(text => new Parse(new CellBase(text))).Parse(input);
}

public Parse More { get; set; }
Expand Down Expand Up @@ -79,7 +79,7 @@ public virtual void AddToBody(string text)
this.SetAttribute(CellAttribute.InformationSuffix, text);
}

Parse(CellBase source): base(source) {}
public Parse(CellBase source) : base(source) {}

Parse(Parse other)
: base(other) {
Expand Down Expand Up @@ -217,9 +217,9 @@ public virtual string Footnote
return new Parse(this);
}

public static Parse CopyFrom(Tree<CellBase> source) {
var result = new Parse(source.Value);
foreach (Tree<CellBase> branch in source.Branches) {
public static Parse CopyFrom(Tree<Cell> source) {
var result = new Parse((CellBase)source.Value);
foreach (var branch in source.Branches) {
Parse newBranch = CopyFrom(branch);
if (result.Parts == null) {
result.Parts = newBranch;
Expand Down
25 changes: 0 additions & 25 deletions source/fit/Operators/ComposeHtmlStoryTestString.cs

This file was deleted.

25 changes: 0 additions & 25 deletions source/fit/Operators/ComposeStoryTestString.cs

This file was deleted.

22 changes: 0 additions & 22 deletions source/fit/Operators/ComposeTextStoryTestString.cs

This file was deleted.

63 changes: 7 additions & 56 deletions source/fit/Runner/FolderRunner.cs
@@ -1,75 +1,26 @@
// Copyright © 2011 Syterra Software Inc.
// Copyright © 2016 Syterra Software Inc.
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

using System;
using System.Collections.Generic;
using fitSharp.Fit.Application;
using fitSharp.Fit.Runner;
using fitSharp.IO;
using fitSharp.Machine.Application;
using fitSharp.Machine.Engine;

namespace fit.Runner {
public class FolderRunner: Runnable {

public int Run(IList<string> commandLineArguments, Memory memory, ProgressReporter reporter) {
var now = DateTime.Now;
myProgressReporter = reporter;
var result = Run(memory, commandLineArguments);
//todo: to suiterunner?
if (!memory.GetItem<Settings>().DryRun)
reporter.Write(string.Format("\n{0}, time: {1}\n", Results, DateTime.Now - now));
return result;
public FolderRunner() {
runner = new fitSharp.Fit.Runner.SuiteRunnerShell();
}

public string Results {get { return myRunner.TestCounts.Description; }}


ProgressReporter myProgressReporter;
SuiteRunner myRunner;
string selectedFile;

int Run(Memory memory, IList<string> arguments) {
ParseArguments(memory, arguments);
var fileSystem = new FileSystemModel(memory.GetItem<Settings>().CodePageNumber);
memory.GetItem<Context>().PageSource = fileSystem;
memory.GetItem<Context>().SuitePath = new DirectoryPath(memory.GetItem<Settings>().InputFolder);
myRunner = new SuiteRunner(memory, myProgressReporter);
myRunner.Run(
CreateStoryTestFolder(memory, fileSystem),
selectedFile);
return myRunner.TestCounts.FailCount;
}

void ParseArguments(Memory memory, IList<string> arguments) {
if (arguments.Count == 0) {
return;
}
var argumentParser = new ArgumentParser();
argumentParser.AddSwitchHandler("d", () => memory.GetItem<Settings>().DryRun = true);
argumentParser.AddArgumentHandler("i", value => memory.GetItem<Settings>().InputFolder = value);
argumentParser.AddArgumentHandler("o", value => memory.GetItem<Settings>().OutputFolder = value);
argumentParser.AddArgumentHandler("s", value => selectedFile = value);
argumentParser.AddArgumentHandler("x", value => memory.GetItem<FileExclusions>().AddRange(value.Split(';')));
argumentParser.AddArgumentHandler("t", value => memory.GetItem<Settings>().TagList = value);

argumentParser.Parse(arguments);
if (memory.GetItem<Settings>().InputFolder == null)
throw new FormatException("Missing input folder");
if (memory.GetItem<Settings>().OutputFolder == null)
throw new FormatException("Missing output folder");
public int Run(IList<string> commandLineArguments, Memory memory, ProgressReporter reporter) {
return runner.Run(commandLineArguments, memory, reporter, m => new Service.Service(m));
}

StoryTestFolder CreateStoryTestFolder(Memory memory, FolderModel folderModel) {
var storyTestFolder = new StoryTestFolder(memory, folderModel);

string tagList = memory.GetItem<Settings>().TagList;
if (!string.IsNullOrEmpty(tagList))
storyTestFolder.AddPageFilter(new TagFilter(tagList));
public string Results { get { return runner.Results; } }

return storyTestFolder;
}
readonly fitSharp.Fit.Runner.SuiteRunnerShell runner;
}
}
7 changes: 1 addition & 6 deletions source/fit/Service/Operators.cs
@@ -1,4 +1,4 @@
// Copyright © 2011 Syterra Software Inc.
// Copyright © 2016 Syterra Software Inc.
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -13,13 +13,8 @@ namespace fit.Service {
public class Operators: CellOperators, Copyable {

public Operators() {
Add(new ComposeShowAsOperator(), 0);

Add(new InvokeProcedure(), 0);

Add(new ComposeStoryTestString(), 0);
Add(new ParseStoryTestString(), 0);

Add(new ComposeTable(), 0);
Add(new ListOperator(), 0);
Add(new CompareList(), 0);
Expand Down
7 changes: 4 additions & 3 deletions source/fit/Service/Service.cs
@@ -1,4 +1,4 @@
// Copyright © 2012 Syterra Software Inc.
// Copyright © 2016 Syterra Software Inc.
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -16,7 +16,6 @@ public class Service: CellProcessorBase {

public Service(Memory memory): base(memory, memory.GetItem<Operators>()) {
ApplicationUnderTest.AddNamespace("fit");
ApplicationUnderTest.AddNamespace("fitSharp.Fit.Fixtures");
ApplicationUnderTest.AddAssembly(Assembly.GetExecutingAssembly().CodeBase);
memory.GetItem<Operators>().AddNamespaces(ApplicationUnderTest);
}
Expand All @@ -32,7 +31,9 @@ public class Service: CellProcessorBase {
}

public override Tree<Cell> MakeCell(string text, string tag, IEnumerable<Tree<Cell>> branches) {
var result = new Parse(tag, text, null, null);
var result = new Parse(new CellBase(text));
if (!string.IsNullOrEmpty(tag)) result.Value.SetTag(tag);
if (!string.IsNullOrEmpty(text)) result.Value.SetAttribute(CellAttribute.Body, text);
foreach (var branch in branches) {
result.Add(branch);
}
Expand Down
4 changes: 0 additions & 4 deletions source/fit/fit.csproj
Expand Up @@ -48,16 +48,12 @@
<Compile Include="Fixtures\RowEntryFixture.cs" />
<Compile Include="Operators\ArrayMatchStrategy.cs" />
<Compile Include="Operators\CompareList.cs" />
<Compile Include="Operators\ComposeHtmlStoryTestString.cs" />
<Compile Include="Operators\ComposeStoryTestString.cs" />
<Compile Include="Operators\ComposeTextStoryTestString.cs" />
<Compile Include="Operators\NamedMatchStrategy.cs" />
<Compile Include="Operators\InvokeProcedure.cs" />
<Compile Include="Runner\FitSocket.cs" />
<Compile Include="Runner\FolderRunner.cs" />
<Compile Include="Runner\HttpRunner.cs" />
<Compile Include="Runner\SocketServer.cs" />
<Compile Include="Runner\SuiteRunner.cs" />
<Compile Include="Service\Operators.cs" />
<Compile Include="Service\Service.cs" />
<Compile Include="Exception\RowWidthException.cs" />
Expand Down
5 changes: 4 additions & 1 deletion source/fitSharp/Fit/Operators/CellOperators.cs
@@ -1,4 +1,4 @@
// Copyright © 2015 Syterra Software Inc. All rights reserved.
// Copyright © 2016 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.
Expand All @@ -13,10 +13,13 @@ public class CellOperators: Operators<Cell, CellProcessor> {

public CellOperators() {
Add(new ComposeDefault(), 0);
Add(new ComposeStoryTestString(), 0);
Add(new ComposeShowAsOperator(), 0);
Add(new ExecuteDefault(), 0);
Add(new InvokeDataRow<Cell, CellProcessor>(), 0);
Add(new InvokeSetUpTearDown(), 0);
Add(new ParseDefault(), 0);
Add(new ParseStoryTestString(), 0);
Add(new ParseMemberName(), 0);
Add(new ParseBoolean(), 0);
Add(new ParseDate(), 0);
Expand Down
37 changes: 37 additions & 0 deletions source/fitSharp/Fit/Operators/ComposeStoryTestString.cs
@@ -0,0 +1,37 @@
// Copyright © 2016 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using fitSharp.Fit.Engine;
using fitSharp.Fit.Model;
using fitSharp.Machine.Application;
using fitSharp.Machine.Engine;
using fitSharp.Machine.Model;
using fitSharp.Parser;

namespace fitSharp.Fit.Operators {
public class ComposeStoryTestString: CellOperator, ComposeOperator<Cell> {
public bool CanCompose(TypedValue instance) {
return instance.Type == typeof(StoryTestString);
}

public Tree<Cell> Compose(TypedValue instance) {
var storyTestInput = instance.ValueString;
if (storyTestInput.Contains(Characters.TextStoryTestBegin)) {
return new TextTables(
new TextTableScanner(instance.ValueString, c => c == CharacterType.Letter),
MakeTreeCell)
.Parse();
}
else {
HtmlString.IsStandard = Processor.Get<Settings>().IsStandard;
return new HtmlTables(MakeTreeCell).Parse(instance.ValueString);
}
}

Tree<Cell> MakeTreeCell(string text) {
return Processor.MakeCell(text, string.Empty, new TreeList<Cell>[] {});
}
}
}
28 changes: 28 additions & 0 deletions source/fitSharp/Fit/Runner/FolderRunner.cs
@@ -0,0 +1,28 @@
// Copyright © 2016 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using System.Collections.Generic;
using fitSharp.Fit.Operators;
using fitSharp.Fit.Service;
using fitSharp.IO;
using fitSharp.Machine.Application;
using fitSharp.Machine.Engine;

namespace fitSharp.Fit.Runner {
public class FolderRunner: Runnable {

public FolderRunner() {
runner = new SuiteRunnerShell();
}

public int Run(IList<string> commandLineArguments, Memory memory, ProgressReporter reporter) {
return runner.Run(commandLineArguments, memory, reporter, m => new CellProcessorBase(m, m.GetItem<CellOperators>()));
}

public string Results { get { return runner.Results; } }

readonly SuiteRunnerShell runner;
}
}

0 comments on commit 8cab6d1

Please sign in to comment.