本文整理汇总了C#中Case.Fail方法的典型用法代码示例。如果您正苦于以下问题:C# Case.Fail方法的具体用法?C# Case.Fail怎么用?C# Case.Fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Case
的用法示例。
在下文中一共展示了Case.Fail方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(Case @case, Action next)
{
try
{
var method = @case.Method;
bool isDeclaredAsync = method.IsAsync();
if (isDeclaredAsync && method.IsVoid())
ThrowForUnsupportedAsyncVoid();
object returnValue;
try
{
if (method.ContainsGenericParameters)
throw new Exception("Could not resolve type parameters for generic test case.");
returnValue = method.Invoke(@case.Fixture.Instance, @case.Parameters);
}
catch (TargetInvocationException exception)
{
throw new PreservedException(exception.InnerException);
}
if (isDeclaredAsync)
{
var task = (Task)returnValue;
try
{
task.Wait();
}
catch (AggregateException exception)
{
throw new PreservedException(exception.InnerExceptions.First());
}
if (method.ReturnType.IsGenericType)
{
var property = task.GetType().GetProperty("Result", BindingFlags.Instance | BindingFlags.Public);
returnValue = property.GetValue(task, null);
}
else
{
returnValue = null;
}
}
@case.ReturnValue = returnValue;
}
catch (Exception exception)
{
@case.Fail(exception);
}
}
示例2: Execute
public void Execute(InvokeBehavior invokeBehavior, Case @case, object instance)
{
try
{
outer(@case, instance, () => inner.Execute(invokeBehavior, @case, instance));
}
catch (Exception exception)
{
@case.Fail(exception);
}
}
示例3: Execute
public void Execute(Case @case, object instance)
{
try
{
outer(@case, instance, () => inner.Execute(@case, instance));
}
catch (Exception exception)
{
@case.Fail(exception);
}
}
示例4: Execute
public void Execute(Case @case, object instance)
{
try
{
var method = @case.Method;
bool isDeclaredAsync = method.IsAsync();
if (isDeclaredAsync && method.IsVoid())
ThrowForUnsupportedAsyncVoid();
object result;
try
{
result = method.Invoke(instance, null);
}
catch (TargetInvocationException exception)
{
throw new PreservedException(exception.InnerException);
}
if (isDeclaredAsync)
{
var task = (Task)result;
try
{
task.Wait();
}
catch (AggregateException exception)
{
throw new PreservedException(exception.InnerExceptions.First());
}
}
}
catch (Exception exception)
{
@case.Fail(exception);
}
}
示例5: Run
public ClassResult Run(Type testClass)
{
var methods = methodDiscoverer.TestMethods(testClass);
var cases = new List<Case>();
foreach (var method in methods)
{
try
{
bool generatedInputParameters = false;
foreach (var parameters in Parameters(method))
{
generatedInputParameters = true;
cases.Add(new Case(method, parameters));
}
if (!generatedInputParameters)
{
if (method.GetParameters().Length > 0)
throw new Exception("This test case has declared parameters, but no parameter values have been provided to it.");
cases.Add(new Case(method));
}
}
catch (Exception parameterGenerationException)
{
var @case = new Case(method);
@case.Fail(parameterGenerationException);
cases.Add(@case);
}
}
var orderedCases = cases.ToArray();
try
{
orderCases(orderedCases);
}
catch (Exception exception)
{
// When an exception is thrown attempting to sort an array,
// the behavior is undefined, so at this point orderedCases
// is no longer reliable and needs to be fixed. The best we
// can do is go with the original order.
orderedCases = cases.ToArray();
foreach (var @case in cases)
@case.Fail(exception);
}
var classResult = new ClassResult(testClass.FullName);
var casesToExecute = new List<Case>();
foreach (var @case in orderedCases)
{
if (@case.Exceptions.Any())
classResult.Add(Fail(@case));
else
{
string reason;
bool skipCase;
try
{
skipCase = SkipCase(@case, out reason);
}
catch (Exception exception)
{
@case.Fail(exception);
classResult.Add(Fail(@case));
continue;
}
if (skipCase)
classResult.Add(Skip(@case, reason));
else
casesToExecute.Add(@case);
}
}
if (casesToExecute.Any())
{
Run(testClass, casesToExecute);
foreach (var @case in casesToExecute)
classResult.Add(@case.Exceptions.Any() ? Fail(@case) : Pass(@case));
}
return classResult;
}
示例6: Run
public ClassResult Run(Type testClass)
{
var methods = methodDiscoverer.TestMethods(testClass);
var cases = new List<Case>();
var parameterGenerationFailures = new List<Case>();
foreach (var method in methods)
{
try
{
bool methodHasParameterizedCase = false;
foreach (var parameters in Parameters(method))
{
methodHasParameterizedCase = true;
cases.Add(new Case(method, parameters));
}
if (!methodHasParameterizedCase)
cases.Add(new Case(method));
}
catch (Exception parameterGenerationException)
{
var @case = new Case(method);
@case.Fail(parameterGenerationException);
parameterGenerationFailures.Add(@case);
}
}
var casesToSkipList = new List<KeyValuePair<Case, string>>();
var casesToExecuteList = new List<Case>();
foreach (var @case in cases)
{
string reason;
if (SkipCase(@case, out reason))
casesToSkipList.Add(new KeyValuePair<Case, string>(@case, reason));
else
casesToExecuteList.Add(@case);
}
var casesToSkip = casesToSkipList.Select(x => x.Key).ToArray();
var casesToExecute = casesToExecuteList.ToArray();
var classResult = new ClassResult(testClass.FullName);
if (casesToSkip.Any())
{
TryOrderCases(casesToSkip);
foreach (var @case in casesToSkip)
classResult.Add(Skip(@case, casesToSkipList.Single(x => x.Key == @case).Value));
}
if (casesToExecute.Any())
{
if (TryOrderCases(casesToExecute))
Run(testClass, casesToExecute);
foreach (var @case in casesToExecute)
classResult.Add(@case.Exceptions.Any() ? Fail(@case) : Pass(@case));
}
if (parameterGenerationFailures.Any())
{
var casesToFailWithoutRunning = parameterGenerationFailures.ToArray();
TryOrderCases(casesToFailWithoutRunning);
foreach (var caseToFailWithoutRunning in casesToFailWithoutRunning)
classResult.Add(Fail(caseToFailWithoutRunning));
}
return classResult;
}
示例7: Run
public ClassResult Run(Type testClass)
{
var methods = methodDiscoverer.TestMethods(testClass);
var cases = new List<Case>();
var parameterGenerationFailures = new List<Case>();
foreach (var method in methods)
{
try
{
bool methodHasParameterizedCase = false;
foreach (var parameters in Parameters(method))
{
methodHasParameterizedCase = true;
cases.Add(new Case(method, parameters));
}
if (!methodHasParameterizedCase)
cases.Add(new Case(method));
}
catch (Exception parameterGenerationException)
{
var @case = new Case(method);
@case.Fail(parameterGenerationException);
parameterGenerationFailures.Add(@case);
}
}
var casesBySkipState = cases.ToLookup(SkipCase);
var casesToSkip = casesBySkipState[true].ToArray();
var casesToExecute = casesBySkipState[false].ToArray();
var classResult = new ClassResult(testClass.FullName);
if (casesToSkip.Any())
{
TryOrderCases(casesToSkip);
foreach (var @case in casesToSkip)
classResult.Add(Skip(@case));
}
if (casesToExecute.Any())
{
if (TryOrderCases(casesToExecute))
Run(testClass, casesToExecute);
foreach (var @case in casesToExecute)
classResult.Add(@case.Exceptions.Any() ? Fail(@case) : Pass(@case));
}
if (parameterGenerationFailures.Any())
{
var casesToFailWithoutRunning = parameterGenerationFailures.ToArray();
TryOrderCases(casesToFailWithoutRunning);
foreach (var caseToFailWithoutRunning in casesToFailWithoutRunning)
classResult.Add(Fail(caseToFailWithoutRunning));
}
return classResult;
}