|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Linq; |
3 | 4 | using Xunit;
|
4 | 5 | using Xunit.Sdk;
|
5 | 6 |
|
@@ -730,6 +731,165 @@ public void Failure_EmbeddedArray_ExtraValueInActual()
|
730 | 731 | }
|
731 | 732 | }
|
732 | 733 |
|
| 734 | + public class ListOfObjects_NotStrict |
| 735 | + { |
| 736 | + [Fact] |
| 737 | + public void Success() |
| 738 | + { |
| 739 | + var expected = new[] { new { Foo = "Bar" } }.ToList(); |
| 740 | + var actual = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList(); |
| 741 | + |
| 742 | + Assert.Equivalent(expected, actual, strict: false); |
| 743 | + } |
| 744 | + |
| 745 | + [Fact] |
| 746 | + public void Success_EmbeddedArray() |
| 747 | + { |
| 748 | + var expected = new { x = new[] { new { Foo = "Bar" } }.ToList() }; |
| 749 | + var actual = new { x = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList() }; |
| 750 | + |
| 751 | + Assert.Equivalent(expected, actual, strict: false); |
| 752 | + } |
| 753 | + |
| 754 | + [Fact] |
| 755 | + public void Failure() |
| 756 | + { |
| 757 | + var expected = new[] { new { Foo = "Biff" } }.ToList(); |
| 758 | + var actual = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList(); |
| 759 | + |
| 760 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual, strict: false)); |
| 761 | + |
| 762 | + Assert.IsType<EquivalentException>(ex); |
| 763 | + Assert.Equal( |
| 764 | + "Assert.Equivalent() Failure: Collection value not found" + Environment.NewLine + |
| 765 | + "Expected: { Foo = Biff }" + Environment.NewLine + |
| 766 | + "In: [{ Foo = Baz }, { Foo = Bar }]", |
| 767 | + ex.Message |
| 768 | + ); |
| 769 | + } |
| 770 | + |
| 771 | + [Fact] |
| 772 | + public void Failure_EmbeddedArray() |
| 773 | + { |
| 774 | + var expected = new { x = new[] { new { Foo = "Biff" } }.ToList() }; |
| 775 | + var actual = new { x = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList() }; |
| 776 | + |
| 777 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual, strict: false)); |
| 778 | + |
| 779 | + Assert.IsType<EquivalentException>(ex); |
| 780 | + Assert.Equal( |
| 781 | + "Assert.Equivalent() Failure: Collection value not found in member 'x'" + Environment.NewLine + |
| 782 | + "Expected: { Foo = Biff }" + Environment.NewLine + |
| 783 | + "In: [{ Foo = Baz }, { Foo = Bar }]", |
| 784 | + ex.Message |
| 785 | + ); |
| 786 | + } |
| 787 | + } |
| 788 | + |
| 789 | + public class ListOfObjects_Strict |
| 790 | + { |
| 791 | + [Fact] |
| 792 | + public void Success() |
| 793 | + { |
| 794 | + var expected = new[] { new { Foo = "Bar" }, new { Foo = "Baz" } }.ToList(); |
| 795 | + var actual = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList(); |
| 796 | + |
| 797 | + Assert.Equivalent(expected, actual, strict: true); |
| 798 | + } |
| 799 | + |
| 800 | + [Fact] |
| 801 | + public void Success_EmbeddedList() |
| 802 | + { |
| 803 | + var expected = new { x = new[] { new { Foo = "Bar" }, new { Foo = "Baz" } }.ToList() }; |
| 804 | + var actual = new { x = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList() }; |
| 805 | + |
| 806 | + Assert.Equivalent(expected, actual, strict: true); |
| 807 | + } |
| 808 | + |
| 809 | + [Fact] |
| 810 | + public void Failure_ValueNotFoundInActual() |
| 811 | + { |
| 812 | + var expected = new[] { new { Foo = "Biff" } }.ToList(); |
| 813 | + var actual = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList(); |
| 814 | + |
| 815 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual, strict: true)); |
| 816 | + |
| 817 | + Assert.IsType<EquivalentException>(ex); |
| 818 | + Assert.Equal( |
| 819 | + "Assert.Equivalent() Failure: Collection value not found" + Environment.NewLine + |
| 820 | + "Expected: { Foo = Biff }" + Environment.NewLine + |
| 821 | + "In: [{ Foo = Baz }, { Foo = Bar }]", |
| 822 | + ex.Message |
| 823 | + ); |
| 824 | + } |
| 825 | + |
| 826 | + [Fact] |
| 827 | + public void Failure_ExtraValueInActual() |
| 828 | + { |
| 829 | + var expected = new[] { new { Foo = "Bar" } }.ToList(); |
| 830 | + var actual = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList(); |
| 831 | + |
| 832 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual, strict: true)); |
| 833 | + |
| 834 | + Assert.IsType<EquivalentException>(ex); |
| 835 | + Assert.Equal( |
| 836 | + "Assert.Equivalent() Failure: Extra values found" + Environment.NewLine + |
| 837 | + "Expected: [{ Foo = Bar }]" + Environment.NewLine + |
| 838 | + "Actual: [{ Foo = Baz }] left over from [{ Foo = Baz }, { Foo = Bar }]", |
| 839 | + ex.Message |
| 840 | + ); |
| 841 | + } |
| 842 | + |
| 843 | + [Fact] |
| 844 | + public void Failure_EmbeddedArray_ValueNotFoundInActual() |
| 845 | + { |
| 846 | + var expected = new { x = new[] { new { Foo = "Biff" } }.ToList() }; |
| 847 | + var actual = new { x = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList() }; |
| 848 | + |
| 849 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual, strict: true)); |
| 850 | + |
| 851 | + Assert.IsType<EquivalentException>(ex); |
| 852 | + Assert.Equal( |
| 853 | + "Assert.Equivalent() Failure: Collection value not found in member 'x'" + Environment.NewLine + |
| 854 | + "Expected: { Foo = Biff }" + Environment.NewLine + |
| 855 | + "In: [{ Foo = Baz }, { Foo = Bar }]", |
| 856 | + ex.Message |
| 857 | + ); |
| 858 | + } |
| 859 | + |
| 860 | + [Fact] |
| 861 | + public void Failure_EmbeddedArray_ExtraValueInActual() |
| 862 | + { |
| 863 | + var expected = new { x = new[] { new { Foo = "Bar" } }.ToList() }; |
| 864 | + var actual = new { x = new[] { new { Foo = "Baz" }, new { Foo = "Bar" } }.ToList() }; |
| 865 | + |
| 866 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual, strict: true)); |
| 867 | + |
| 868 | + Assert.IsType<EquivalentException>(ex); |
| 869 | + Assert.Equal( |
| 870 | + "Assert.Equivalent() Failure: Extra values found in member 'x'" + Environment.NewLine + |
| 871 | + "Expected: [{ Foo = Bar }]" + Environment.NewLine + |
| 872 | + "Actual: [{ Foo = Baz }] left over from [{ Foo = Baz }, { Foo = Bar }]", |
| 873 | + ex.Message |
| 874 | + ); |
| 875 | + } |
| 876 | + } |
| 877 | + |
| 878 | + public class ArraysAndListsAreEquivalent |
| 879 | + { |
| 880 | + [Fact] |
| 881 | + public void ArrayIsEquivalentToList() |
| 882 | + { |
| 883 | + Assert.Equivalent(new[] { 1, 2, 3 }, new List<int> { 1, 2, 3 }); |
| 884 | + } |
| 885 | + |
| 886 | + [Fact] |
| 887 | + public void ListIsEquivalentToArray() |
| 888 | + { |
| 889 | + Assert.Equivalent(new List<int> { 1, 2, 3 }, new[] { 1, 2, 3 }); |
| 890 | + } |
| 891 | + } |
| 892 | + |
733 | 893 | public class Dictionaries_NotStrict
|
734 | 894 | {
|
735 | 895 | [Fact]
|
@@ -940,8 +1100,3 @@ public SelfReferential(bool circularReference)
|
940 | 1100 | public SelfReferential Other { get; }
|
941 | 1101 | }
|
942 | 1102 | }
|
943 |
| - |
944 |
| - |
945 |
| - |
946 |
| - |
947 |
| - |
|
0 commit comments