public void EqualsIsSummetricWithSemanticallyUnequalObjects() { // Fixture setup var source = new ConcreteType("Lorem", "ipsum", "dolor", "sit"); var dest = new DoublePropertyHolder <object, object>(); dest.Property1 = source.Property1; dest.Property2 = "abc"; var sut = new SemanticComparer <ConcreteType, DoublePropertyHolder <object, object> >(); // Exercise system and verify outcome Assert.False(sut.Equals(source, dest) && sut.Equals(dest, source)); // Teardown }
private static void CompareSemantically <TSource, TDestination>(TSource likenObject, TDestination comparee, bool expectedResult) { // Fixture setup var sut = new SemanticComparer <TSource, TDestination>(); // Exercise system bool result = sut.Equals(likenObject, comparee); // Verify outcome Assert.Equal(expectedResult, result); // Teardown }
public void SutDoesNotEqualAnonymousObject() { // Fixture setup var sut = new SemanticComparer <ConcreteType, ConcreteType>(); object anonymousObject = new object(); // Exercise system var result = sut.Equals(new ConcreteType(), anonymousObject); // Verify outcome Assert.False(result); // Teardown }
public void SutEqualsIdenticalStrongType() { // Fixture setup var ticks = 8293247; var value = TimeSpan.FromTicks(ticks); var sut = new SemanticComparer <TimeSpan, TimeSpan>(); var other = TimeSpan.FromTicks(ticks); // Exercise system var result = sut.Equals(value, other); // Verify outcome Assert.True(result); // Teardown }
public void SutWithSemanticEqualityWillReturnTrue() { // Fixture setup var value = new ConcreteType("Lorem", "ipsum", "dolor", "sit"); var sut = new SemanticComparer <ConcreteType, DoublePropertyHolder <object, object> >(); var other = new DoublePropertyHolder <object, object>(); other.Property1 = value.Property1; other.Property2 = value.Property2; // Exercise system var result = sut.Equals(value, other); // Verify outcome Assert.True(result); // Teardown }
public void EqualsWhenOverriddenSourcePropertyEqualsReturnsFalseWillReturnFalse() { // Fixture setup var equalityResponse = false; var value = new PropertyHolder <EqualityResponder>(); value.Property = new EqualityResponder(equalityResponse); var sut = new SemanticComparer <PropertyHolder <EqualityResponder>, PropertyHolder <object> >(); var other = new PropertyHolder <object>(); other.Property = new object(); // Exercise system var result = sut.Equals(value, other); // Verify outcome Assert.Equal(equalityResponse, result); // Teardown }
public void SutOfAbstractTypeDoesNotEqualConcreteInstanceWhenPropertyDiffers() { // Fixture setup var value = new ConcreteType("Lorem", "ipsum", "dolor", "sit"); value.Property4 = "Ploeh"; var sut = new SemanticComparer <ConcreteType, AbstractType>(); var other = new ConcreteType(); other.Property1 = value.Property1; other.Property2 = value.Property2; other.Property3 = value.Property3; other.Property4 = "Fnaah"; // Exercise system var result = sut.Equals(value, other); // Verify outcome Assert.False(result); // Teardown }
public void SutOfAbstractTypeEqualsConcreteInstancesThatDifferOnlyOnMemberNotDefinedByAbstraction() { // Fixture setup var value = new ConcreteType("Lorem", "ipsum", "dolor", "sit"); value.Property5 = "Ploeh"; var sut = new SemanticComparer <ConcreteType, AbstractType>(); var other = new ConcreteType(); other.Property1 = value.Property1; other.Property2 = value.Property2; other.Property3 = value.Property3; other.Property4 = value.Property4; other.Property5 = "Fnaah"; // Exercise system var result = sut.Equals(value, other); // Verify outcome Assert.True(result); // Teardown }
private static IEnumerable <bool> BothEquals <T>(SemanticComparer <T> sut, T x, T y) { yield return(sut.Equals(x, y)); yield return(((IEqualityComparer)sut).Equals(x, y)); }