Skip to content

Instantly share code, notes, and snippets.

@adamralph
Forked from bwatts/NoBaseClass.cs
Created October 20, 2012 13:02
Show Gist options
  • Save adamralph/3923217 to your computer and use it in GitHub Desktop.
Save adamralph/3923217 to your computer and use it in GitHub Desktop.
Behaviors with LINQ syntax using a scenario monad
public class IntervalFeature : Feature
{
[Scenario]
public void Comparison()
{
var result =
from interval in Given("an interval", Interval.WholeStep)
from smallerInterval in And("a smaller interval", Interval.HalfStep)
select When("comparing the intervals", left.CompareTo(right));
Then("the first interval is determined to be larger than the second interval", () => result.Should().Be(1));
}
}
public class IntervalFeature
{
[Scenario]
public void ComparisonUsingLinq()
{
var result =
from left in "Given an interval".Of(Interval.WholeStep)
from right in "And a smaller interval".Of(Interval.HalfStep)
select "When comparing the intervals".Do(left.CompareTo(right));
"Then the first interval is determined to be larger than the second interval".Do(() => result.Should().Be(1));
}
[Scenario]
public void ComparisonWithoutUsingLinq()
{
var left = "Given an interval".Given(() => Interval.WholeStep);
var right = "And a smaller interval".And(() => Interval.HalfStep);
var result = "When comparing the intervals".When(() => left.CompareTo(right));
"Then the first interval is determined to be larger than the second interval".Then(() => result.Should().Be(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment