I need to pass a complex object (Dictionary<Decimal, Int32>
, in my case) to a test method. Can it be done?
Yes, I read available answers here, none of them work with dictionaries, not PropertyData, not ClassData, and InlineData only allows compile-time constants
I use xunit.net 1.9.2
Asked
Active
Viewed 702 times
0

chester89
- 8,328
- 17
- 68
- 113
-
Huh ? What have you tried? `[Theory, PropertyData("Provider")` works for me and lots of people including stuff far more exotic than a Dictionary. Are you returning `object[]` from you Property? – Ruben Bartelink Aug 18 '16 at 20:21
-
@RubenBartelink so I need to return object[], not IEnumerable – chester89 Aug 18 '16 at 20:37
-
No, when I say `return`, I meant `yield return` :P Yes, IEnumerable. I (because you didnt give any exception info, stack traces, output window messages) was having a wild stab that the issue could be returning e.g. `IEnumerable
`, `IEnumerable – Ruben Bartelink Aug 18 '16 at 23:28 -
@RubenBartelink you're right. I'll post my code that didn't work – chester89 Aug 19 '16 at 06:54
-
@RubenBartelink I must have been wrong. using `PropertyData` attribute and returning `return new[] { new object[] { new Dictionary
() { ... } } }` for test data worked just fine – chester89 Aug 19 '16 at 11:23 -
Unless there's a cast to `object[]`, the fact that the result is marked as just `Object` can make it very errorprone - but in general ther's always a clear message IME. Good you're sorted. – Ruben Bartelink Aug 19 '16 at 13:13