Skip to content

Instantly share code, notes, and snippets.

@adamralph
Last active December 12, 2015 10:39
Show Gist options
  • Save adamralph/4760589 to your computer and use it in GitHub Desktop.
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.
[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));
}
@adamralph
Copy link
Author

Currently, this code has to be written as shown at https://github.com/xbehave/xbehave.net#how-do-i-use-it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment