ASP.NET 中的跨进程模拟
我正在使用 ASP.NET MVC 3 构建 REST API。我正在使用 SpecFlow 进行 BDD 风格的构建使用 NUnit 作为测试运行程序。
由于它是 REST API,因此测试 Url:s 显然非常重要,因此我希望能够在规范中进行真正的 HTTP 调用。
我现在正在寻找有关如何进行跨进程模拟的提示。简而言之,我想用我在规范中生成的实体来模拟数据层。
在 Rails 应用程序中,我将使用 Webrat 来实现此目的。 .NET 中还有与此相当的东西吗?
我已经尝试过 Deleporter 但它似乎无法“发送”高级构造(在规范中创建一个简单的字符串并在 Deleporter 中使用它可以工作,但对于自定义类,属性全部变为空)
有没有人有经验或有关如何执行此操作的提示?
编辑: 我在 Deleporter 中尝试做的事情是这样的(我知道我可以在 Deleporter 代码中生成模型,但这是一个简化的示例,所以这对我来说不起作用):
var models = Builder<Foo>.CreateListOfSize(300);
Deleporter.Run(() =>
{
var mockService = new Mock<IFooService>();
// Models will be a list of 300 Foos but the foos properties will all be null
mockService.Setup(s => s.GetStuff()).Returns(models);
ObjectFactory.Inject(mockService.Object);
});
I'm building a REST API using ASP.NET MVC 3. I'm doing it BDD-style using SpecFlow with NUnit as test runner.
Since it's a REST API, testing the Url:s are obviously very important so I want to be able to make real HTTP calls in the specs.
I'm now looking for tips on how to get Cross Process Mocking going. In short I want to mock the data layer with entities that I generate in the Specs.
In a Rails application I would use Webrat for this. Is there anything equivalent to that in .NET yet?
I've already tried Deleporter but it doesn't seem to be able to "send" advanced constructs (Creating a simple string in the specs and using it in Deleporter works, but doesn't for a custom class the properties all becomes null)
Does anyone have experiences or tips on how to do this?
Edit:
What I was trying do to in Deleporter was something like this (I am aware that i could generate the models inside the Deleporter code but this is a simplified example, so that wouldn't work for me):
var models = Builder<Foo>.CreateListOfSize(300);
Deleporter.Run(() =>
{
var mockService = new Mock<IFooService>();
// Models will be a list of 300 Foos but the foos properties will all be null
mockService.Setup(s => s.GetStuff()).Returns(models);
ObjectFactory.Inject(mockService.Object);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是自己调查这个问题。查看 GuestBookDemo 中的一些示例代码 似乎可以使用 Deleporter 来实现此目的。
您有一个具体的例子来说明您希望能够做什么吗?
I'm just investigating this myself. Looking at some of the example code in the GuestBookDemo it seems possible to use Deleporter for this.
Do you have an example of exactly what you'd like to be able to do?
我想您可能正在寻找 WatiN
I think you're probably looking for WatiN