Skip to content

Commit

Permalink
Changed signature of CallFormatter.Format to pass ArgumentMatchInfo i…
Browse files Browse the repository at this point in the history
…nstead

  of indicies of arguments to highlight.
  • Loading branch information
dtchepak committed Dec 29, 2011
1 parent 7be0b76 commit 3a9702b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
7 changes: 1 addition & 6 deletions Source/NSubstitute.Specs/CallFormatterSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,10 @@ public override CallFormatter CreateSubjectUnderTest()
}

private void AssertCallFormat(Action<ISample> callOnSubstitute, string expectedFormat)
{
AssertCallFormat(callOnSubstitute, new int[0], expectedFormat);
}

private void AssertCallFormat(Action<ISample> callOnSubstitute, IEnumerable<int> argumentsToHighlight, string expectedFormat)
{
callOnSubstitute(_sampleSub);
var call = _sampleSub.ReceivedCalls().First();
var format = sut.Format(call.GetMethodInfo(), call.GetArguments(), argumentsToHighlight);
var format = sut.Format(call.GetMethodInfo(), call.GetArguments(), new ArgumentMatchInfo[0]);
Assert.That(format, Is.EqualTo(expectedFormat));
}

Expand Down
4 changes: 3 additions & 1 deletion Source/NSubstitute.Specs/CallSpecificationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public override void Context()
{
base.Context();
_callFormatter = mock<ICallFormatter>();
_callFormatter.stub(x => x.Format(_methodInfoSpecified, new[] { _firstArgSpec, _secondArgSpec }, new int[0])).Return(FormattedCall);
_callFormatter
.stub(x => x.Format(_methodInfoSpecified, new[] { _firstArgSpec, _secondArgSpec }, new ArgumentMatchInfo[0]))
.Return(FormattedCall);
}

public override void Because()
Expand Down
6 changes: 3 additions & 3 deletions Source/NSubstitute/Core/CallFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public CallFormatter(IArgumentsFormatter argumentsFormatter)

public string Format(ICall call, ICallSpecification withRespectToCallSpec)
{
return Format(call.GetMethodInfo(), call.GetArguments(), withRespectToCallSpec.NonMatchingArguments(call).Select(x=> x.Index));
return Format(call.GetMethodInfo(), call.GetArguments(), withRespectToCallSpec.NonMatchingArguments(call));
}

public string Format(MethodInfo methodInfoOfCall, IEnumerable<object> arguments, IEnumerable<int> argumentsToHighlight)
public string Format(MethodInfo methodInfoOfCall, IEnumerable<object> arguments, IEnumerable<ArgumentMatchInfo> nonMatchingArguments)
{
return _methodInfoFormatters
.First(x => x.CanFormat(methodInfoOfCall))
.Format(methodInfoOfCall, arguments, argumentsToHighlight);
.Format(methodInfoOfCall, arguments, nonMatchingArguments.Select(x => x.Index));
}
}
}
2 changes: 1 addition & 1 deletion Source/NSubstitute/Core/CallSpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public bool IsSatisfiedBy(ICall call)

public string Format(ICallFormatter callFormatter)
{
return callFormatter.Format(_methodInfo, _argumentSpecifications, new int[0]);
return callFormatter.Format(_methodInfo, _argumentSpecifications, new ArgumentMatchInfo[0]);
}

public IEnumerable<ArgumentMatchInfo> NonMatchingArguments(ICall call)
Expand Down
3 changes: 2 additions & 1 deletion Source/NSubstitute/Core/ICallFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using System.Reflection;
using NSubstitute.Core.Arguments;

namespace NSubstitute.Core
{
public interface ICallFormatter
{
string Format(ICall call, ICallSpecification withRespectToCallSpec);
string Format(MethodInfo methodInfoOfCall, IEnumerable<object> arguments, IEnumerable<int> argumentsToHighlight);
string Format(MethodInfo methodInfoOfCall, IEnumerable<object> arguments, IEnumerable<ArgumentMatchInfo> nonMatchingArguments);
}
}

0 comments on commit 3a9702b

Please sign in to comment.