The “Thunderdome Principle” – All
Controller methods take in one
viewmodel object (or zero objects in
some cases) and return a single
viewmodel object (one object enters,
one object leaves). The Controller
classes will NEVER be directly exposed
to anything related to HttpContext.
Nothing makes me cry like seeing
people trying to write tests that mock
or stub that new IHttpContextWrapper
interface. Likewise,Controller
methods do not return ViewResult
objects and are generally decoupled
from all MVC infrastructure. We
adopted this strategy very early on as
a way to make Controller testing
simpler mechanically. It’s definitely
achieved that goal,but it’s also made
the Controller code very streamlined
and easy to read. We’ll explain how
this works at KaizenConf.
解决方法
由于我们所有的控制器操作都遵循相同的模式,因此我们可以假设很多事情并加速并简化我们的控制器集成测试工作.
有一个控制器动作有多个参数,没有什么不对,但我们发现有一个实际的模型对象为我们提供了一些额外的功能,因为模型可以包含简单的逻辑并暴露方便的属性,这可能只是一些更复杂的方面.它自己的状态等 – 基本上,这是拥有任何丰富模型的论据,并不是Thunderdome / OMIOMO模式所独有的.