[tinybdd] r53 committed - More work on extending the GivenWhenThen dsl to make it easier to use.

0 views
Skip to first unread message

codesite...@google.com

unread,
Sep 8, 2009, 3:23:36 AM9/8/09
to tin...@googlegroups.com
Revision: 53
Author: goeran.hansen
Date: Tue Sep 8 00:22:46 2009
Log: More work on extending the GivenWhenThen dsl to make it easier to use.

http://code.google.com/p/tinybdd/source/detail?r=53

Added:
/trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs
/trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs
Deleted:
/trunk/TinyBDD/Dsl/GivenWhenThen/Behaviour.cs
/trunk/TinyBDDTests/Dsl/GivenWhenThen/BehaviourSpecs.cs
Modified:
/trunk/TinyBDD/TinyBDD.csproj
/trunk/TinyBDDTests/TinyBDDTests.csproj

=======================================
--- /dev/null
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Tue Sep 8 00:22:46
2009
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TinyBDD.SemanticModel;
+
+namespace TinyBDD.Dsl.GivenWhenThen
+{
+ public class ScenarioClass<TClass>
+ {
+ private AAA semanticModel;
+ private Semantics scenario;
+
+ public ScenarioClass()
+ {
+
+ }
+
+ public ScenarioClass(AAA semanticModel)
+ {
+ this.semanticModel = semanticModel;
+ scenario = new
Semantics(Activator.CreateInstance(typeof(TClass)), semanticModel);
+ }
+
+ public GivenSemantics Given(string text)
+ {
+ return scenario.Given(text);
+ }
+
+ public GivenSemantics Given(string text, Action action)
+ {
+ return scenario.Given(text, action);
+ }
+
+ public GivenSemantics Given(Context context)
+ {
+ return scenario.Given(context);
+ }
+
+ public void When(string text)
+ {
+ scenario.When(text);
+ }
+
+ public void When(string text, Action action)
+ {
+ scenario.When(text, action);
+ }
+
+ public void When(When when)
+ {
+ scenario.When(when);
+ }
+
+ public ThenSemantics Then(string text)
+ {
+ return scenario.Then(text);
+ }
+
+ public ThenSemantics Then(string text, Action action)
+ {
+ return scenario.Then(text, action);
+ }
+
+ public ThenSemantics Then(Then then)
+ {
+ return scenario.Then(then);
+ }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassSpecs.cs Tue Sep 8
00:22:46 2009
@@ -0,0 +1,194 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using TinyBDD.Dsl.GivenWhenThen;
+using TinyBDD.SemanticModel;
+using TinyBDD.Specification.NUnit;
+using Assert=NUnit.Framework.Assert;
+
+namespace TinyBDDTests.Dsl.GivenWhenThen.ScenarioClassSpecs
+{
+ public class Changeset_notification :
ScenarioClass<Changeset_notification>
+ {
+ public static Context there_are_changesets_in_SourceControl = ()
=> { };
+ public static When notified_to_refresh = () => { };
+ public static Then assure_all_changesets_are_received = () => { };
+
+ public Changeset_notification()
+ {
+
+ }
+
+ public Changeset_notification(AAA semanticModel)
+ : base(semanticModel)
+ {
+
+ }
+ }
+
+ public class Shared
+ {
+ protected AAA semanticModel;
+ protected AAAMemento semanticModelState;
+ protected ScenarioClass<Changeset_notification> scenario;
+
+ protected void SetupContext()
+ {
+ semanticModelState = new AAAMemento();
+ semanticModel = new AAA(semanticModelState);
+ scenario = new Changeset_notification(semanticModel);
+ }
+ }
+
+ [TestFixture]
+ public class When_describing_Scenario_Givens : Shared
+ {
+ [SetUp]
+ public void Setup()
+ {
+ SetupContext();
+ }
+
+ [Test]
+ public void Assure_Given_add_arrange_to_the_SemanticModel()
+ {
+ scenario.Given("there are changesets in SourceControl");
+ AssertArrange("there are changesets in SourceControl");
+ semanticModelState.Arranges.Clear();
+
+ scenario.Given("there are changesets in SourceControl", () =>
{ });
+ AssertArrange("there are changesets in SourceControl");
+ semanticModelState.Arranges.Clear();
+
+
scenario.Given(Changeset_notification.there_are_changesets_in_SourceControl);
+ AssertArrange("there are changesets in SourceControl");
+ semanticModelState.Arranges.Clear();
+ }
+
+ [Test]
+ public void Assure_Given_with_only_text_returns_semantics()
+ {
+ var semantics = scenario.Given("there are changesets in
SourceControl");
+
+ semantics.ShouldBeInstanceOfType<GivenSemantics>();
+ }
+
+ [Test]
+ public void Assure_Given_with_text_and_code_returns_semantics()
+ {
+ var semantics = scenario.Given("there are changesets in
SourceControl", () => { });
+
+ semantics.ShouldBeInstanceOfType<GivenSemantics>();
+ }
+
+ [Test]
+ public void Assure_Given_with_Context_returns_semantics()
+ {
+ var semantics =
scenario.Given(Changeset_notification.there_are_changesets_in_SourceControl);
+
+ semantics.ShouldBeInstanceOfType<GivenSemantics>();
+ }
+
+ private void AssertArrange(string text)
+ {
+ semanticModelState.Arranges.ShouldHave(1);
+ semanticModelState.Arranges.First().Text.ShouldBe(text);
+ }
+ }
+
+ [TestFixture]
+ public class When_describing_Scenario_Whens : Shared
+ {
+ [SetUp]
+ public void Setup()
+ {
+ SetupContext();
+ }
+
+ [Test]
+ public void Assure_When_add_act_to_the_SemanticModel()
+ {
+ scenario.When("notified to refresh");
+ AssertAct("notified to refresh");
+ semanticModelState.Acts.Clear();
+
+ scenario.When("notified to refresh", () => { });
+ AssertAct("notified to refresh");
+ semanticModelState.Acts.Clear();
+
+ scenario.When(Changeset_notification.notified_to_refresh);
+ AssertAct("notified to refresh");
+ semanticModelState.Acts.Clear();
+ }
+
+ private void AssertAct(string text)
+ {
+ semanticModelState.Acts.Count.ShouldBe(1);
+ semanticModelState.Acts.Keys.First().Text.ShouldBe(text);
+ }
+ }
+
+ public class When_describing_Scenario_Thens : Shared
+ {
+ [SetUp]
+ public void Setup()
+ {
+ SetupContext();
+
+ //The SemanticModel expect and act, before an
+ //assert can take place.
+ scenario.When("notified to refresh");
+ }
+
+ [Test]
+ public void Assure_Then_add_Assert_to_the_SemanticModel()
+ {
+ scenario.Then("all changesets are received");
+ VerifyAssertBeenAdded("all changesets are received");
+ semanticModelState.Acts.Clear();
+
+ scenario.When("notified to refresh");
+ scenario.Then("all changesets are received", () => { });
+ VerifyAssertBeenAdded("all changesets are received");
+ semanticModelState.Acts.Clear();
+
+ scenario.When("notified to refresh");
+
scenario.Then(Changeset_notification.assure_all_changesets_are_received);
+ VerifyAssertBeenAdded("assure all changesets are received");
+ }
+
+ [Test]
+ public void Assure_Then_with_only_text_returns_semantics()
+ {
+ var semantics = scenario.Then("assure all changesets are
received");
+
+ semantics.ShouldBeInstanceOfType<ThenSemantics>();
+ }
+
+ [Test]
+ public void Assure_Then_with_text_and_code_returns_semantics()
+ {
+ var semantics = scenario.Then("assure all changesets are
received", () => { });
+
+ semantics.ShouldBeInstanceOfType<ThenSemantics>();
+ }
+
+ [Test]
+ public void Assure_Then_with_Then_returns_semnatics()
+ {
+ var semantics =
scenario.Then(Changeset_notification.assure_all_changesets_are_received);
+
+ semantics.ShouldBeInstanceOfType<ThenSemantics>();
+ }
+
+ private void VerifyAssertBeenAdded(string text)
+ {
+ semanticModelState.Acts.Values.First().ShouldHave(1);
+
semanticModelState.Acts.Values.First().First().Text.ShouldBe(text);
+ }
+
+
+ }
+}
=======================================
--- /trunk/TinyBDD/Dsl/GivenWhenThen/Behaviour.cs Sun Aug 23 10:20:30 2009
+++ /dev/null
@@ -1,65 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using TinyBDD.SemanticModel;
-
-namespace TinyBDD.Dsl.GivenWhenThen
-{
- public class Behaviour<TClass>
- {
- private AAA semanticModel;
- private Semantics scenario;
-
- public Behaviour()
- {
-
- }
-
- public Behaviour(AAA semanticModel)
- {
- this.semanticModel = semanticModel;
- scenario = new
Semantics(Activator.CreateInstance(typeof(TClass)), semanticModel);
- }
-
- public void Given(string text)
- {
- scenario.Given(text);
- }
-
- public void Given(string text, Action action)
- {
- scenario.Given(text, action);
- }
-
- public void Given(Context context)
- {
- scenario.Given(context);
- }
-
- public void When(string text)
- {
- scenario.When(text);
- }
-
- public void When(string text, Action action)
- {
- scenario.When(text, action);
- }
-
- public void When(When when)
- {
- scenario.When(when);
- }
-
- public void Then(string text)
- {
- scenario.Then(text);
- }
-
- public void Then(string text, Action action)
- {
- scenario.Then(text, action);
- }
- }
-}
=======================================
--- /trunk/TinyBDDTests/Dsl/GivenWhenThen/BehaviourSpecs.cs Sun Aug 23
10:20:30 2009
+++ /dev/null
@@ -1,113 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-using TinyBDD.Dsl.GivenWhenThen;
-using TinyBDD.SemanticModel;
-using TinyBDD.Specification.NUnit;
-using Assert=NUnit.Framework.Assert;
-
-namespace TinyBDDTests.Dsl.GivenWhenThen.BehaviourSpecs
-{
- public class Changeset_notification : Behaviour<Changeset_notification>
- {
- public static Context there_are_changesets_in_SourceControl = ()
=> { };
- public static When notified_to_refresh = () => { };
-
- public Changeset_notification()
- {
-
- }
-
- public Changeset_notification(AAA semanticModel)
- : base(semanticModel)
- {
-
- }
- }
-
- [TestFixture]
- public class When_describing_scenario
- {
- private AAA semanticModel;
- private AAAMemento semanticModelState;
- private Behaviour<Changeset_notification> scenario;
-
- [SetUp]
- public void Setup()
- {
- semanticModelState = new AAAMemento();
- semanticModel = new AAA(semanticModelState);
- scenario = new Changeset_notification(semanticModel);
- }
-
- [Test]
- public void Assure_Given_add_arrange_to_the_SemanticModel()
- {
- scenario.Given("there are changesets in SourceControl");
- AssertArrange("there are changesets in SourceControl");
- semanticModelState.Arranges.Clear();
-
- scenario.Given("there are changesets in SourceControl", () =>
{ });
- AssertArrange("there are changesets in SourceControl");
- semanticModelState.Arranges.Clear();
-
-
scenario.Given(Changeset_notification.there_are_changesets_in_SourceControl);
- AssertArrange("there are changesets in SourceControl");
- semanticModelState.Arranges.Clear();
- }
-
- private void AssertArrange(string text)
- {
- semanticModelState.Arranges.ShouldHave(1);
- semanticModelState.Arranges.First().Text.ShouldBe(text);
- }
-
- [Test]
- public void Assure_When_add_act_to_the_SemanticModel()
- {
- scenario.When("notified to refresh");
- AssertAct("notified to refresh");
- semanticModelState.Acts.Clear();
-
- scenario.When("notified to refresh", () => { });
- AssertAct("notified to refresh");
- semanticModelState.Acts.Clear();
-
- scenario.When(Changeset_notification.notified_to_refresh);
- AssertAct("notified to refresh");
- semanticModelState.Acts.Clear();
- }
-
- private void AssertAct(string text)
- {
- semanticModelState.Acts.Count.ShouldBe(1);
- semanticModelState.Acts.Keys.First().Text.ShouldBe(text);
- }
-
- [Test]
- public void Assure_Then_add_Assert_to_the_SemanticModel()
- {
- //The SemanticModel expect and act, before an
- //assert can take place.
- scenario.When("notified to refresh");
-
- scenario.Then("all changesets are received");
- VerifyAssertBeenAdded("all changesets are received");
- semanticModelState.Acts.Clear();
-
- scenario.When("notified to refresh");
- scenario.Then("all changesets are received", () => { });
- VerifyAssertBeenAdded("all changesets are received");
- semanticModelState.Acts.Clear();
- }
-
- private void VerifyAssertBeenAdded(string text)
- {
- semanticModelState.Acts.Values.First().ShouldHave(1);
-
semanticModelState.Acts.Values.First().First().Text.ShouldBe(text);
- }
-
- }
-}
=======================================
--- /trunk/TinyBDD/TinyBDD.csproj Sun Aug 23 10:20:30 2009
+++ /trunk/TinyBDD/TinyBDD.csproj Tue Sep 8 00:22:46 2009
@@ -69,7 +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\Behaviour.cs" />
+ <Compile Include="Dsl\GivenWhenThen\ScenarioClass.cs" />
<Compile Include="Dsl\GivenWhenThen\TestMetadataParser.cs" />
<Compile Include="Dsl\GivenWhenThen\TextSpecGenerator.cs" />
<Compile Include="Dsl\GivenWhenThen\GivenSemantics.cs" />
=======================================
--- /trunk/TinyBDDTests/TinyBDDTests.csproj Sun Aug 23 10:20:30 2009
+++ /trunk/TinyBDDTests/TinyBDDTests.csproj Tue Sep 8 00:22:46 2009
@@ -76,7 +76,7 @@
<Compile Include="Dsl\GivenWhenThenNO\DslTests.cs" />
<Compile Include="Dsl\GivenWhenThenNO\ScenarioTests.cs" />
<Compile Include="Dsl\GivenWhenThenNO\SemantikkTests.cs" />
- <Compile Include="Dsl\GivenWhenThen\BehaviourSpecs.cs" />
+ <Compile Include="Dsl\GivenWhenThen\ScenarioClassSpecs.cs" />
<Compile Include="Dsl\GivenWhenThen\DslTests.cs" />
<Compile Include="Dsl\GivenWhenThen\GivenSemanticsTests.cs" />
<Compile Include="Dsl\GivenWhenThen\ScenarioTests.cs" />
Reply all
Reply to author
Forward
0 new messages