-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Give mocks names #76
Merged
Merged
Give mocks names #76
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
da5bd5f
Add naming to mock objects, to make them more easily distinguishable …
d8b30e0
Add mock names to proxy instances in addition to the mocks themselves
c0f5262
Extend mock naming to mock names of classes, in addition to instances.
pimterry 89f063d
Use C# code provider to get clean simple type names in tricky cases (…
pimterry f6748bc
Split Mock property & ToString mixins into separate intercept strategies
pimterry 9e4e589
Small refactorings around mock naming to clarify tests and proxy help…
pimterry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using Castle.DynamicProxy; | ||
|
||
namespace Moq.Proxy | ||
{ | ||
/// <summary> | ||
/// Hook used to tells Castle which methods to proxy in mocked classes. | ||
/// | ||
/// Here we proxy the default methods Castle suggests (everything Object's methods) | ||
/// plus Object.ToString(), so we can give mocks useful default names. | ||
/// | ||
/// This is required to allow Moq to mock ToString on proxy *class* implementations. | ||
/// </summary> | ||
internal class ProxyMethodHook : AllMethodsHook | ||
{ | ||
/// <summary> | ||
/// Extends AllMethodsHook.ShouldInterceptMethod to also intercept Object.ToString(). | ||
/// </summary> | ||
public override bool ShouldInterceptMethod(Type type, MethodInfo methodInfo) | ||
{ | ||
var isObjectToString = methodInfo.DeclaringType == typeof(Object) && methodInfo.Name == "ToString"; | ||
return base.ShouldInterceptMethod(type, methodInfo) || isObjectToString; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The base class used for all our interface-inheriting proxies, which overrides the default | ||
/// Object.ToString() behavior, to route it via the mock by default, unless overriden by a | ||
/// real implementation. | ||
/// | ||
/// This is required to allow Moq to mock ToString on proxy *interface* implementations. | ||
/// </summary> | ||
internal abstract class InterfaceProxy | ||
{ | ||
public override string ToString() | ||
{ | ||
return ((IMocked)this).Mock.ToString() + ".Object"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice trick here! :)