我想告诉Machine.Fakes框架在创建主题时使用特定值作为构造函数参数
测试对象具有以下构造函数
/// <summary>
/// Initializes a new instance of the <see cref="CsvFileRepository{TModel}"/> class.
/// </summary>
/// <param name="fileService">The file service.</param>
/// <param name="repositorySettings">The repository settings.</param>
/// <param name="mappingFunction">The mapping function. The mapping function takes in a line from the CSV file and returns the model for said line.</param>
public CsvFileRepository(IFileService fileService, IRepositorySettings repositorySettings, Func<string, TModel> mappingFunction)
{
this.FileService = fileService;
this.RepositorySettings = repositorySettings;
this.MappingFunction = mappingFunction;
}
Run Code Online (Sandbox Code Playgroud)
我已经创建了一个测试存根,如下所示:
public class when_i_pass_a_csv_file_the_results_are_mapped_to_model_objects : WithSubject<CsvFileRepository<StandardOffer>>
{
Establish context = () => …
Run Code Online (Sandbox Code Playgroud) 我用Machine.Fakes打了一个僵局.我无法弄清楚如何仅out
使用Machine.Fakes设备模拟参数.由于RhinoMocks 中存在错误,我将mfakes适配器切换为FakeItEasy.据我所知,任何适配器都应该是可互换的.
问题是这导致"out"测试失败,看起来像这样的东西不再编译,因为Arg
是Rhino.Mocks.
The<IMembershipService>()
.WhenToldTo(x => x.CreateUser(Param<string>.IsAnything,
Param<bool>.IsAnything,
Param<object>.IsAnything,
out Arg<MembershipCreateStatus>
.Out(MembershipCreateStatus.UserRejected)
.Dummy))
.Return(user);
Run Code Online (Sandbox Code Playgroud)
我尝试使用"虚拟"局部变量,设置为原始Arg<T>
参数设置的相同值,但这导致我的测试失败 - 好像值没有被传递! Arg<T>
真的有解决方案,但我不能再使用它了,因为它是Rhino.Mocks的一部分.
假设我的上下文配置类似于:
Establish context = () =>
{
...
IFileProcesser processer = new FileProcesser();
The<IFileProcesser>()
.WhenToldTo(x => x.Read(Param<Stream>.IsAnything))
.Return<Stream>(processer.Read);
...
};
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法告诉Machine.Fakes不要伪造IFileProcesser并使用FileProcesser的实现?