当前位置: 首页>>代码示例>>C#>>正文


C# IFoo.BazAsync方法代码示例

本文整理汇总了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>());
        }
开发者ID:adamralph,项目名称:FakeItEasy,代码行数:17,代码来源:ThrowsAsyncSpecs.cs

示例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>());
        }
开发者ID:adamralph,项目名称:FakeItEasy,代码行数:18,代码来源:ThrowsAsyncSpecs.cs

示例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));
        }
开发者ID:adamralph,项目名称:FakeItEasy,代码行数:20,代码来源:CancellationSpecs.cs

示例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));
        }
开发者ID:adamralph,项目名称:FakeItEasy,代码行数:17,代码来源:CancellationSpecs.cs

示例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));
        }
开发者ID:adamralph,项目名称:FakeItEasy,代码行数:20,代码来源:CancellationSpecs.cs

示例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));
        }
开发者ID:adamralph,项目名称:FakeItEasy,代码行数:17,代码来源:CancellationSpecs.cs


注:本文中的IFoo.BazAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。