C#:带有服务层、接口和模拟的文件夹结构?
我最近开始创建服务层并做出如下声明:
MyService myService = new MyService();
myService.DoSomething();
这受到一些 ASP.NET MVC 视频的启发,我喜欢这种模式。
然后我开始创建接口和模拟,例如:
IMyService myService = new MockMyService();
myService.DoSomething();
这样我就可以隔离部分代码进行测试。但现在我的服务层文件夹加载了类、接口和模拟类:
IServiceTypeA.cs
ServiceTypeA.cs
MockServiceTypeA.cs
IServiceTypeB.cs
ServiceTypeB.cs
MockServiceTypeB.cs
...
IServiceTypeZ.cs
ServiceTypeZ.cs
MockServiceTypeZ.cs
如何以逻辑方式组织这些?
I recently started creating services layers and making declarations like:
MyService myService = new MyService();
myService.DoSomething();
This was inspired by some ASP.NET MVC videos and I like the pattern.
Then I started creating interfaces and mocks like:
IMyService myService = new MockMyService();
myService.DoSomething();
So I can isolate parts of the code to test. But now my service layer folder is loaded with classes, interfaces, and mock classes:
IServiceTypeA.cs
ServiceTypeA.cs
MockServiceTypeA.cs
IServiceTypeB.cs
ServiceTypeB.cs
MockServiceTypeB.cs
...
IServiceTypeZ.cs
ServiceTypeZ.cs
MockServiceTypeZ.cs
How do you organize these in a logical way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者您可以使用模拟框架在运行时生成模拟服务。
Or you could use Mocking frameworks to have the Mock Services generated at runtime.