在ASP.NET 1.0的核心单元测试路由(如MVC 6) [英] Unit testing routing in ASP.NET Core 1.0 (ex MVC 6)

查看:170
本文介绍了在ASP.NET 1.0的核心单元测试路由(如MVC 6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于ASP.NET Core架构1.0(前MVC 6 / ASP.NET 5.0)显著改变,又怎么会一步到位单元测试路由?

作为一个例子,我喜欢的库如这一个(为< = MVC 5):的https: //github.com/AnthonySteele/MvcRouteTester

下来的东西流利的扩展方法行:

  routes.ShouldMap(/)到<&HomeController的GT;(X => x.Index());


解决方案

好吧...我没有ping到ASP.NET团队,问他们如何着手做自己的测试。

简短的回答

您不能没有嘲笑世界的单元测试。你所要做的集成/功能测试。

稍长的答案

路由可以来自许多地方(属性,$ P $对 - 定义路线,区域等),并且甚至可以由中间件所改变。包括测试中的所有这些情景都需要设置一些大规模的依赖关系树虽然是测试它的一个更简单的方法。

他们是如何做到这一点。

基本上,他们正在创建一个 TestStartup.cs ,自托管在测试过程中应用程序和击球本身,看它如何表现。他们重写结果......这是pretty多少呢。

我想我已经给你们这里所有可能的工具来引导实际的东西给自己。

As the architecture of ASP.NET Core 1.0 (ex MVC 6 / ASP.NET 5.0) changed significantly, how would one go about unit testing the routing?

As an example, I like the libraries such as this one (as for <= MVC 5): https://github.com/AnthonySteele/MvcRouteTester

Something down the lines of fluent extension methods:

routes.ShouldMap("/").To<HomeController>(x => x.Index());

解决方案

Alright... I did ping the ASP.NET team and asked them how they proceeded to do their tests.

Short answer

You can't unit test without mocking the world. You have to do integration/functional tests.

Slightly longer answer

Routing can come from many places (attributes, pre-defined routes, areas, etc) and can even be altered by middleware. Including all those scenarios in a test would need to setup some massive dependency tree while there is an easier way to test it.

How they do it.

Basically, they are creating a TestStartup.cs, self-hosting the app in the test process and hitting itself to see how it behaves. They override the results and... that's pretty much it.

I think I've given you all the possible tools here to actually bootstrap something for yourself.

这篇关于在ASP.NET 1.0的核心单元测试路由(如MVC 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆