Revision: 54
Author: goeran.hansen
Date: Tue Sep 8 01:30:22 2009
Log: more work on the Scenario dsl. Going good!
http://code.google.com/p/tinybdd/source/detail?r=54
Added:
/trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassDslTests.cs
Modified:
/trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs
/trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs
/trunk/TinyBDDTests/TinyBDDTests.csproj
=======================================
--- /dev/null
+++ /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassDslTests.cs Tue Sep
8 01:30:22 2009
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TinyBDD.Dsl.GivenWhenThen;
+using NUnit.Framework;
+
+namespace TinyBDDTests.Dsl.GivenWhenThen.ScenarioClassDslTests
+{
+ public class Shared : ScenarioClass
+ {
+ protected Context there_are_changesets_in_sourceControl = () => {
};
+ protected When Controller_notified_to_refresh = () => { };
+ protected Then assure_all_changesets_are_received = () => { };
+
+ [TearDown]
+ public void Haldis()
+ {
+ Run();
+ }
+ }
+
+ [TestFixture]
+ public class When_describing_Scenario : Shared
+ {
+ [SetUp]
+ public void Setup()
+ {
+ Given(there_are_changesets_in_sourceControl).
+ And("controller has been created");
+
+ When(Controller_notified_to_refresh);
+
+ Then(assure_all_changesets_are_received).
+ And("they are ordered by Revision");
+
+ }
+
+ [Test]
+ public void Assure_arranges_been_added_to_the_SemanticModel()
+ {
+ //Run();
+ }
+ }
+
+ [TestFixture]
+ public class When_describing_empty_Scenario : Shared
+ {
+ [Test]
+ public void Test()
+ {
+ Scenario("");
+ Given("there are changesets in sourceControl");
+ //Run();
+ }
+ }
+}
=======================================
--- /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Tue Sep 8 00:22:46
2009
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Tue Sep 8 01:30:22
2009
@@ -6,20 +6,33 @@
namespace TinyBDD.Dsl.GivenWhenThen
{
- public class ScenarioClass<TClass>
+ public class ScenarioClass
{
private AAA semanticModel;
+ private AAAMemento semanticModelState;
private Semantics scenario;
-
- public ScenarioClass()
- {
-
+ private TextSpecGenerator specGenerator;
+ private TestMetadataParser metadataParser;
+
+ public ScenarioClass() :
+ this(new AAAMemento())
+ {
}
- public ScenarioClass(AAA semanticModel)
- {
- this.semanticModel = semanticModel;
- scenario = new
Semantics(Activator.CreateInstance(typeof(TClass)), semanticModel);
+ public ScenarioClass(AAAMemento semanticModelState)
+ {
+ this.semanticModel = new AAA(semanticModelState);
+ this.semanticModelState = semanticModelState;
+ this.scenario = new Semantics(this, semanticModel);
+ this.specGenerator = new TextSpecGenerator();
+ this.metadataParser = new TestMetadataParser(this);
+
+ semanticModelState.Text =
metadataParser.TranslateTestClassNameToText();
+ }
+
+ public void Scenario(string text)
+ {
+ semanticModelState.Text = text;
}
public GivenSemantics Given(string text)
@@ -36,6 +49,11 @@
{
return scenario.Given(context);
}
+
+ public GivenSemantics Given(GivenSemantics semantics)
+ {
+ return semantics;
+ }
public void When(string text)
{
@@ -66,5 +84,17 @@
{
return scenario.Then(then);
}
+
+ public ThenSemantics Then(ThenSemantics semantics)
+ {
+ return semantics;
+ }
+
+ public void Run()
+ {
+ specGenerator.Generate(semanticModelState);
+ Console.WriteLine(specGenerator.Output);
+ semanticModel.Execute();
+ }
}
}
=======================================
--- /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs Tue Sep 8
00:22:46 2009
+++ /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs Tue Sep 8
01:30:22 2009
@@ -10,7 +10,7 @@
namespace TinyBDDTests.Dsl.GivenWhenThen.ScenarioClassSpecs
{
- public class Changeset_notification :
ScenarioClass<Changeset_notification>
+ public class Changeset_notification : ScenarioClass
{
public static Context there_are_changesets_in_SourceControl = ()
=> { };
public static When notified_to_refresh = () => { };
@@ -21,8 +21,8 @@
}
- public Changeset_notification(AAA semanticModel)
- : base(semanticModel)
+ public Changeset_notification(AAAMemento semanticModelState)
+ : base(semanticModelState)
{
}
@@ -30,17 +30,39 @@
public class Shared
{
- protected AAA semanticModel;
protected AAAMemento semanticModelState;
- protected ScenarioClass<Changeset_notification> scenario;
+ protected ScenarioClass scenario;
protected void SetupContext()
{
semanticModelState = new AAAMemento();
- semanticModel = new AAA(semanticModelState);
- scenario = new Changeset_notification(semanticModel);
+ scenario = new Changeset_notification(semanticModelState);
}
}
+
+ [TestFixture]
+ public class When_desribing_Scenario : Shared
+ {
+ [SetUp]
+ public void Setup()
+ {
+ SetupContext();
+ }
+
+ [Test]
+ public void Assure_class_name_is_used_as_text_for_the_scenario()
+ {
+ semanticModelState.Text.ShouldBe("Changeset notification");
+ }
+
+ [Test]
+ public void Assure_its_possible_to_set_custom_text_for_Scenario()
+ {
+ scenario.Scenario("custom text");
+
+ semanticModelState.Text.ShouldBe("custom text");
+ }
+ }
[TestFixture]
public class When_describing_Scenario_Givens : Shared
@@ -90,6 +112,20 @@
semantics.ShouldBeInstanceOfType<GivenSemantics>();
}
+
+ [Test]
+ public void Assure_its_possible_to_reuse_Context()
+ {
+
scenario.Given(There_are_changesets_and_Controller_is_created());
+
+ semanticModelState.Arranges.Count.ShouldBe(2);
+ }
+
+ private GivenSemantics
There_are_changesets_and_Controller_is_created()
+ {
+ return scenario.Given("there are changesets in sourceControl").
+ And("the controller is created");
+ }
private void AssertArrange(string text)
{
@@ -182,6 +218,20 @@
semantics.ShouldBeInstanceOfType<ThenSemantics>();
}
+
+ [Test]
+ public void Assure_its_possible_to_reuse_Thens()
+ {
+ scenario.Then(Assure_changesets_are_received_and_sorted());
+
+ semanticModelState.Acts.Values.First().Count.ShouldBe(2);
+ }
+
+ private ThenSemantics Assure_changesets_are_received_and_sorted()
+ {
+ return scenario.Then("assure all changesets are received").
+ And("they are sorted");
+ }
private void VerifyAssertBeenAdded(string text)
{
=======================================
--- /trunk/TinyBDDTests/TinyBDDTests.csproj Tue Sep 8 00:22:46 2009
+++ /trunk/TinyBDDTests/TinyBDDTests.csproj Tue Sep 8 01:30:22 2009
@@ -76,6 +76,7 @@
<Compile Include="Dsl\GivenWhenThenNO\DslTests.cs" />
<Compile Include="Dsl\GivenWhenThenNO\ScenarioTests.cs" />
<Compile Include="Dsl\GivenWhenThenNO\SemantikkTests.cs" />
+ <Compile Include="Dsl\GivenWhenThen\ScenarioClassDslTests.cs" />
<Compile Include="Dsl\GivenWhenThen\ScenarioClassSpecs.cs" />
<Compile Include="Dsl\GivenWhenThen\DslTests.cs" />
<Compile Include="Dsl\GivenWhenThen\GivenSemanticsTests.cs" />