Skip to content

Commit c1b09dd

Browse files
committed
added But ExecAttr & refactored exec attr tests
1 parent 8109710 commit c1b09dd

File tree

3 files changed

+49
-130
lines changed

3 files changed

+49
-130
lines changed

TestStack.BDDfy.Tests/Scanner/WhenTestClassUsesExecutableAttributes.cs

Lines changed: 36 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public void AndThen() { }
4242

4343
[AndGiven]
4444
public void SomeOtherPartOfTheGiven() { }
45+
46+
[But]
47+
public void IDontWantThisToBeTrue() { }
4548
}
4649

4750
[SetUp]
@@ -59,166 +62,69 @@ private static string GetStepTextFromMethodName(Action methodInfoAction)
5962
[Test]
6063
public void DecoratedMethodsAreReturned()
6164
{
62-
Assert.That(_steps.Count, Is.EqualTo(7));
63-
}
64-
65-
Step GivenStep
66-
{
67-
get
68-
{
69-
return _steps.Single(s => s.Title == "Given");
70-
}
71-
}
72-
73-
[Test]
74-
public void GivenStep_IsFoundAsSetupState()
75-
{
76-
Assert.That(GivenStep.ExecutionOrder, Is.EqualTo(ExecutionOrder.SetupState));
77-
}
78-
79-
[Test]
80-
public void GivenStep_DoesNotAssert()
81-
{
82-
Assert.IsFalse(GivenStep.Asserts);
83-
}
84-
85-
[Test]
86-
public void GivenStep_TextIsFetchedFromMethodName()
87-
{
88-
Assert.That(GivenStep.Title.Trim(), Is.EqualTo(GetStepTextFromMethodName(_typeWithAttribute.Given)));
89-
}
90-
91-
Step AndGivenStep
92-
{
93-
get
94-
{
95-
return _steps.Single(s => s.Title.Trim() == "Some other part of the given");
96-
}
97-
}
98-
99-
[Test]
100-
public void AndGivenIsFoundAsConsequtiveSetupState()
101-
{
102-
Assert.That(AndGivenStep.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveSetupState));
103-
}
104-
105-
[Test]
106-
public void AndGivenStepDoesNotAssert()
107-
{
108-
Assert.IsFalse(AndGivenStep.Asserts);
109-
}
110-
111-
[Test]
112-
public void AndGivenStepTextIsFetchedFromMethodName()
113-
{
114-
Assert.That(AndGivenStep.Title.Trim(), Is.EqualTo(GetStepTextFromMethodName(_typeWithAttribute.SomeOtherPartOfTheGiven)));
115-
}
116-
117-
Step WhenStep
118-
{
119-
get
120-
{
121-
return _steps.Single(s => s.Title == TypeWithAttribute.MethodTextForWhenSomethingHappens);
122-
}
123-
}
124-
125-
[Test]
126-
public void WhenStep_IsFoundAsTransitionStep()
127-
{
128-
Assert.That(WhenStep.ExecutionOrder, Is.EqualTo(ExecutionOrder.Transition));
129-
}
130-
131-
[Test]
132-
public void WhenStep_StepTextIsFetchedFromExecutableAttribute()
133-
{
134-
Assert.That(WhenStep.Title, Is.EqualTo(TypeWithAttribute.MethodTextForWhenSomethingHappens));
65+
Assert.That(_steps.Count, Is.EqualTo(8));
13566
}
13667

13768
[Test]
138-
public void WhenStep_StepDoesNotAssert()
139-
{
140-
Assert.IsFalse(WhenStep.Asserts);
141-
}
142-
143-
Step TheOtherPartOfWhenStep
69+
public void Given()
14470
{
145-
get
146-
{
147-
return _steps.Single(s => s.Title.Trim() == "The other part of when");
148-
}
71+
var givenStep = _steps.Single(s => s.Title == "Given");
72+
Assert.That(givenStep.ExecutionOrder, Is.EqualTo(ExecutionOrder.SetupState));
73+
Assert.IsFalse(givenStep.Asserts);
74+
Assert.That(givenStep.Title.Trim(), Is.EqualTo(GetStepTextFromMethodName(_typeWithAttribute.Given)));
14975
}
15076

15177
[Test]
152-
public void TheOtherPartOfWhenStep_IsFoundAsConsecutiveTransition()
78+
public void AndGiven()
15379
{
154-
Assert.That(TheOtherPartOfWhenStep.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveTransition));
80+
var step = _steps.Single(s => s.Title.Trim() == "Some other part of the given");
81+
Assert.That(step.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveSetupState));
82+
Assert.IsFalse(step.Asserts);
83+
Assert.That(step.Title.Trim(), Is.EqualTo(GetStepTextFromMethodName(_typeWithAttribute.SomeOtherPartOfTheGiven)));
15584
}
15685

15786
[Test]
158-
public void TheOtherPartOfWhenStep_StepTextIsFetchedFromMethodName()
87+
public void When()
15988
{
160-
Assert.That(TheOtherPartOfWhenStep.Title.Trim(), Is.EqualTo(GetStepTextFromMethodName(_typeWithAttribute.TheOtherPartOfWhen)));
89+
var step = _steps.Single(s => s.Title == TypeWithAttribute.MethodTextForWhenSomethingHappens);
90+
Assert.That(step.ExecutionOrder, Is.EqualTo(ExecutionOrder.Transition));
91+
Assert.That(step.Title, Is.EqualTo(TypeWithAttribute.MethodTextForWhenSomethingHappens));
92+
Assert.IsFalse(step.Asserts);
16193
}
16294

16395
[Test]
164-
public void TheOtherPartOfWhenStep_StepDoesNotAssert()
96+
public void TheOtherPartOfWhen()
16597
{
166-
Assert.IsFalse(TheOtherPartOfWhenStep.Asserts);
98+
var step = _steps.Single(s => s.Title.Trim() == "The other part of when");
99+
Assert.That(step.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveTransition));
100+
Assert.That(step.Title.Trim(), Is.EqualTo(GetStepTextFromMethodName(_typeWithAttribute.TheOtherPartOfWhen)));
101+
Assert.IsFalse(step.Asserts);
167102
}
168103

169104
[Test]
170-
public void ThenStepsAreReturnedAsAssertingSteps()
105+
public void ThenStepsWithArgs()
171106
{
172-
var steps = ThenSteps.ToList();
107+
var steps = _steps.Where(s => s.Title == "Then 1, 2" || s.Title == "Then 3, 4").ToList();
173108
Assert.IsTrue(steps.All(s => s.ExecutionOrder == ExecutionOrder.Assertion));
174-
}
175-
176-
IEnumerable<Step> ThenSteps
177-
{
178-
get
179-
{
180-
return _steps.Where(s => s.Title == "Then 1, 2" || s.Title == "Then 3, 4");
181-
}
182-
}
183-
184-
[Test]
185-
public void ThenSteps_DoAssert()
186-
{
187-
var steps = ThenSteps.ToList();
188-
Assert.True(steps.All(s => s.Asserts));
189-
}
190-
191-
[Test]
192-
public void ThenSteps_StepTextIsFetchedFromMethodNamePostfixedWithArguments()
193-
{
194-
var steps = ThenSteps.ToList();
109+
Assert.IsTrue(steps.All(s => s.Asserts));
195110
Assert.IsTrue(steps.All(s => s.Title.EndsWith(" 1, 2") || s.Title.EndsWith(" 3, 4")));
196111
}
197112

198-
Step AndThenStep
199-
{
200-
get
201-
{
202-
return _steps.Single(s => s.Title.Trim() == TypeWithAttribute.MethodTextForAndThen);
203-
}
204-
}
205-
206-
[Test]
207-
public void AndThenStep_IsFoundAndConsecutiveAssertingStep()
208-
{
209-
Assert.That(AndThenStep.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveAssertion));
210-
}
211-
212113
[Test]
213-
public void AndThenStep_Asserts()
114+
public void AndThen()
214115
{
215-
Assert.IsTrue(AndThenStep.Asserts);
116+
var step = _steps.Single(s => s.Title.Trim() == TypeWithAttribute.MethodTextForAndThen);
117+
Assert.That(step.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveAssertion));
118+
Assert.IsTrue(step.Asserts);
119+
Assert.That(step.Title.Trim(), Is.EqualTo(TypeWithAttribute.MethodTextForAndThen));
216120
}
217121

218122
[Test]
219-
public void AndThenStep_StepTextIsFetchedFromExecutableAttribute()
123+
public void But()
220124
{
221-
Assert.That(AndThenStep.Title.Trim(), Is.EqualTo(TypeWithAttribute.MethodTextForAndThen));
125+
var step = _steps.Single(s => s.Title == "I dont want this to be true");
126+
Assert.That(step.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveAssertion));
127+
Assert.IsTrue(step.Asserts);
222128
}
223129
}
224130
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace TestStack.BDDfy
2+
{
3+
public class ButAttribute : ExecutableAttribute
4+
{
5+
public ButAttribute() : this(null) { }
6+
7+
public ButAttribute(string stepTitle) : base(ExecutionOrder.ConsecutiveAssertion, stepTitle)
8+
{
9+
Asserts = true;
10+
}
11+
}
12+
}

TestStack.BDDfy/TestStack.BDDfy.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
<Compile Include="Scanners\StepScanners\Examples\ExampleTable.cs" />
116116
<Compile Include="Scanners\StepScanners\Examples\ExampleValue.cs" />
117117
<Compile Include="Scanners\StepScanners\Examples\UnassignableExampleException.cs" />
118+
<Compile Include="Scanners\StepScanners\ExecutableAttribute\GwtAttributes\ButAttribute.cs" />
118119
<Compile Include="Scanners\StepScanners\WithTagsExtensions.cs" />
119120
<Compile Include="Scanners\StepScanners\Fluent\FluentApi.cs">
120121
<AutoGen>True</AutoGen>

0 commit comments

Comments
 (0)