如何对服务类内的存储库的虚假实现进行单元测试?
我有一个对象,它保存多种语言的消息,在我的项目中称为 LookupString。
我还有一个该实体的存储库,它是 LookupTableRepository,它是从 ILookupTableRepository 实现的。
我有一个名为 LookupTableProvider 的服务类。这只是为了调用存储库。它只有一种方法,即 GetEntry(string id,cultureinfoculture),它能够获取我想要的指定区域性的消息。
现在我想对持有存储库的 LookupTableProvider 进行单元测试。但我希望为此目的使用一个假存储库,因为最小起订量对我没有多大帮助,因为我只想测试提供程序的实现。
如果我使用 Ninject ,使单元测试提供程序成为假存储库的实现的最佳方法是什么?我如何调用 ninject 来给我这个假存储库的实例?
I have an object which hold a message in many language this is called a LookupString in my project.
I have also a repository for this entity which is LookupTableRepository which is implemented from ILookupTableRepository.
I have a service class which is called LookupTableProvider.. this is simply to call out the repository. It only got one method which is GetEntry(string id, cultureinfo culture) which enable to get a message in the specified culture i want.
Now i want to unit test the LookupTableProvider which hold a repository.. but i wish to use a fake repository for this purpose since a moq won't help me much there since i only want to test the implementation of the provider.
What is the best way to make the unit test provider me an implementation of the fake repository if i use Ninject ? How i can call ninject to give me an instance of this fake repository ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该使用 IoC 容器对您的类进行单元测试。只需新建您的 Provider 并将所有模拟传递给构造函数即可。
You shouldn't use an IoC Container for unit testing your classes. Simply new up your Provider and pass all mocks to the constructor.