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


C# IFoo.BarAsync方法代码示例

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

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

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

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

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


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