本文整理汇总了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();
}
示例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");
}
示例3: ShouldThrowAWobbly
protected override void ShouldThrowAWobbly()
{
var action = new Func<int>(() => { throw new InvalidOperationException(); });
action.ShouldNotThrow("Some additional context");
}
示例4: ShouldPass
protected override void ShouldPass()
{
var action = new Func<int>(() => 1);
action.ShouldNotThrow().ShouldBe(1);
}
示例5: ShouldPass
public void ShouldPass()
{
var action = new Func<int>(() => 1);
action.ShouldNotThrow().ShouldBe(1);
}