Skip to content

Instantly share code, notes, and snippets.

@blairconrad
Created August 30, 2014 12:17
Show Gist options
  • Save blairconrad/c83f0e6756879d6c8f25 to your computer and use it in GitHub Desktop.
Save blairconrad/c83f0e6756879d6c8f25 to your computer and use it in GitHub Desktop.
A slightly more fluent version of MustHaveHappend(Repeated.Exactly(times)). For https://github.com/FakeItEasy/FakeItEasy/issues/354
// Allows
// A.CallTo(() => fake.Add(A<object>._))
// .MustHaveHappened(2.Times());
//
// but then the ints all have a Times method on them.
public static class IntTimesExtensions
{
public static Repeated Times(this int i)
{
return Repeated.Exactly.Times(i);
}
}
// Allows
// A.CallTo(() => fake.Add(A<object>._))
// .MustHaveHappened(3).Times();
public static class MustHaveHappenedIntExtensions
{
public static RepeatSpecification MustHaveHappened(this IAssertConfiguration config, int times)
{
return new RepeatSpecification(config, times);
}
public class RepeatSpecification
{
private readonly int times;
private readonly IAssertConfiguration config;
public RepeatSpecification(IAssertConfiguration config, int times)
{
this.config = config;
this.times = times;
}
public void Times()
{
config.MustHaveHappened(Repeated.Exactly.Times(times));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment