AutofacContrib.NSubstitute | Automocking container for Autofac | Dependency Injection library
kandi X-RAY | AutofacContrib.NSubstitute Summary
kandi X-RAY | AutofacContrib.NSubstitute Summary
[NuGet version] An auto-mocking Autofac container that resolves unknown dependencies from NSubstitute. Useful for unit testing classes with lots of dependencies.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of AutofacContrib.NSubstitute
AutofacContrib.NSubstitute Key Features
AutofacContrib.NSubstitute Examples and Code Snippets
Community Discussions
Trending Discussions on AutofacContrib.NSubstitute
QUESTION
I used to use Moq and AutoMoqer in unit tests, but my team has decided to change to NSubstitute. We use DI heavily, so I'd like to be able to ask for a target to test and have that target automatically given all mocked objects to its constructor, or in other words a DI container that passes in mocks. I also want to modify those mocked objects as necessary.
Example using Moq/AutoMoq/MSTest
...ANSWER
Answered 2017-Oct-06 at 05:48I little bid confused when you call Autofixture
a Dependency Injection container. It is not.
AutoFixture
is simply generate values/instances you don't care about in current test, but they cannot hold default values.
In your case, you correctly created mock of IPromise
, but class under test doesn't know about it. AutoFixture have generated "own" instance and pass it to class under test.
You should create instance of class under test manually - because you need full control of all dependencies - for documentation reasons, where other developers can see how object created
You can use AutoFixture for dependencies you do not care about in the particular test, but for getting class under test work properly this dependency should return some value (not null or default values).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install AutofacContrib.NSubstitute
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page