Comments (7)
@zvirja I think there are still some legitimate use cases not covered by the current id scheme.
For mocking in acceptance tests like https://gist.github.com/GraemeF/b759fa100814bd04eb11 I don't think a random identifier will assist in finding the source of the substitute. Instead if we could tag a substitute on creation (something like var estate = Substitute.For<IEstate>(); estate.LabelSubstitute("Estate from DB"); Inject(estate);
) then the output could show the substitute label. I think it would be useful to see:
ReceivedCallsException : Expected to receive a call matching:
Blah(1, <Estate from DB>)
Actually received no matching calls.
Received 2 non-matching calls (non-matching arguments indicated with '*' characters):
Blah(1, *<Substitute.IEstate|34c247>*)
Blah(1, *<Estate from cache>*)
I'm happy to wait on another request and a real example (I had lots a long time ago on a previous project, but nothing current) before progressing with this though. :)
from nsubstitute.
I need it too.
I want to mark my substitutes in the Output window because now I have this:
Expected: not collection containing <Castle.Proxies.IFormProxy>
But was: < <Castle.Proxies.IFormProxy>, <Castle.Proxies.IFormProxy> >
I want this:
Expected: not collection containing <Bad>
But was: < <Good>, <Bad> >
from nsubstitute.
@dtchepak What if we simply override ToString()
to return the incremental number? That will be like Substitute #42
, Substitute #421
. It should provide the desirable value.
from nsubstitute.
@zvirja I think it would be useful to add a custom description. And I think we should avoid overriding ToString()
for classes that could already have a reasonable implementation. But a reasonable first pass could be auto-numbering for interfaces.
from nsubstitute.
#379 partially addresses this by giving substitutes identifiers based on hashCode, but I would still like the feature of being able to "name" a specific instance of a substitute as per CompleteBrains' comment.
See Zvirja's notes on this PR for some suggestions on implementing this with ProxyIdInterceptor
.
from nsubstitute.
@dtchepak I'm not sure we need this feature 😕 Sure, it's interesting from the technical perspective, but I don't see much value in it. The already merged PR allows you to clearly indentify the substitute. The id consists of type name and hash code. It's unlikely that often we will be able to find the better name than resolver
for IFooResolver
or factManager
for IFactManager
. As result, the feature might be required really rarely, if never.
The main concern from @CompleteBrains what that it was impossible to recognize the substitute and it was addressed.
I'd suggest to close the issue as is and reopen it later only if there are explicit requests for it. It will allow us to see how it goes with the current way and whether we really need it. WDYT? 😉
from nsubstitute.
This would make tests far more readable, +1 from me.
from nsubstitute.
Related Issues (20)
- How to name a satellite nuget package designed to work with NSubstitute? HOT 7
- Argument matcher for a struct with a field with non-default value HOT 3
- How to argument match the generic parameter of a Func<T> with generic constraints?
- Arg.Is<object[]> is not working as expected HOT 2
- NSubstitute makes it impossible to unit test memory leaks HOT 4
- NSubstitute Received() verifies different function in substite. HOT 2
- Proposition: Mark as unlisted and Deprecated some old versions HOT 4
- Library is not compatible with .NET MAUI 8.0.6 HOT 4
- How can I pass event args to event with Func<TEventArgs, Task>? HOT 2
- Add ability to capture and verify on an argument at the same time HOT 1
- Provide more intuitive methods HOT 3
- NSubstitute.Exceptions.SubstituteInternalException HOT 1
- IMemoryCache TryGetValue mocking not working HOT 2
- Unable to match arguments whose type is generic, when their concrete type is not known HOT 1
- Arg.Any<Arg.AnyType>() does not match arguments passed by reference
- Provide a way to pass null for custom event args so that Raise.EventWith can be used to raise events for custom event args without a default constructor
- I can't test code that has dbcontext.SomeEntity.SingleOrDefault() HOT 2
- I'm receiving NSubstitute.Exceptions.NotASubstituteException when I shouldn't HOT 3
- Need to release 5.2.0 HOT 6
- Configured calls to 'hidden' properties are not matched HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nsubstitute.