Skip to content

Instantly share code, notes, and snippets.

@krist00fer
Created May 7, 2020 08:36
Show Gist options
  • Save krist00fer/b82859f2695afa0e0d5498a048c35b12 to your computer and use it in GitHub Desktop.
Save krist00fer/b82859f2695afa0e0d5498a048c35b12 to your computer and use it in GitHub Desktop.
Equivalent comparison using FluentAssertions
using FluentAssertions;
using System;
using System.Collections.Generic;
namespace CompareTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test");
var order1 = new Order { ID = 1, Customer = "Customer 1" };
order1.Rows.Add(new OrderRow{ RowNo = 1, Article = "Article 1", Qty = 42 });
order1.Rows.Add(new OrderRow{ RowNo = 2, Article = "Article 2", Qty = 43 });
var order2 = new Order { ID = 2, Customer = "Customer 2" };
order2.Rows.Add(new OrderRow { RowNo = 1, Article = "Article 1", Qty = 42 });
order2.Rows.Add(new OrderRow { RowNo = 2, Article = "Article 5", Qty = 3 });
var order3 = new Order { ID = 1, Customer = "Customer 1" };
order3.Rows.Add(new OrderRow { RowNo = 1, Article = "Article 1", Qty = 42 });
order3.Rows.Add(new OrderRow { RowNo = 2, Article = "Article 2", Qty = 43 });
order1.Should().BeEquivalentTo(order3); // This line works since the orders are equivalent
order1.Should().BeEquivalentTo(order2); // This line fails since they are not equivalent
}
}
public class Order
{
public int ID { get; set; }
public string Customer { get; set; }
public List<OrderRow> Rows { get; } = new List<OrderRow>();
}
public class OrderRow
{
public int RowNo { get; set; }
public string Article { get; set; }
public int Qty { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment