Last active
December 12, 2015 10:39
-
-
Save adamralph/4760589 to your computer and use it in GitHub Desktop.
I did a spike once for xBehave.net which would allow this in .NET 4.0+. The `scenario` object which is passed as an argument to each step expression is an `ExpandoObject` typed as `dynamic`. I'd love to come up with a solution which doesn't have the issue noted in the code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Scenario] | |
public void PushingAnElementOntoAStack() // No parameters :-D | |
{ | |
"Given an element" | |
.Given(scenario => scenario.Element = 11); | |
"And a stack" | |
.And(scenario => scenario.Stack = new Stack<int>()); | |
"When pushing the element onto the stack" | |
.When(scenario => scenario.Stack.Push(element)); | |
// NOTE: I would like to write this without the cast but I can't because | |
// Should() is an extension method on object provided by FluentAssertions and | |
// it is not possible to call extension methods on dynamic :-( | |
"Then the element should be at the top of the stack" | |
.And(scenario => ((int)scenario.Peek()).Should().Be(element)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, this code has to be written as shown at https://github.com/xbehave/xbehave.net#how-do-i-use-it