Last active
October 10, 2015 19:07
-
-
Save bugthesystem/3736662 to your computer and use it in GitHub Desktop.
Moq Sequences Revisited from http://haacked.com/archive/2010/11/24/moq-sequences-revisited.aspx Added ReturnsAsync method for c# 5.0 tests
This file contains 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
public static class MoqExtensions | |
{ | |
public static void ReturnsInOrder<T, TResult>(this ISetup<T, TResult> setup, | |
params object[] results) where T : class { | |
var queue = new Queue(results); | |
setup.Returns(() => { | |
var result = queue.Dequeue(); | |
if (result is Exception) { | |
throw result as Exception; | |
} | |
return (TResult)result; | |
}); | |
} | |
public static IReturnsResult<TMock> ReturnsAsync<TMock, TResult>( | |
this IReturns<TMock, Task<TResult>> setup, TResult value) | |
where TMock : class | |
{ | |
return setup.Returns(Task.FromResult(value)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment