Permalink
Browse files

clean up

  • Loading branch information...
1 parent 8ddc9ce commit 9de644828f35e7f05e4d3a05c0030152b38985d7 jediwhale committed Sep 10, 2009
View
@@ -13,3 +13,4 @@ mwiki/
my*.*
*.pdb
testoutput/
+my*/
@@ -158,7 +158,7 @@ public abstract class FlowFixtureBase: Fixture {
var restOfTable = new Parse("table", "", theRestOfTheRows, null);
theFixture.Prepare(this, restOfTable);
try {
- StoryTest.DoTable(restOfTable, theFixture, false);
+ ExecuteStoryTest.DoTable(restOfTable, theFixture, false);
}
catch (Exception e) {
TestStatus.MarkException(theRestOfTheRows.Parts, e);
@@ -23,11 +23,10 @@ public class FitServer: Runnable
private Socket clientSocket;
private SocketStream socketStream;
- private bool verbose = false;
+ private bool verbose;
private string host;
private int port;
private string socketToken;
- public FixtureListener fixtureListener;
private bool IMaybeProcessingSuiteSetup = true;
private Configuration configuration;
@@ -36,17 +35,17 @@ public class FitServer: Runnable
private const int PORT = 2;
private const int SOCKET_TOKEN = 3;
private const int DONE = 4;
+ private static readonly IdentifierName ourSuiteSetupIdentifier = new IdentifierName("suitesetup");
public static int Main(string[] CommandLineArguments)
{
- FitServer fitServer = new FitServer();
+ var fitServer = new FitServer();
fitServer.Run(CommandLineArguments);
return fitServer.ExitCode();
}
public FitServer() {
Status = new TestStatus();
- fixtureListener = new TablePrintingFixtureListener(this);
}
public FitServer(Configuration configuration, string host, int port, bool verbose) : this()
@@ -111,7 +110,7 @@ private static void PrintUsageAndExit()
public void ParseAssemblyList(string path)
{
- PathParser parser = new PathParser(path);
+ var parser = new PathParser(path);
foreach (string assemblyPath in parser.AssemblyPaths) {
if (assemblyPath == "defaultPath") continue;
configuration.GetItem<ApplicationUnderTest>().AddAssembly(assemblyPath.Replace("\"", string.Empty));
@@ -127,7 +126,7 @@ public int Run(string[] CommandLineArguments)
EstablishConnection();
ValidateConnection();
- int errorCount = ProcessTestDocuments();
+ int errorCount = ProcessTestDocuments(WriteFitProtocol);
CloseConnection();
Exit();
return errorCount;
@@ -177,16 +176,14 @@ public void ValidateConnection()
}
}
- public int ProcessTestDocuments()
+ public int ProcessTestDocuments(WriteTestResult writer)
{
string document;
while ((document = ReceiveDocument()).Length > 0)
{
WriteLogMessage("processing document of size: " + document.Length);
- TestStatus currentStatus = ProcessTestDocument(document);
- Status.TallyCounts(currentStatus);
- WriteLogMessage("\tresults: " + currentStatus.CountDescription);
+ ProcessTestDocument(document, writer);
IMaybeProcessingSuiteSetup = false;
}
WriteLogMessage("\ncompletion signal recieved");
@@ -199,32 +196,25 @@ public int ExitCode()
return Status.FailCount;
}
- private TestStatus ProcessTestDocument(string document)
- {
- return RunTest(document);
- }
-
- private TestStatus RunTest(string document)
+ private void ProcessTestDocument(string document, WriteTestResult writer)
{
try
{
Tree<Cell> result = configuration.GetItem<Service>().Compose(new StoryTestString(document));
var parse = result != null ? (Parse)result.Value : null;
- StoryTest storyTest = new StoryTest(parse, fixtureListener);
+ var storyTest = new StoryTest(parse, writer);
WriteLogMessage(parse.Leader);
if (ourSuiteSetupIdentifier.IsStartOf(parse.Leader) || IMaybeProcessingSuiteSetup)
storyTest.ExecuteOnConfiguration();
else
storyTest.Execute();
- return storyTest.TestStatus;
}
catch (Exception e)
{
- Fixture fixture = new Fixture();
- Parse parse = new Parse("body", "Unable to parse input. Input ignored.", null, null);
- fixture.Exception(parse, e);
- fixtureListener.TableFinished(parse);
- return fixture.TestStatus;
+ var testStatus = new TestStatus();
+ var parse = new Parse("div", "Unable to parse input. Input ignored.", null, null);
+ testStatus.MarkException(parse, e);
+ writer(parse, testStatus);
}
}
@@ -241,7 +231,7 @@ public void WriteLogMessage(string logMessage)
private static Socket SocketConnectionTo(string hostName, int port)
{
- Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect(hostName, port);
return clientSocket;
}
@@ -269,9 +259,9 @@ public int DecodeInteger(string encodedInteger)
return Convert.ToInt32(encodedInteger);
}
- private static string ReadFixedLengthString(StreamReader reader, int stringLength)
+ private static string ReadFixedLengthString(TextReader reader, int stringLength)
{
- char[] numberCharacters = new char[stringLength];
+ var numberCharacters = new char[stringLength];
reader.Read(numberCharacters, 0, stringLength);
return new StringBuilder(stringLength).Append(numberCharacters).ToString();
@@ -294,29 +284,17 @@ public string ReadFrom(StreamReader reader)
return ReadFixedLengthString(reader, contentLength);
}
- private static readonly IdentifierName ourSuiteSetupIdentifier = new IdentifierName("suitesetup");
- }
-
- public class TablePrintingFixtureListener : FixtureListener
- {
- private FitServer fitServer;
-
- public TablePrintingFixtureListener(FitServer fitServer)
- {
- this.fitServer = fitServer;
- }
-
- public void TableFinished(Parse finishedTable) {}
+ private void WriteFitProtocol(Parse theTables, TestStatus status)
+ {
+ string testResultDocument = TablesToString(theTables);
+ WriteLogMessage("\tTransmitting tables of length " + testResultDocument.Length);
+ Transmit(Protocol.FormatDocument(testResultDocument));
- public void TablesFinished(Parse theTables, TestStatus status)
- {
- string testResultDocument = fitServer.TablesToString(theTables);
- fitServer.WriteLogMessage("\tTransmitting tables of length " + testResultDocument.Length);
- fitServer.Transmit(Protocol.FormatDocument(testResultDocument));
+ WriteLogMessage("\tTest Document finished");
+ Transmit(Protocol.FormatCounts(status));
- fitServer.WriteLogMessage("\tTest Document finished");
- fitServer.Transmit(Protocol.FormatCounts(status));
- }
-
+ Status.TallyCounts(status);
+ WriteLogMessage("\tresults: " + status.CountDescription);
+ }
}
-}
+}
@@ -1,14 +0,0 @@
-// Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
-// Copyright (c) 2002 Cunningham & Cunningham, Inc.
-// Released under the terms of the GNU General Public License version 2 or later.
-
-using fitSharp.Fit.Model;
-
-namespace fit
-{
- public interface FixtureListener
- {
- void TableFinished(Parse finishedTable);
- void TablesFinished(Parse theTables, TestStatus status);
- }
-}
@@ -1,19 +0,0 @@
-// Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
-// Copyright (c) 2002 Cunningham & Cunningham, Inc.
-// Released under the terms of the GNU General Public License version 2 or later.
-
-using fitSharp.Fit.Model;
-
-namespace fit
-{
- public class NullFixtureListener : FixtureListener
- {
- public void TableFinished(Parse finishedTable)
- {
- }
-
- public void TablesFinished(Parse theTables, TestStatus status)
- {
- }
- }
-}
@@ -15,33 +15,31 @@
namespace fit {
public interface StoryCommand {
void Execute();
- TestStatus TestStatus { get; }
}
public class StoryTest: StoryCommand {
- public TestStatus TestStatus { get; private set; }
+ private WriteTestResult writer;
+ private Parse resultTables;
- public FixtureListener Listener { get; private set; }
public Parse Tables { get; private set; }
public static Parse TestResult(Parse theTest) {
- var listener = new SpecifyListener();
- var story = new StoryTest(theTest, listener);
+ var story = new StoryTest(theTest);
+ story.writer = story.SaveTestResult;
story.Execute();
- return listener.Tables;
+ return story.resultTables;
}
public StoryTest() {
- Listener = new NullFixtureListener();
- TestStatus = new TestStatus();
+ writer = (t, s) => {};
}
public StoryTest(Parse theTables): this() {
Tables = theTables;
}
- public StoryTest(Parse theTables, FixtureListener theListener): this(theTables) {
- Listener = theListener;
+ public StoryTest(Parse theTables, WriteTestResult writer): this(theTables) {
+ this.writer = writer;
}
public void Execute() {
@@ -67,27 +65,51 @@ public class StoryTest: StoryCommand {
}
private void DoTables() {
- TestStatus.Summary["run date"] = DateTime.Now;
- TestStatus.Summary["run elapsed time"] = new RunTime();
- Parse heading = Tables.At(0, 0, 0);
- try {
- object instance = Fixture.LoadClass(Tables.At(0, 0, 0).Text);
- myFirstFixture = instance as Fixture;
- if (myFirstFixture == null) {
- myFirstFixture = new DoFixture(instance);
+ new ExecuteStoryTest(writer).DoTables(Tables);
+ }
+
+ private void SaveTestResult(Parse theTables, TestStatus status) {
+ for (Parse table = theTables; table != null; table = table.More) {
+ Parse newTable = table.Copy();
+ if (resultTables == null) {
+ resultTables = newTable;
}
+ else {
+ resultTables.Last.More = newTable;
+ }
+ }
+ }
+ }
+
+ public delegate void WriteTestResult(Parse tables, TestStatus status);
+
+ public class ExecuteStoryTest {
+ private readonly WriteTestResult writer;
+ private readonly TestStatus testStatus;
+
+ public ExecuteStoryTest(WriteTestResult writer) {
+ this.writer = writer;
+ testStatus = new TestStatus();
+ }
+
+ public TestStatus DoTables(Parse tables) {
+ testStatus.Summary["run date"] = DateTime.Now;
+ testStatus.Summary["run elapsed time"] = new RunTime();
+ Parse heading = tables.At(0, 0, 0);
+ Fixture myFirstFixture;
+ try {
+ object instance = Fixture.LoadClass(tables.At(0, 0, 0).Text);
+ myFirstFixture = instance as Fixture ?? new DoFixture(instance);
}
catch (Exception e) {
- myFirstFixture = new Fixture();
- myFirstFixture.TestStatus = TestStatus;
- TestStatus.MarkException(heading, e);
- Listener.TableFinished(Tables);
- Listener.TablesFinished(Tables, TestStatus);
- return;
+ testStatus.MarkException(heading, e);
+ writer(tables, testStatus);
+ return testStatus;
}
- myFirstFixture.TestStatus = TestStatus;
+ myFirstFixture.TestStatus = testStatus;
myFirstFixture.Processor = Context.Configuration.GetItem<Service.Service>();
- DoTables(myFirstFixture, Tables);
+ DoTables(myFirstFixture, tables);
+ return testStatus;
}
private void DoTables(Fixture firstFixture, Parse theTables) {
@@ -98,7 +120,7 @@ public class StoryTest: StoryCommand {
try {
try {
Parse heading = table.At(0, 0, 0);
- if (heading != null && !TestStatus.IsAbandoned) {
+ if (heading != null && !testStatus.IsAbandoned) {
if (flowFixture == null) {
object instance = Fixture.LoadClass(heading.Text);
var activeFixture = instance as Fixture ?? new DoFixture(instance);
@@ -113,20 +135,18 @@ public class StoryTest: StoryCommand {
}
}
catch (Exception e) {
- TestStatus.MarkException(table.At(0, 0, 0), e);
+ testStatus.MarkException(table.At(0, 0, 0), e);
}
}
catch (AbandonStoryTestException) {}
- Listener.TableFinished(table);
tableCount++;
}
if (flowFixture != null) flowFixture.DoTearDown(theTables);
}
catch (Exception e) {
- TestStatus.MarkException(theTables.Parts.Parts, e);
- Listener.TableFinished(theTables);
+ testStatus.MarkException(theTables.Parts.Parts, e);
}
- Listener.TablesFinished(theTables, TestStatus);
+ writer(theTables, testStatus);
}
public static void DoTable(Parse table, Fixture activeFixture, bool inFlow) {
@@ -135,27 +155,5 @@ public class StoryTest: StoryCommand {
activeFixture.DoTable(table);
if (activeFlowFixture != null && !inFlow) activeFlowFixture.DoTearDown(table);
}
-
- private Fixture myFirstFixture;
-
- private class SpecifyListener: FixtureListener {
-
- public void TablesFinished(Parse theTables, TestStatus status) {}
-
- public void TableFinished(Parse finishedTable) {
- Parse newTable = finishedTable.Copy();
- if (myTables == null) {
- myTables = newTable;
- }
- else {
- myTables.Last.More = newTable;
- }
- }
-
- public Parse Tables {get {return myTables;}}
-
- private Parse myTables;
-
- }
}
}
Oops, something went wrong.

0 comments on commit 9de6448

Please sign in to comment.