[tinybdd] r74 committed - Last revision was a long shoot (to late last night) and now updated th...

0 views
Skip to first unread message

codesite...@google.com

unread,
Nov 4, 2009, 4:34:09 AM11/4/09
to tin...@googlegroups.com
Revision: 74
Author: goeran.hansen
Date: Wed Nov 4 01:33:57 2009
Log: Last revision was a long shoot (to late last night) and now updated
the code base.

When a Scenario is executed using the ScenarioClass and StartSCenario the
SemanticModel State is cleared. This makes it's easier to build scenarios
after one is executed.

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

Added:
/trunk/TinyBDDTests/SemanticModel/AAAMementoTests.cs
Modified:
/trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs
/trunk/TinyBDD/SemanticModel/AAAMemento.cs
/trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassDslTests.cs
/trunk/TinyBDDTests/TinyBDDTests.csproj

=======================================
--- /dev/null
+++ /trunk/TinyBDDTests/SemanticModel/AAAMementoTests.cs Wed Nov 4
01:33:57 2009
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using TinyBDD.SemanticModel;
+using Assert=TinyBDD.SemanticModel.Assert;
+
+using TinyBDD.Specification.NUnit;
+
+namespace TinyBDDTests.SemanticModel
+{
+ [TestFixture]
+ public class AAAMementoTests
+ {
+ [Test]
+ public void Assure_its_cloneable()
+ {
+ var state = new AAAMemento();
+ state.Text = "When login";
+ state.Arranges.Add(new Arrange("ViewModel is created", () => {
}));
+ state.Acts.Add(new Act("login", () => {}), new List<Assert>());
+ state.Acts.First().Value.Add(new Assert("assure credentials
are validated against the AuthService", () => { }));
+
+ var stateCopy = state.Copy() as AAAMemento;
+
+ stateCopy.Text.ShouldBe(state.Text);
+ stateCopy.Arranges.ShouldNotBeNull();
+ stateCopy.Arranges.Count.ShouldBe(state.Arranges.Count);
+ foreach (var arrange in state.Arranges)
+ stateCopy.Arranges.ShouldContain(arrange);
+
+ stateCopy.Acts.ShouldNotBeNull();
+ stateCopy.Acts.Count.ShouldBe(state.Acts.Count);
+ foreach (var act in state.Acts)
+ {
+ stateCopy.Acts.Keys.ShouldContain(act.Key);
+ stateCopy.Acts.Values.ShouldContain(act.Value);
+ }
+ }
+ }
+}
=======================================
--- /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Tue Nov 3 16:02:45
2009
+++ /trunk/TinyBDD/Dsl/GivenWhenThen/ScenarioClass.cs Wed Nov 4 01:33:57
2009
@@ -13,7 +13,6 @@
private Semantics scenario;
private TextSpecGenerator specGenerator;
private TestMetadataParser metadataParser;
- private bool flagClearScenario;

public ScenarioClass() :
this(new AAAMemento())
@@ -34,42 +33,32 @@
public void Scenario(string text)
{
semanticModelState.Text = text;
-
- flagClearScenario = true;
- ClearScenario();
+ ClearSemanticModelState();
}

- private void ClearScenario()
- {
- if (flagClearScenario)
- {
- semanticModelState.Arranges.Clear();
- semanticModelState.Acts.Clear();
- flagClearScenario = false;
- }
+ private void ClearSemanticModelState()
+ {
+ semanticModelState.Arranges.Clear();
+ semanticModelState.Acts.Clear();
}

public GivenSemantics Given(string text)
{
- ClearScenario();
return scenario.Given(text);
}

public GivenSemantics Given(string text, Action action)
{
- ClearScenario();
return scenario.Given(text, action);
}

public GivenSemantics Given(Context context)
{
- ClearScenario();
return scenario.Given(context);
}

public GivenSemantics Given(GivenSemantics semantics)
{
- ClearScenario();
return semantics;
}

@@ -142,12 +131,13 @@

public void StartScenario()
{
- SemanticModelState(semanticModelState);
+ SemanticModelState(semanticModelState.Copy());
+
specGenerator.Generate(semanticModelState);
Console.WriteLine(specGenerator.Output);
semanticModel.Execute();

- flagClearScenario = true;
+ ClearSemanticModelState();
}

protected virtual void SemanticModelState(AAAMemento
semanticModelState)
=======================================
--- /trunk/TinyBDD/SemanticModel/AAAMemento.cs Tue Jun 23 15:58:04 2009
+++ /trunk/TinyBDD/SemanticModel/AAAMemento.cs Wed Nov 4 01:33:57 2009
@@ -5,7 +5,7 @@

namespace TinyBDD.SemanticModel
{
- public class AAAMemento
+ public class AAAMemento
{
public string Text { get; set; }
public List<Arrange> Arranges { get; set; }
@@ -16,5 +16,21 @@
Arranges = new List<Arrange>();
Acts = new Dictionary<Act, List<Assert>>();
}
+
+ #region ICloneable Members
+
+ public AAAMemento Copy()
+ {
+ var newMemento = new AAAMemento();
+ newMemento.Text = Text;
+ newMemento.Arranges.AddRange(Arranges);
+
+ foreach (var act in Acts)
+ newMemento.Acts.Add(act.Key, act.Value);
+
+ return newMemento;
+ }
+
+ #endregion
}
}
=======================================
--- /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassDslTests.cs Tue Nov
3 15:34:57 2009
+++ /trunk/TinyBDDTests/Dsl/GivenWhenThen/ScenarioClassDslTests.cs Wed Nov
4 01:33:57 2009
@@ -33,16 +33,32 @@
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_all_changesets_are_received()
+ {
+ Then(() => { }).And("they are ordered by revision", () =>{});
+ StartScenario();
+
+ //Asserts that the scenario is built as expected
+ semanticModelState.Text.ShouldBe("When describing Scenario");
+ semanticModelState.Arranges.Count.ShouldBe(2);
+ semanticModelState.Acts.Count.ShouldBe(1);
+ semanticModelState.Acts.First().Value.Count.ShouldBe(2);
+ }
+
[Test]
- public void Assure_arranges_been_added_to_the_SemanticModel()
- {
- //Run();
+ public void Assure_changesets_are_added_to_ViewModel()
+ {
+ Then(() => { });
+ StartScenario();
+
+ //Asserts that the scenario is built as expected
+ semanticModelState.Text.ShouldBe("When describing Scenario");
+ semanticModelState.Arranges.Count.ShouldBe(2);
+ semanticModelState.Acts.Count.ShouldBe(1);
+ semanticModelState.Acts.First().Value.Count.ShouldBe(1);
}
}

=======================================
--- /trunk/TinyBDDTests/TinyBDDTests.csproj Tue Nov 3 15:09:15 2009
+++ /trunk/TinyBDDTests/TinyBDDTests.csproj Wed Nov 4 01:33:57 2009
@@ -85,6 +85,7 @@
<Compile Include="Learning\FileSystemWatcherTests.cs" />
<Compile Include="Learning\StackTraceTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="SemanticModel\AAAMementoTests.cs" />
<Compile Include="SemanticModel\AAATests.cs" />
</ItemGroup>
<ItemGroup>
Reply all
Reply to author
Forward
0 new messages