-
Notifications
You must be signed in to change notification settings - Fork 179
/
CastleInvocationCallAdapter.cs
95 lines (85 loc) · 3.27 KB
/
CastleInvocationCallAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
namespace FakeItEasy.Creation.CastleDynamicProxy
{
using System;
using System.Diagnostics;
using System.Reflection;
using Castle.DynamicProxy;
using FakeItEasy.Configuration;
using FakeItEasy.Core;
/// <summary>
/// An adapter that adapts an <see cref="IInvocation" /> to a <see cref="IFakeObjectCall" />.
/// </summary>
internal class CastleInvocationCallAdapter
: InterceptedFakeObjectCall
{
private readonly IInvocation invocation;
private readonly object[] originalArguments;
/// <summary>
/// Initializes a new instance of the <see cref="CastleInvocationCallAdapter"/> class.
/// </summary>
/// <param name="invocation">The invocation.</param>
[DebuggerStepThrough]
public CastleInvocationCallAdapter(IInvocation invocation)
{
this.invocation = invocation;
var savedArguments = new object[invocation.Arguments.Length];
Array.Copy(invocation.Arguments, savedArguments, savedArguments.Length);
this.originalArguments = savedArguments;
this.Method = invocation.Method;
this.Arguments = new ArgumentCollection(invocation.Arguments, invocation.Method);
}
/// <summary>
/// Gets the method that's called.
/// </summary>
public override MethodInfo Method { get; }
/// <summary>
/// Gets the arguments used in the call.
/// </summary>
public override ArgumentCollection Arguments { get; }
/// <summary>
/// Gets the faked object the call is performed on.
/// </summary>
public override object FakedObject => this.invocation.Proxy;
public override object ReturnValue
{
get => this.invocation.ReturnValue;
set => this.invocation.ReturnValue = value;
}
/// <summary>
/// Returns a completed call suitable for being recorded.
/// </summary>
/// <returns>A completed fake object call.</returns>
public override CompletedFakeObjectCall ToCompletedCall()
{
return new CompletedFakeObjectCall(
this,
this.originalArguments);
}
/// <summary>
/// Calls the base method, should not be used with interface types.
/// </summary>
public override void CallBaseMethod()
{
this.invocation.Proceed();
}
/// <summary>
/// Sets the specified value to the argument at the specified index.
/// </summary>
/// <param name="index">The index of the argument to set the value to.</param>
/// <param name="value">The value to set to the argument.</param>
public override void SetArgumentValue(int index, object value)
{
this.invocation.SetArgumentValue(index, value);
}
/// <summary>
/// Returns a description of the call.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
return this.GetDescription();
}
}
}