How to Compare two objects in unit test?

前端 未结 15 1677
自闭症患者
自闭症患者 2020-11-30 03:15
public class Student
{
    public string Name { get; set; }
    public int ID { get; set; }
}

...

var st1 = new Student
{
    ID =          


        
15条回答
  •  粉色の甜心
    2020-11-30 03:21

    1. Hello firstly add your test project Newtonsoft.Json with Nuget PM

      PM> Install-Package Newtonsoft.Json -Version 10.0.3

    2. Then add test file

      using Newtonsoft.Json;
      
    3. Usage:

      Assert.AreEqual(
          JsonConvert.SerializeObject(expected),
          JsonConvert.SerializeObject(actual));
      

提交回复
热议问题