Revision: 57
Author: goeran.hansen
Date: Wed Oct 7 05:18:41 2009
Log: More work on the new DSL in the Scenario class. Now added support for
And Semantics.
http://code.google.com/p/tinybdd/source/detail?r=57
Added:
/trunk/TinyBDD/Dsl/GivenWhenThen/AndSemantics.cs
Modified:
/trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs
/trunk/TinyBDD/TinyBDD.csproj
/trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs
=======================================
--- /dev/null
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/AndSemantics.cs Wed Oct 7 05:18:41
2009
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TinyBDD.Dsl.GivenWhenThen
+{
+ public class AndSemantics
+ {
+ SemanticModel.AAA semanticModel;
+ TestMetadataParser metadataParser;
+ Object test;
+
+ public AndSemantics(Object test, SemanticModel.AAA semanticModel)
+ {
+ this.test = test;
+ this.semanticModel = semanticModel;
+ metadataParser = new TestMetadataParser(test);
+ }
+
+ }
+}
=======================================
--- /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Tue Sep 15 00:04:29
2009
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Wed Oct 7 05:18:41
2009
@@ -91,6 +91,38 @@
{
return semantics;
}
+
+ public AndSemantics And(Context context)
+ {
+ semanticModel.Arrange(metadataParser.TranslateToText(context),
() => { context(); });
+ return new AndSemantics(this, semanticModel);
+ }
+
+ public AndSemantics And(Then then)
+ {
+ semanticModel.Assert(metadataParser.TranslateToText(then), ()
=> { then(); });
+ return new AndSemantics(this, semanticModel);
+ }
+
+ public AndSemantics And(string text)
+ {
+ return And(text, () => { });
+ }
+
+ public AndSemantics And(string text, Action a)
+ {
+ if (semanticModelState.Acts.Count == 0)
+ semanticModel.Arrange(text, a);
+ else
+ semanticModel.Assert(text, a);
+
+ return new AndSemantics(this, semanticModel);
+ }
+
+ public AndSemantics And(AndSemantics semantics)
+ {
+ return semantics;
+ }
public void Run()
{
=======================================
--- /trunk/TinyBDD/TinyBDD.csproj Tue Sep 8 00:22:46 2009
+++ /trunk/TinyBDD/TinyBDD.csproj Wed Oct 7 05:18:41 2009
@@ -69,6 +69,7 @@
<Compile Include="Dsl\GivenWhenThenNO\Scenario.cs" />
<Compile Include="Dsl\GivenWhenThenNO\Semantikk.cs" />
<Compile Include="Dsl\GivenWhenThenNO\SåSemantikk.cs" />
+ <Compile Include="Dsl\GivenWhenThen\AndSemantics.cs" />
<Compile Include="Dsl\GivenWhenThen\ScenarioClass.cs" />
<Compile Include="Dsl\GivenWhenThen\TestMetadataParser.cs" />
<Compile Include="Dsl\GivenWhenThen\TextSpecGenerator.cs" />
=======================================
--- /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs Tue Sep 15
00:04:29 2009
+++ /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs Wed Oct 7
05:18:41 2009
@@ -144,6 +144,87 @@
semanticModelState.Arranges.First().Text.ShouldBe(text);
}
}
+
+ [TestFixture]
+ public class When_describing_Scenario_Ands : Shared
+ {
+ [SetUp]
+ public void Setup()
+ {
+ SetupContext();
+ scenario.Given("there are changesets in SourceControl");
+ }
+
+ [Test]
+ public void Assure_And_with_only_Text_returns_Semantics()
+ {
+ var semantics = scenario.And("the controller is created");
+
+ semantics.ShouldBeInstanceOfType<AndSemantics>();
+ }
+
+ [Test]
+ public void Assure_And_with_text_add_Arrage_to_the_SemanticModel()
+ {
+ scenario.And("the controller is created");
+
+ semanticModelState.Arranges.Count.ShouldBe(2);
+ semanticModelState.Arranges.Last().Text.ShouldBe("the
controller is created");
+ }
+
+ [Test]
+ public void
Assure_And_with_text_add_Assert_to_the_SemanticModel_When_Acts_is_added()
+ {
+ scenario.When("notified to refresh");
+ scenario.Then("assure all changesets are received");
+ scenario.And("assure changesets are sorted by revision
number");
+
+ var arranges = semanticModelState.Acts.First().Value;
+ arranges.Count.ShouldBe(2);
+ arranges.Last().Text.ShouldBe("assure changesets are sorted by
revision number");
+ }
+
+ [Test]
+ public void Assure_its_possible_to_use_text_and_code()
+ {
+ scenario.And("the controller is created", () => { });
+ }
+
+ [Test]
+ public void Assure_its_possible_to_reuse_Context()
+ {
+
scenario.And(Changeset_notification.there_are_changesets_in_SourceControl);
+
+ semanticModelState.Arranges.Count.ShouldBe(2);
+ semanticModelState.Arranges.Last().Text.ShouldBe("there are
changesets in SourceControl");
+ }
+
+ [Test]
+ public void Assure_its_possible_to_reuse_Then()
+ {
+ scenario.When("notified to refresh");
+ scenario.Then("SourceControl system is contacted");
+
scenario.And(Changeset_notification.assure_all_changesets_are_received);
+
+ var asserts = semanticModelState.Acts.First().Value;
+ asserts.Count.ShouldBe(2);
+ asserts.Last().Text.ShouldBe("assure all changesets are
received");
+ }
+
+ [Test]
+ public void Assure_its_possible_to_reuse_AndSemantics()
+ {
+ scenario.And(controller_is_created());
+
+ semanticModelState.Arranges.Count.ShouldBe(2);
+ semanticModelState.Arranges.Last().Text.ShouldBe("controller
is created");
+ }
+
+ private AndSemantics controller_is_created()
+ {
+ return scenario.And("controller is created");
+ }
+ }
[TestFixture]
public class When_describing_Scenario_Whens : Shared