简体   繁体   English

如何测试使用IEnumerable的方法

[英]How to test a method that uses IEnumerable

I'm trying to test a method that takes in an object that has an IEnumerable<string> property but don't know how to make that work in a test. 我正在尝试测试一种方法,该方法采用具有IEnumerable<string>属性的对象,但不知道如何在测试中使该方法起作用。

I've tried Mocking the property which failed because the object isn't mocked. 我尝试过模拟失败的属性,因为没有嘲笑对象。

The method I want to test looks like: 我要测试的方法如下所示:

myMethod(MyObject object)

The object has the property: 该对象具有以下属性:

public IEnumerable<string> EnumProperty { get; set; }

I'm sure(and hoping) I'm just missing something really obvious. 我确定(并希望)我只是缺少一些明显的东西。

I was definitely overthinking it. 我绝对想得太多。 As Panagiotis Kanavos quite rightly pointed out, all i needed was to make it as a new string[] . 正如Panagiotis Kanavos正确指出的那样,我需要做的只是将其作为new string[] Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM