Using Ninject with mocks in F#

♀尐吖头ヾ 提交于 2019-12-13 18:36:03

问题


This question is part of larger question that can be found here

As in out production code we use Ninject and constructor injection our services tend to look like this

public class Service : IService
{
    private readonly IRepository _repository;

    public Service(IRepository repository)
    {
        _repository = repository;
    }

    public Task<IEnumerable<SelectOption>> GetAlLogicOptions()
    {
        return  _repository.GetOptionsAsync();
    }
}

how ever list of constructor parameters may and will change over time. This is the reason that we want to have IoC to also be used in tests.

In C# NUnit this is quite easy as we have Ninject.MockingKernel that always provides mock implementation and in each test fixture we just rebind sut to it real implementation.

How to achieve same thing in F# xUnit.

来源:https://stackoverflow.com/questions/35765611/using-ninject-with-mocks-in-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!