Created
August 30, 2014 12:17
-
-
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
This file contains hidden or 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
// 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); | |
} | |
} |
This file contains hidden or 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
// 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