Skip to content

Commit

Permalink
Make CompletedFakeObjectCall not read-only
Browse files Browse the repository at this point in the history
and refactor InterceptedFakeObjectCall a bit
  • Loading branch information
thomaslevesque committed Nov 14, 2019
1 parent 5c27afd commit b13cba7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
5 changes: 2 additions & 3 deletions src/FakeItEasy/Core/CompletedFakeObjectCall.cs
Expand Up @@ -5,17 +5,16 @@ namespace FakeItEasy.Core

internal class CompletedFakeObjectCall : ICompletedFakeObjectCall
{
public CompletedFakeObjectCall(IInterceptedFakeObjectCall interceptedCall, object[] arguments, object returnValue)
public CompletedFakeObjectCall(IInterceptedFakeObjectCall interceptedCall, object[] arguments)
{
this.FakedObject = interceptedCall.FakedObject;
this.Method = interceptedCall.Method;
this.Arguments = new ArgumentCollection(arguments, this.Method);
this.ArgumentsAfterCall = interceptedCall.Arguments;
this.ReturnValue = returnValue;
this.SequenceNumber = SequenceNumberManager.GetNextSequenceNumber();
}

public object ReturnValue { get; }
public object ReturnValue { get; set; }

public MethodInfo Method { get; }

Expand Down
6 changes: 3 additions & 3 deletions src/FakeItEasy/Core/FakeManager.cs
Expand Up @@ -159,8 +159,8 @@ void IFakeCallProcessor.Process(InterceptedFakeObjectCall fakeObjectCall)
listenerNode.Value.OnBeforeCallIntercepted(fakeObjectCall);
}

var readonlyCall = fakeObjectCall.AsReadOnly();
this.RecordCall(readonlyCall);
var callToRecord = fakeObjectCall.ToCompletedCall();
this.RecordCall(callToRecord);

try
{
Expand All @@ -170,7 +170,7 @@ void IFakeCallProcessor.Process(InterceptedFakeObjectCall fakeObjectCall)
{
for (var listenerNode = this.interceptionListeners.Last; listenerNode is object; listenerNode = listenerNode.Previous)
{
listenerNode.Value.OnAfterCallIntercepted(readonlyCall);
listenerNode.Value.OnAfterCallIntercepted(callToRecord);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/FakeItEasy/Core/InterceptedFakeObjectCall.cs
Expand Up @@ -21,10 +21,15 @@ internal abstract class InterceptedFakeObjectCall : IInterceptedFakeObjectCall
public abstract MethodInfo Method { get; }

/// <summary>
/// Freezes the call so that it can no longer be modified.
/// Gets or sets the return value of the call.
/// </summary>
public abstract object ReturnValue { get; set; }

/// <summary>
/// Returns a completed call suitable for being recorded.
/// </summary>
/// <returns>A completed fake object call.</returns>
public abstract CompletedFakeObjectCall AsReadOnly();
public abstract CompletedFakeObjectCall ToCompletedCall();

/// <summary>
/// Calls the base method, should not be used with interface types.
Expand All @@ -38,10 +43,6 @@ internal abstract class InterceptedFakeObjectCall : IInterceptedFakeObjectCall
/// <param name="value">The value to set to the argument.</param>
public abstract void SetArgumentValue(int index, object value);

/// <summary>
/// Sets the return value of the call.
/// </summary>
/// <param name="returnValue">The return value.</param>
public abstract void SetReturnValue(object returnValue);
void IInterceptedFakeObjectCall.SetReturnValue(object returnValue) => this.ReturnValue = returnValue;
}
}
Expand Up @@ -46,16 +46,21 @@ public CastleInvocationCallAdapter(IInvocation invocation)
/// </summary>
public override object FakedObject => this.invocation.Proxy;

public override object ReturnValue
{
get => this.invocation.ReturnValue;
set => this.invocation.ReturnValue = value;
}

/// <summary>
/// Freezes the call so that it can no longer be modified.
/// Returns a completed call suitable for being recorded.
/// </summary>
/// <returns>A completed fake object call.</returns>
public override CompletedFakeObjectCall AsReadOnly()
public override CompletedFakeObjectCall ToCompletedCall()
{
return new CompletedFakeObjectCall(
this,
this.originalArguments,
this.invocation.ReturnValue);
this.originalArguments);
}

/// <summary>
Expand All @@ -76,16 +81,6 @@ public override void SetArgumentValue(int index, object value)
this.invocation.SetArgumentValue(index, value);
}

/// <summary>
/// Sets the return value of the call.
/// </summary>
/// <param name="returnValue">The return value.</param>
[DebuggerStepThrough]
public override void SetReturnValue(object returnValue)
{
this.invocation.ReturnValue = returnValue;
}

/// <summary>
/// Returns a description of the call.
/// </summary>
Expand Down
Expand Up @@ -204,19 +204,14 @@ public DelegateFakeObjectCall(Delegate instance, MethodInfo method, object[] arg
this.Method = method;
}

public object ReturnValue { get; private set; }
public override object ReturnValue { get; set; }

public override MethodInfo Method { get; }

public override ArgumentCollection Arguments { get; }

public override object FakedObject { get; }

public override void SetReturnValue(object value)
{
this.ReturnValue = value;
}

public override void CallBaseMethod()
{
throw new FakeConfigurationException(ExceptionMessages.DelegateCannotCallBaseMethod);
Expand All @@ -227,12 +222,11 @@ public override void SetArgumentValue(int index, object value)
this.Arguments.GetUnderlyingArgumentsArray()[index] = value;
}

public override CompletedFakeObjectCall AsReadOnly()
public override CompletedFakeObjectCall ToCompletedCall()
{
return new CompletedFakeObjectCall(
this,
this.originalArguments,
this.ReturnValue);
this.originalArguments);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/FakeItEasy.Tests/Core/FakeManagerTests.cs
Expand Up @@ -379,7 +379,7 @@ public void Should_invoke_listener_after_call_has_been_intercepted()
// Arrange
var completedCall = A.Dummy<CompletedFakeObjectCall>();
var interceptedCall = A.Fake<InterceptedFakeObjectCall>();
A.CallTo(() => interceptedCall.AsReadOnly()).Returns(completedCall);
A.CallTo(() => interceptedCall.ToCompletedCall()).Returns(completedCall);

var listener = A.Fake<IInterceptionListener>();
var manager = new FakeManager(typeof(int), 0, null);
Expand All @@ -399,7 +399,7 @@ public void Should_invoke_listener_after_call_has_been_intercepted_when_applicat
// Arrange
var completedCall = A.Dummy<CompletedFakeObjectCall>();
var interceptedCall = A.Fake<InterceptedFakeObjectCall>();
A.CallTo(() => interceptedCall.AsReadOnly()).Returns(completedCall);
A.CallTo(() => interceptedCall.ToCompletedCall()).Returns(completedCall);

var listener = A.Fake<IInterceptionListener>();
var manager = new FakeManager(typeof(int), 0, null);
Expand Down

0 comments on commit b13cba7

Please sign in to comment.