如何模拟实现多个接口的类 [英] How to mock a class that implements multiple interfaces
本文介绍了如何模拟实现多个接口的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何模拟以下类:
UserRepository : GenericRepository<User>, IUserRepository
public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class
我使用的是Moq,我很困惑如何正确处理多个接口.
I am using Moq, and I am confused how to handle multiple interfaces correctly.
推荐答案
看看 https: //github.com/Moq/moq4/wiki/快速入门
高级功能
// implementing multiple interfaces in mock
var foo = new Mock<IFoo>();
var disposableFoo = foo.As<IDisposable>();
// now IFoo mock also implements IDisposable :)
disposableFoo.Setup(df => df.Dispose());
这篇关于如何模拟实现多个接口的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文