Pulling out argument compatiblility check from ArgumentSpecification into AnyArgumentMatcher and delegating call.
This commit is contained in:
Родитель
33ea6fcf26
Коммит
017cde3cdc
|
@ -15,9 +15,15 @@ namespace NSubstitute.Core.Arguments
|
|||
|
||||
public bool IsSatisfiedBy(object argument)
|
||||
{
|
||||
if (argument == null) return true;
|
||||
var specifiedType = (_typeArgMustBeCompatibleWith.IsByRef) ? _typeArgMustBeCompatibleWith.GetElementType() : _typeArgMustBeCompatibleWith;
|
||||
return specifiedType.IsAssignableFrom(argument.GetType());
|
||||
return ArgumentIsCompatibleWithType(argument);
|
||||
}
|
||||
|
||||
private bool ArgumentIsCompatibleWithType(object argument)
|
||||
{
|
||||
var requiredType = (_typeArgMustBeCompatibleWith.IsByRef) ? _typeArgMustBeCompatibleWith.GetElementType() : _typeArgMustBeCompatibleWith;
|
||||
return argument == null ? TypeCanBeNull(requiredType) : requiredType.IsAssignableFrom(argument.GetType());
|
||||
}
|
||||
|
||||
private bool TypeCanBeNull(Type type) { return !type.IsValueType; }
|
||||
}
|
||||
}
|
|
@ -4,13 +4,15 @@ namespace NSubstitute.Core.Arguments
|
|||
{
|
||||
public class ArgumentSpecification : IArgumentSpecification
|
||||
{
|
||||
private readonly Type _forType;
|
||||
private readonly IArgumentMatcher _matcher;
|
||||
readonly Type _forType;
|
||||
readonly IArgumentMatcher _matcher;
|
||||
readonly IArgumentMatcher _compatibleMatcher;
|
||||
|
||||
public ArgumentSpecification(Type forType, IArgumentMatcher matcher)
|
||||
{
|
||||
_forType = forType;
|
||||
_matcher = matcher;
|
||||
_compatibleMatcher = new AnyArgumentMatcher(forType);
|
||||
Action = x => { };
|
||||
}
|
||||
|
||||
|
@ -27,10 +29,7 @@ namespace NSubstitute.Core.Arguments
|
|||
|
||||
private bool ArgumentIsCompatibleWithType(object argument)
|
||||
{
|
||||
var requiredType = (ForType.IsByRef) ? ForType.GetElementType() : ForType;
|
||||
return argument == null ? TypeCanBeNull(requiredType) : requiredType.IsAssignableFrom(argument.GetType());
|
||||
return _compatibleMatcher.IsSatisfiedBy(argument);
|
||||
}
|
||||
|
||||
private bool TypeCanBeNull(Type type) { return !type.IsValueType; }
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче