我正在尝试将自定义类类型的字典检查为值。
我想知道在 Fluent Assertion 中使用 ContainValue 在 Dictionary 中搜索值的方法是否正确。
这是代码
public static void VerifyDictionary()
{
try
{
Dictionary<int, Employee> empDict = new Dictionary<int, Employee>
{
{ 1, new Employee() {EmployeeID = 100,Name="Karthik", EmployeeEmail="karthik@executeautomation.com", EmployeeAddress="Chennai,India"}},
{2, new Employee() { EmployeeID = 101,Name="Jack",EmployeeEmail="Jack@jill.com",EmployeeAddress="CA"} },
{3, new Employee() { EmployeeID=102,Name="Sam",EmployeeEmail="Sam@sung.com",EmployeeAddress="SFO"}},
{4, new Employee() { EmployeeID=103,Name="Max",EmployeeEmail="micro@max.com",EmployeeAddress="India" }}
};
empDict.Should().ContainValue(new Employee() { EmployeeID = 10, EmployeeEmail = "micro@max.com", EmployeeAddress = "India", Name = "Max" }, "because thats the information I need");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
员工类
public class Employee
{
public int EmployeeID { get; set; }
public string Name { get; set; }
public string EmployeeEmail { get; set; }
public string EmployeeAddress { get; set; }
}
当我执行这段代码时,我得到了如图所示的异常
**
Expected dictionary {[1, BDDDemo.Employee], [2, BDDDemo.Employee], [3, BDDDemo.Employee], [4, BDDDemo.Employee]} to contain value
BDDDemo.Employee
{
EmployeeAddress = "India"
EmployeeEmail = "micro@max.com"
EmployeeID = 10
Name = "Max"
} because thats the information I need.
**
请帮助我了解我在这里做错了什么。
谢谢,