Giter Site home page Giter Site logo

Identifying substitutes about nsubstitute HOT 7 OPEN

nsubstitute avatar nsubstitute commented on May 18, 2024 1
Identifying substitutes

from nsubstitute.

Comments (7)

dtchepak avatar dtchepak commented on May 18, 2024 2

@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.

Brains avatar Brains commented on May 18, 2024

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.

zvirja avatar zvirja commented on May 18, 2024

@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.

dtchepak avatar dtchepak commented on May 18, 2024

@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.

dtchepak avatar dtchepak commented on May 18, 2024

#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.

zvirja avatar zvirja commented on May 18, 2024

@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.

ryantheleach avatar ryantheleach commented on May 18, 2024

This would make tests far more readable, +1 from me.

from nsubstitute.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.