我有 2 个字典,我希望内容不相等,因为字典包含不同类型的值。但是以下测试通过
[Scenario]
public void DictionariesWithDifferentTypesShouldBeEquivalent(
Dictionary<string, object> firstDictionary,
Dictionary<string, object> secondDictionary)
{
"Given a dictionary"
.f(() => firstDictionary = new Dictionary<string, object>
{
{ "latency", 0 },
{ "errorMessages", new string[0] },
{ "lastChanged", new DateTime(635272310930829706) },
{ "query", new string[0] },
{ "items", new string[] { "foo", "bar" } },
{ "name", "Bob" },
{ "number", 3 },
{ "updateInterval", 10 },
});
"And a second dictionary with same values but of differing types"
.f(() => secondDictionary = new Dictionary<string, object>
{
{ "latency", 0L },
{ "errorMessages", new object[0] },
{ "lastChanged", new DateTime(635272310930829706) },
{ "query", new string[0] },
{ "items", new string[] { "bar", "foo" } },
{ "name", "Bob" },
{ "number", 3 },
{ "updateInterval", "10" },
});
"When I check for equivalency"
.f(() => { });
"Then the dictionaries should be equivalent"
.f(() => firstDictionary.ShouldBeEquivalentTo(secondDictionary));
}
如果这是预期的行为,我该如何设置一个流畅的断言规则来检查类型是否匹配?
我已经使用 MatchingRule 和 AssertionRule 进行了调查,但在这两种情况下,我似乎都无法访问主题的原始类型和预期。似乎主题已经转换为预期的类型。即,在上面的示例中,第一个字典中的 updateInterval 已经被转换为字符串,以便与第二个字典进行比较。
谢谢你的帮助,
瑞秋