Skip to content

Instantly share code, notes, and snippets.

@bwatts
Created October 19, 2012 00:33
Show Gist options
  • Save bwatts/3915594 to your computer and use it in GitHub Desktop.
Save bwatts/3915594 to your computer and use it in GitHub Desktop.
Behaviors with LINQ syntax using a scenario monad
public class IntervalComparisons : Behavior
{
[Scenario]
public void GreaterThan()
{
var result =
from left in Given("an interval", Interval.WholeStep)
from right in And("a lesser interval", Interval.HalfStep)
select When("comparing them", left.CompareTo(right));
Then("the result is 1", () => result.Should().Be(1));
}
}
public class IntervalComparisons
{
[Scenario]
public void Linq_NoBaseClass()
{
var result =
from left in "Given an interval".Of(Interval.WholeStep)
from right in "And a lesser interval".Of(Interval.HalfStep)
select "When comparing them".Do(left.CompareTo(right));
"Then the result is 1".Do(() => result.Should().Be(1));
}
[Scenario]
public void NoLinq_InlineAssignments()
{
var left = "Given an interval".Given(() => Interval.WholeStep);
var right = "And a lesser interval".And(() => Interval.HalfStep);
var result = "When comparing them".When(() => left.CompareTo(right));
"Then the result is 1".Then(() => result.Should().Be(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment