如何利用Delphi-Mocks框架在子类中实现模拟,改写为长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计323个文字,预计阅读时间需要2分钟。
好的,以下是修改后的内容,不超过100字:
使用Delphi-Mocks Framework时,遇到问题。接口定义如下:`IDepartment=Interface [‘{F4915950-8F32-4944-A3B6-8E08F6C38ECC}’] function getID(): Integer; function getName(): String; property ...`
好的,我一直在使用优秀的 Delphi-Mocks Framework,我刚遇到一个问题.假设我有以下接口: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.
本文共计323个文字,预计阅读时间需要2分钟。
好的,以下是修改后的内容,不超过100字:
使用Delphi-Mocks Framework时,遇到问题。接口定义如下:`IDepartment=Interface [‘{F4915950-8F32-4944-A3B6-8E08F6C38ECC}’] function getID(): Integer; function getName(): String; property ...`
好的,我一直在使用优秀的 Delphi-Mocks Framework,我刚遇到一个问题.假设我有以下接口: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.

