本文整理汇总了C#中IInterceptedFakeObjectCall类的典型用法代码示例。如果您正苦于以下问题:C# IInterceptedFakeObjectCall类的具体用法?C# IInterceptedFakeObjectCall怎么用?C# IInterceptedFakeObjectCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IInterceptedFakeObjectCall类属于命名空间,在下文中一共展示了IInterceptedFakeObjectCall类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
Guard.AgainstNull(fakeObjectCall, nameof(fakeObjectCall));
var returnType = fakeObjectCall.Method.ReturnType;
if (typeof(Task).GetTypeInfo().IsAssignableFrom(returnType))
{
Task task;
if (returnType == typeof(Task))
{
task = TaskHelper.Canceled();
}
else
{
var taskResultType = returnType.GetTypeInfo().GetGenericArguments()[0];
task = TaskHelper.Canceled(taskResultType);
}
fakeObjectCall.SetReturnValue(task);
}
else
{
var token = GetCanceledTokens(fakeObjectCall).First();
token.ThrowIfCancellationRequested();
}
}
示例2: Apply
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
Guard.AgainstNull(fakeObjectCall, "fakeObjectCall");
var returnValue = ResolveReturnValue(fakeObjectCall);
fakeObjectCall.SetReturnValue(returnValue);
}
示例3: Apply
/// <summary>
/// Applies an action to the call, might set a return value or throw
/// an exception.
/// </summary>
/// <param name="fakeObjectCall">The call to apply the interceptor to.</param>
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
Guard.AgainstNull(fakeObjectCall, "fakeObjectCall");
var parameters = fakeObjectCall.Arguments.GetUnderlyingArgumentsArray();
var valueFromWrappedInstance = fakeObjectCall.Method.Invoke(this.wrappedObject, parameters);
fakeObjectCall.SetReturnValue(valueFromWrappedInstance);
}
示例4:
void IFakeObjectCallRule.Apply(IInterceptedFakeObjectCall invocation)
{
this.ApplyWasCalled = true;
if (this.Apply != null)
{
this.Apply(invocation);
}
}
示例5: ResolveReturnValue
public static object ResolveReturnValue(IInterceptedFakeObjectCall fakeObjectCall)
{
object result;
if (!FakeManager.TryCreateDummy(fakeObjectCall.Method.ReturnType, out result))
{
return fakeObjectCall.Method.ReturnType.GetDefaultValue();
}
return result;
}
示例6: Apply
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
var newRule = new CallRuleMetadata
{
CalledNumberOfTimes = 1,
Rule = new PropertyBehaviorRule(fakeObjectCall.Method, this.FakeManager) { Value = fakeObjectCall.Arguments[0] }
};
this.FakeManager.allUserRulesField.AddFirst(newRule);
}
示例7: Apply
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
var newRule = new CallRuleMetadata
{
Rule = new PropertyBehaviorRule(fakeObjectCall.Method, FakeManager) { Value = CreateFake(fakeObjectCall.Method.ReturnType) },
CalledNumberOfTimes = 1
};
this.FakeManager.allUserRulesField.AddFirst(newRule);
newRule.Rule.Apply(fakeObjectCall);
}
示例8: TryHandleGetHashCode
private bool TryHandleGetHashCode(IInterceptedFakeObjectCall fakeObjectCall)
{
if (!IsSameMethod(fakeObjectCall.Method, ObjectMethods[2]))
{
return false;
}
fakeObjectCall.SetReturnValue(this.fakeManager.GetHashCode());
return true;
}
示例9: TryHandleGetHashCode
private bool TryHandleGetHashCode(IInterceptedFakeObjectCall fakeObjectCall)
{
if (!fakeObjectCall.Method.MethodHandle.Equals(ObjectMethodsMethodHandles[2]))
{
return false;
}
fakeObjectCall.SetReturnValue(this.FakeManager.GetHashCode());
return true;
}
示例10: TryHandleToString
private bool TryHandleToString(IInterceptedFakeObjectCall fakeObjectCall)
{
if (!fakeObjectCall.Method.MethodHandle.Equals(ObjectMethodsMethodHandles[1]))
{
return false;
}
fakeObjectCall.SetReturnValue("Faked {0}".FormatInvariant(this.FakeManager.FakeObjectType.FullName));
return true;
}
示例11: ResolveReturnValue
private static object ResolveReturnValue(IInterceptedFakeObjectCall fakeObjectCall)
{
object result = null;
if (!FakeManager.TryCreateDummy(fakeObjectCall.Method.ReturnType, out result))
{
result = Helpers.GetDefaultValueOfType(fakeObjectCall.Method.ReturnType);
}
return result;
}
示例12: ApplyNext
/// <summary>
/// Applies the call if the call has been recorded.
/// </summary>
/// <param name="fakeObjectCall">The call to apply to from recording.</param>
public void ApplyNext(IInterceptedFakeObjectCall fakeObjectCall)
{
this.AssertThatCallQueueIsNotEmpty();
var callToApply = this.callQueue.Dequeue();
AssertThatMethodsMatches(fakeObjectCall, callToApply);
ApplyOutputArguments(fakeObjectCall, callToApply);
fakeObjectCall.SetReturnValue(callToApply.RecordedCall.ReturnValue);
callToApply.HasBeenApplied = true;
}
示例13: Apply
/// <summary>
/// Applies an action to the call, might set a return value or throw
/// an exception.
/// </summary>
/// <param name="fakeObjectCall">The call to apply the interceptor to.</param>
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
if (this.recorder.IsRecording)
{
this.wrappedRule.Apply(fakeObjectCall);
this.recorder.RecordCall(fakeObjectCall.AsReadOnly());
}
else
{
this.recorder.ApplyNext(fakeObjectCall);
}
}
示例14: Apply
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
if (this.IsPropertyGetter(fakeObjectCall))
{
fakeObjectCall.SetReturnValue(this.Value);
}
else
{
this.Value = fakeObjectCall.Arguments[0];
}
this.fakeManager.MoveRuleToFront(this);
}
示例15: Apply
public void Apply(IInterceptedFakeObjectCall fakeObjectCall)
{
Guard.AgainstNull(fakeObjectCall, "fakeObjectCall");
if (this.IsPropertyGetter(fakeObjectCall))
{
fakeObjectCall.SetReturnValue(this.Value);
}
else
{
this.Value = fakeObjectCall.Arguments.Last();
}
this.fakeManager.MoveRuleToFront(this);
}