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


C# Func.ShouldNotThrow方法代码示例

本文整理汇总了C#中Func.ShouldNotThrow方法的典型用法代码示例。如果您正苦于以下问题:C# Func.ShouldNotThrow方法的具体用法?C# Func.ShouldNotThrow怎么用?C# Func.ShouldNotThrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Func的用法示例。


在下文中一共展示了Func.ShouldNotThrow方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DelegateShouldDropSynchronisationContext

        public void DelegateShouldDropSynchronisationContext()
        {
            // The await keyword will automatically capture synchronisation context
            // Because shouldly uses .Wait() we cannot let continuations run on the sync context without a deadlock
            var synchronizationContext = new SynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(synchronizationContext);
            SynchronizationContext.Current.ShouldNotBe(null);

            var syncFunc1 = new Func<Task<object>>(() =>
            {
                SynchronizationContext.Current.ShouldBe(null);

                var taskCompletionSource = new TaskCompletionSource<object>();
                taskCompletionSource.SetResult(null);
                return taskCompletionSource.Task;
            });
            syncFunc1.ShouldNotThrow();

            var syncFunc2 = new Func<Task>(() =>
            {
                SynchronizationContext.Current.ShouldBe(null);

                var taskCompletionSource = new TaskCompletionSource<object>();
                taskCompletionSource.SetResult(null);
                return taskCompletionSource.Task;
            });

            syncFunc2.ShouldNotThrow();
        }
开发者ID:CoderDennis,项目名称:shouldly,代码行数:29,代码来源:NestedAwaitsDoNotDeadlockScenario.cs

示例2: FuncDelegateScenarioShouldFail

        public void FuncDelegateScenarioShouldFail()
        {
            var action = new Func<int>(() => { throw new InvalidOperationException(); });
            Verify.ShouldFail(() =>
action.ShouldNotThrow("Some additional context"),

errorWithSource:
@"`action()`
    should not throw but threw
System.InvalidOperationException
    with message
""Operation is not valid due to the current state of the object.""

Additional Info:
    Some additional context",

errorWithoutSource:
@"delegate
    should not throw but threw
System.InvalidOperationException
    with message
""Operation is not valid due to the current state of the object.""

Additional Info:
    Some additional context");
        }
开发者ID:CoderDennis,项目名称:shouldly,代码行数:26,代码来源:FuncDelegateScenario.cs

示例3: ShouldThrowAWobbly

 protected override void ShouldThrowAWobbly()
 {
     var action = new Func<int>(() => { throw new InvalidOperationException(); });
     action.ShouldNotThrow("Some additional context");
 }
开发者ID:gwest,项目名称:shouldly,代码行数:5,代码来源:FuncDelegateScenario.cs

示例4: ShouldPass

 protected override void ShouldPass()
 {
     var action = new Func<int>(() => 1);
     action.ShouldNotThrow().ShouldBe(1);
 }
开发者ID:gwest,项目名称:shouldly,代码行数:5,代码来源:FuncDelegateScenario.cs

示例5: ShouldPass

 public void ShouldPass()
 {
     var action = new Func<int>(() => 1);
     action.ShouldNotThrow().ShouldBe(1);
 }
开发者ID:CoderDennis,项目名称:shouldly,代码行数:5,代码来源:FuncDelegateScenario.cs


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