-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Extend PartsOf to mock non-virtual methods implementing an i… #700
base: main
Are you sure you want to change the base?
Changes from all commits
e58685a
05cb82c
7940897
266ace9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace NSubstitute.Exceptions | ||
Check failure on line 3 in src/NSubstitute/Exceptions/TypeForwardingException.cs GitHub Actions / format-verify
Check failure on line 3 in src/NSubstitute/Exceptions/TypeForwardingException.cs GitHub Actions / format-verify
|
||
{ | ||
public abstract class TypeForwardingException : SubstituteException | ||
{ | ||
protected TypeForwardingException(string message) : base(message) { } | ||
} | ||
|
||
public sealed class CanNotForwardCallsToClassNotImplementingInterfaceException : TypeForwardingException | ||
{ | ||
public CanNotForwardCallsToClassNotImplementingInterfaceException(Type type) : base(DescribeProblem(type)) { } | ||
private static string DescribeProblem(Type type) | ||
{ | ||
return string.Format("The provided class '{0}' doesn't implement all requested interfaces. ", type.Name); | ||
} | ||
} | ||
|
||
public sealed class CanNotForwardCallsToAbstractClassException : TypeForwardingException | ||
{ | ||
public CanNotForwardCallsToAbstractClassException(Type type) : base(DescribeProblem(type)) { } | ||
private static string DescribeProblem(Type type) | ||
{ | ||
return string.Format("The provided class '{0}' is abstract. ", type.Name); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
|
||
|
||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: additional blank lines not required |
||
using NSubstitute.Core; | ||
|
||
namespace NSubstitute.Proxies; | ||
|
||
[Obsolete("This class is deprecated and will be removed in future versions of the product.")] | ||
public class ProxyFactory(IProxyFactory delegateFactory, IProxyFactory dynamicProxyFactory) : IProxyFactory | ||
{ | ||
public object GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[]? additionalInterfaces, object?[]? constructorArguments) | ||
|
||
public object GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[]? additionalInterfaces, bool isPartial, object?[]? constructorArguments) | ||
{ | ||
var isDelegate = typeToProxy.IsDelegate(); | ||
return isDelegate | ||
? delegateFactory.GenerateProxy(callRouter, typeToProxy, additionalInterfaces, constructorArguments) | ||
: dynamicProxyFactory.GenerateProxy(callRouter, typeToProxy, additionalInterfaces, constructorArguments); | ||
? delegateFactory.GenerateProxy(callRouter, typeToProxy, additionalInterfaces, isPartial, constructorArguments) | ||
: dynamicProxyFactory.GenerateProxy(callRouter, typeToProxy, additionalInterfaces, isPartial, constructorArguments); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
using NSubstitute.Core; | ||
|
||
// Disable nullability for client API, so it does not affect clients. | ||
|
@@ -89,4 +90,19 @@ | |
var substituteFactory = SubstitutionContext.Current.SubstituteFactory; | ||
return (T)substituteFactory.CreatePartial([typeof(T)], constructorArguments); | ||
} | ||
|
||
public static T ForTypeForwardingTo<T,TClass>(params object[] constructorArguments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore: could you please add doc comments here (see |
||
where T : class | ||
{ | ||
var substituteFactory = SubstitutionContext.Current.SubstituteFactory; | ||
return (T)substituteFactory.CreatePartial(new[] { typeof(T), typeof(TClass) }, constructorArguments); | ||
Check failure on line 98 in src/NSubstitute/Substitute.cs GitHub Actions / format-verify
Check failure on line 98 in src/NSubstitute/Substitute.cs GitHub Actions / format-verify
|
||
} | ||
|
||
Comment on lines
90
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: not sure if it is just the diff view but the code indenting looks non-standard here? |
||
//public static T ForTypeForwardingTo<T, T2, T3>(params object[] constructorArguments) | ||
// where T : class | ||
//{ | ||
// var substituteFactory = SubstitutionContext.Current.SubstituteFactory; | ||
// return (T)substituteFactory.CreatePartial(new[] { typeof(T), typeof(TClass) }, constructorArguments); | ||
//} | ||
Comment on lines
+101
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore (nitpick): please remove commented out code. |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (nitpick): several of these changed files have a blank line to added to start. Is this an editorconfig thing or accidental?