0

I have a controller method that accepts a couple of input parameters (string, int, etc.). Because I don't want to declare each parameter in this method I created a class with properties that map to this parameters and now the only parameter to this method is an instance of this class. When the method is called, the object's properties are populated with the values of arguments according to their names.

Now I want to unit test this method; so I want to send a mock of this class to the method. At first I created a mock of the class and send it to the method; it worked fine except that I had to mark all properties that I want to set inside mock with the virtual keyword so mock framework can access it.
Because of that I thought that I could create an interface that this class implements, but it is not possible to send the interface as an argument to the controller method.

Is it somehow possible to manually bind input parameters to the properties of the object? For example, to inject interface via controller's constructor and then trigger some manual bind of the input values to the properties?

I am using ASP.NET MVC 3.

4

1 回答 1

0

如果我理解它,您正在尝试测试控制器并需要使用模型类的模拟。

我的第一个想法是,为什么不能只使用模型类的实际实例?

大概您的模型类具有要隔离的依赖项或副作用...

在这种情况下,也许模型类做得太多了?

于 2012-06-16T19:53:01.457 回答