public void ListOfUsersShouldBeComparedUsingKeys() { // Arrange List <User> l1 = UserCollection1.ToList(); List <User> l2 = UserCollection2.ToList(); // Act List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(l1, l2).ToList(); // Assert Assert.Empty(variances); }
public void ListOfUsersWithDifferentKeysShouldYieldVariance() { // Arrange List <User> l1 = UserCollection1.ToList(); List <User> l2 = UserCollection3.ToList(); // Act List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(l1, l2).ToList(); // Assert Assert.NotEmpty(variances); Assert.Equal(3, variances.Count); Assert.Equal("Extra object in IEnumerable 1 with key {Id=3}", variances[0].PropertyName); Assert.Equal(l1[2], variances[0].PropertyValue1); Assert.Null(variances[0].PropertyValue2); Assert.NotNull(variances[0].ParentVariance); Assert.Equal(l1, variances[0].ParentVariance.PropertyValue1); Assert.Equal(l2, variances[0].ParentVariance.PropertyValue2); Assert.Null(variances[0].ParentVariance.PropertyName); Assert.Null(variances[0].ParentVariance.ParentVariance); Assert.Equal("Extra object in IEnumerable 2 with key {Id=4}", variances[1].PropertyName); Assert.Null(variances[1].PropertyValue1); Assert.Equal(l2[2], variances[1].PropertyValue2); Assert.NotNull(variances[1].ParentVariance); Assert.Equal(l1, variances[1].ParentVariance.PropertyValue1); Assert.Equal(l2, variances[1].ParentVariance.PropertyValue2); Assert.Null(variances[1].ParentVariance.PropertyName); Assert.Null(variances[1].ParentVariance.ParentVariance); Assert.Equal("Bar", variances[2].PropertyValue1); Assert.Equal("Test", variances[2].PropertyValue2); Assert.Equal("Name", variances[2].PropertyName); Assert.NotNull(variances[2].ParentVariance); Assert.Equal(l1[1], variances[2].ParentVariance.PropertyValue1); Assert.Equal(l2[1], variances[2].ParentVariance.PropertyValue2); Assert.Equal("{Id=2}", variances[2].ParentVariance.PropertyName); Assert.NotNull(variances[2].ParentVariance.ParentVariance); Assert.Equal(l1, variances[2].ParentVariance.ParentVariance.PropertyValue1); Assert.Equal(l2, variances[2].ParentVariance.ParentVariance.PropertyValue2); Assert.Null(variances[2].ParentVariance.ParentVariance.PropertyName); }
public void DifferentLengthsOfUserListsReversedShouldAlsoReturnVariances() { // Arrange List <User> l1 = UserCollection4.ToList(); List <User> l2 = UserCollection1.ToList(); // Act List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(l1, l2).ToList(); // Assert Assert.NotEmpty(variances); Assert.Equal(1, variances.Count); Assert.Equal("Extra object in IEnumerable 1 with key {Id=4}", variances[0].PropertyName); Assert.Equal(l1[3], variances[0].PropertyValue1); Assert.Null(variances[0].PropertyValue2); Assert.NotNull(variances[0].ParentVariance); Assert.Equal(l1, variances[0].ParentVariance.PropertyValue1); Assert.Equal(l2, variances[0].ParentVariance.PropertyValue2); Assert.Null(variances[0].ParentVariance.PropertyName); Assert.Null(variances[0].ParentVariance.ParentVariance); }