
IDepartment = Interface ['{F4915950-8F32-4944-A3B6-8E08F6C38ECC}'] function getID() : Integer; function getname() : String; property ID: Integer read getID; property name: String read getname; end;ISale = Interface ['{F4915950-8F32-4944-A3B6-8E08F6C38E77}'] function getAmmount() : Currency; function getDepartment() : IDepartment; property Ammount: Currency read getAmmount; property Department : IDepartment getDepartment;end; 现在,我尝试使用DUnit和Delphi-Mocks测试Sale接口,并按如下方式使用它:
procedure TMyTest.Test_Sale_HasDepartment;var mckDepartment : TMock<IDeparment>; mckSale : TMock<ISale>;begin mckDepartment := TMock<IDepartment>.Create; mckDepartment.Setup.WillReturn('My Department').When.name; mckDepartment.Setup.WillReturn(1).When.ID; // Create a sale Mock mckSale := TMock<ISale>.Create; mckSale.Setup.WillReturn(100).When.Ammount; //** Here´s there is where I don´t kNow how to add a "child mock"** mckSale.Setup.WillReturn(TValue.From<IDepartment>(mckDepartment)).When.Department; // What I am trying to get is the following: WriteLn(mckSale.Instance.Department.name); // Should return "My Department" but fails with an AV. end; 所以我的问题是:如何将一个子模拟添加到现有的模拟接口并调用其方法和属性?
谢谢!
附:我正在使用Delphi XE2.
以上是内存溢出为你收集整理的如何使用Delphi-Mocks框架在Delphi中使用子类中的模拟全部内容,希望文章能够帮你解决如何使用Delphi-Mocks框架在Delphi中使用子类中的模拟所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)