ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 363 forks source link

[Question]How to use nsubstitute with zenject? #598

Open loverainstm opened 5 years ago

loverainstm commented 5 years ago

we want to use nsubstitute for automation test. any suggestion? thanks a lot.

svermeulen commented 5 years ago

This should be possible. I'm not familiar with nsubstitute, but can you just pass in the instance that nsubstitute generates using FromInstance?

Mathijs-Bakker commented 5 years ago

`[TestFixture] public class PlayerMovementTests : ZenjectUnitTestFixture {

    private PlayerMovement _sut;
    private MovementDirection _movementDirection;

    [SetUp]
    public void CommonInstall()
    {
        _movementDirection = Substitute.For<MovementDirection>();

        Container
            .Bind<MovementDirection>()
            .FromInstance(_movementDirection);

        Container
            .Bind<PlayerMovement>()
            .AsSingle();

        _sut = Container.Resolve<PlayerMovement>();
    }

}`

Mathijs-Bakker commented 4 years ago

NSubstitute has been added to the optional extras. https://github.com/Mathijs-Bakker/Extenject/blob/master/Documentation/AutoMocking.md