'Moq: How to Setup ToDictionary
I want to mock a Linq expression that returns a Dictionary<string, string>
Dictionary<string, string> properties = new Dictionary<string, string>()
{
{ "Service", "serviceTest" }
}
equipment.SetProperties(dmsElement.Properties.ToDictionary(x => x.Definition.Name, x => x.Value));
Here is the unit test
fakeEquipment.Setup(e => e.Properties.ToDictionary(It.IsAny<Func<IDmsElementProperty, string>>(), It.IsAny<Func<IDmsElementProperty, string>>())).Returns(properties);
I am getting the following error:
System.NotSupportedException: 'Unsupported expression: ... => ....ToDictionary<IDmsElementProperty, string, string>(It.IsAny<Func<IDmsElementProperty, string>>(), It.IsAny<Func<IDmsElementProperty, string>>())
How can I setup the ToDictionary method to retrieve the expected values?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
