Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 使用Rhino Mock保存到存储库_Unit Testing_Testing_Mocking_Rhino Mocks - Fatal编程技术网

Unit testing 使用Rhino Mock保存到存储库

Unit testing 使用Rhino Mock保存到存储库,unit-testing,testing,mocking,rhino-mocks,Unit Testing,Testing,Mocking,Rhino Mocks,到目前为止,我一直在编写代码,使用Rhino Mocks在我的业务/服务层中使用Get方法来获取预期的列表或类型,并让Rhino Mocks为我返回它,我的问题是如何测试set/save调用,例如void SaveCustomers(Customer) 我有一个名为GetCustomers的调用,我可以在调用SaveCustomers后立即使用Rhino mocks调用它,查看它是否将其保存到内存中?我试过模仿我的回购协议并调用它,但它返回空值,正确的语法是什么?我找不到使用StrictMock

到目前为止,我一直在编写代码,使用Rhino Mocks在我的业务/服务层中使用Get方法来获取预期的列表或类型,并让Rhino Mocks为我返回它,我的问题是如何测试set/save调用,例如
void SaveCustomers(Customer)

我有一个名为
GetCustomers
的调用,我可以在调用
SaveCustomers
后立即使用Rhino mocks调用它,查看它是否将其保存到内存中?我试过模仿我的回购协议并调用它,但它返回空值,正确的语法是什么?我找不到使用StrictMock或GenerateSub的示例


谢谢

如果您正在谈论使用Rhino mock来模拟存储库,您不需要让它调用GetCustomers,您可以直接使用如下语法检查它(使用“AAA”样式):

IMyRepository repository=MockRepository.GenerateMock();
//使用存储库做一些事情
AssertWasCalled(x=>x.SaveCustomers(myTestCustomer));
IMyRepository repository = MockRepository.GenerateMock<IMyRepository>();
// do stuff with repository
repository.AssertWasCalled(x => x.SaveCustomers(myTestCustomer));