本文整理汇总了C#中IFoo.BarAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IFoo.BarAsync方法的具体用法?C# IFoo.BarAsync怎么用?C# IFoo.BarAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFoo
的用法示例。
在下文中一共展示了IFoo.BarAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NoResultPassExceptionFactoryWithCallArg
public void NoResultPassExceptionFactoryWithCallArg(IFoo fake, Task task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And an async method of the fake configured to throw asynchronously"
.x(() => A.CallTo(() => fake.BarAsync()).ThrowsAsync(call => new MyException()));
"When that method is called"
.x(() => { task = fake.BarAsync(); });
"Then it returns a failed task"
.x(() => task.Status.Should().Be(TaskStatus.Faulted));
"And the task's exception is the configured exception"
.x(() => task.Exception?.InnerException.Should().BeAnExceptionOfType<MyException>());
}
示例2: AsyncWithResultCanceledTokenWithConfiguredCallForNonCanceledToken
public void AsyncWithResultCanceledTokenWithConfiguredCallForNonCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Task<int> task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a call configured on that fake for a non-canceled token"
.x(() => A.CallTo(() => fake.BarAsync(A<CancellationToken>.That.IsNotCanceled())).Returns(42));
"And a cancellation token that is canceled"
.x(() => cancellationToken = new CancellationToken(true));
"When the configured async method is called with this cancellation token"
.x(() => { task = fake.BarAsync(cancellationToken); });
"Then it returns a canceled task"
.x(() => task.Status.Should().Be(TaskStatus.Canceled));
}
示例3: AsyncWithResultCanceledToken
public void AsyncWithResultCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Task<int> task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a cancellation token that is canceled"
.x(() => cancellationToken = new CancellationToken(true));
"When an async method is called with this cancellation token"
.x(() => { task = fake.BarAsync(cancellationToken); });
"Then it returns a canceled task"
.x(() => task.Status.Should().Be(TaskStatus.Canceled));
}
示例4: AsyncWithResultCanceledTokenWithConfiguredCallForAnyToken
public void AsyncWithResultCanceledTokenWithConfiguredCallForAnyToken(
IFoo fake,
CancellationToken cancellationToken,
Task<int> task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a call configured on that fake"
.x(() => A.CallTo(() => fake.BarAsync(A<CancellationToken>._)).Returns(42));
"And a cancellation token that is canceled"
.x(() => cancellationToken = new CancellationToken(true));
"When the configured async method is called with this cancellation token"
.x(() => { task = fake.BarAsync(cancellationToken); });
"Then it returns a successfully completed task"
.x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
"And the task's result is the configured value"
.x(() => task.Result.Should().Be(42));
}
示例5: AsyncWithResultNonCanceledToken
public void AsyncWithResultNonCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Task<int> task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a cancellation token that is not canceled"
.x(() => cancellationToken = new CancellationToken(false));
"When an async method is called with this cancellation token"
.x(() => { task = fake.BarAsync(cancellationToken); });
"Then it returns a successfully completed task"
.x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
"And the task's result should be the default value"
.x(() => task.Result.Should().Be(0));
}