本文整理汇总了C#中IFoo.BazAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IFoo.BazAsync方法的具体用法?C# IFoo.BazAsync怎么用?C# IFoo.BazAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFoo
的用法示例。
在下文中一共展示了IFoo.BazAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithResultPassExceptionInstance
public void WithResultPassExceptionInstance(IFoo fake, Task<int> task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And an async method of the fake configured to throw asynchronously"
.x(() => A.CallTo(() => fake.BazAsync()).ThrowsAsync(new MyException()));
"When that method is called"
.x(() => { task = fake.BazAsync(); });
"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: WithResultPassExceptionFactoryWithFourArgs
public void WithResultPassExceptionFactoryWithFourArgs(IFoo fake, Task<int> task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And an async method of the fake configured to throw asynchronously"
.x(() => A.CallTo(() => fake.BazAsync(0, "x", false, 0.0))
.ThrowsAsync((int a, string b, bool c, double d) => new MyException()));
"When that method is called"
.x(() => { task = fake.BazAsync(0, "x", false, 0.0); });
"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>());
}
示例3: AsyncWithoutResultCanceledTokenWithConfiguredCallForNonCanceledToken
public void AsyncWithoutResultCanceledTokenWithConfiguredCallForNonCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Task 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.BazAsync(A<CancellationToken>.That.IsNotCanceled())).Returns(Task.FromResult(0)));
"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.BazAsync(cancellationToken); });
"Then it returns a canceled task"
.x(() => task.Status.Should().Be(TaskStatus.Canceled));
}
示例4: AsyncWithoutResultCanceledToken
public void AsyncWithoutResultCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Task 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.BazAsync(cancellationToken); });
"Then it returns a canceled task"
.x(() => task.Status.Should().Be(TaskStatus.Canceled));
}
示例5: AsyncWithoutResultNonCanceledTokenWithConfiguredCall
public void AsyncWithoutResultNonCanceledTokenWithConfiguredCall(
IFoo fake,
CancellationToken cancellationToken,
Task task)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a call configured on that fake"
.x(() => A.CallTo(() => fake.BazAsync(A<CancellationToken>._)).Returns(Task.FromResult(0)));
"And a cancellation token that is not canceled"
.x(() => cancellationToken = new CancellationToken(false));
"When the configured async method is called with this cancellation token"
.x(() => { task = fake.BazAsync(cancellationToken); });
"Then it returns a successfully completed task"
.x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
}
示例6: AsyncWithoutResultNonCanceledToken
public void AsyncWithoutResultNonCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Task 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.BazAsync(cancellationToken); });
"Then it returns a successfully completed task"
.x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
}