vendredi 22 novembre 2019

How to use IServiceCollection in .Net Core Integration Tests

I want to prepare integration tests for my project but it's not connected to a specyfic request and I don't want to use mocked TestServer. In unit tests we use AutoMoq IFixture and I would like to make something like that:

[TestFixture]
internal class MyClassTests
{
    private IFixture _fixture;

    [SetUp]
    public void SetUp()
    {
        _fixture = new Fixture().Customize(serviceCollection => serviceCollection.AddProjectServices());
    }

    public CreateSut()
    {
        return _fixture.Create<MyClass>();
    }
}

Is it possible to inject real classes to Fixture like it is done in Startup?

Aucun commentaire:

Enregistrer un commentaire