이 작동합니다 :
public static IThenConfiguration<IReturnValueConfiguration<T>> ReturnsNextLazilyFromSequence<T>(
this IReturnValueConfiguration<T> configuration, params Func<T>[] valueProducers)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (valueProducers == null) throw new ArgumentNullException(nameof(valueProducers));
var queue = new Queue<Func<T>>(valueProducers);
return configuration.ReturnsLazily(x => queue.Dequeue().Invoke()).NumberOfTimes(queue.Count);
}
이 같이 호출 :
를
var funcs = new Queue<Func<string>>(new Func<string>[]
{
() => throw new Exception(),
() => throw new Exception(),
() => "a",
});
A.CallTo(() => this.fakeRepo.Get(1)).ReturnsLazily(() => funcs.Dequeue().Invoke()).NumberOfTimes(queue.Count);
이 확장 방법을 할 수 :
A.CallTo(() => this.fakeRepo.Get(1))
.Throws<Exception>().Twice()
.Then
.Returns("a");
또 다른 방법은 순서처럼 할
A.CallTo(() => this.fakeRepo.Get(1)).ReturnsNextLazilyFromSequence(
() => throw new Exception(),
() => throw new Exception(),
() => "a");
또는'(). Twice(). Then.Returns ("a")';) –