Rac*_*ael 5 c# fluent-assertions
我有 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));
}
Run Code Online (Sandbox Code Playgroud)
如果这是预期的行为,我如何设置流畅的断言规则来检查类型是否匹配?
我已经使用 MatchingRule 和 AssertionRule 进行了调查,但在这两种情况下,我似乎都无法访问主题和预期的原始类型。看来主题已经转换为预期的类型。即在上面的示例中,第一个字典中的 updateInterval 已经被转换为字符串以与第二个字典进行比较。
谢谢你的帮助,
瑞秋
[这个问题已经有将近一年了,但我在寻找同一问题的答案时发现的]
请允许我稍微改变一下问题:
如何使用 FluentAssertions 检查类型?
FluentAssertions“ShouldBeEquivelentOf”是一种引用检查,用于查看对象是否“相同”(byRef)
正确的 FluentAssertions 调用只是“Should().Be(...) asobjectList.GetType().Should().Be(typeof(List<Classes.SomeListObject>));