public void AValueObject_IsNotEqualToAnotherOne_WhenHaveAnyPropertyWithDifferentValue() { //Arrange var objectClass = new SomeClass() { MyProp = "Test" }; var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString", SomeClassProperty = objectClass }; var b = new SomeValueObject() { SomeIntProp = 2, SomeStringProp = "MyString", SomeClassProperty = objectClass }; //Assert Assert.IsTrue(a != b); //Arrange b.SomeIntProp = 1; b.SomeStringProp = "OtherValue"; //Assert Assert.IsTrue(a != b); }
public void GetHashCode_ReturnsDifferentValues_WhenTwoValueObjectAreNotEquals() { //Arrange var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString" }; var b = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString" }; var c = new ValueObjectWithAnotherValueObject() { MyProp = "MyString", SomeValueObjectProperty = a }; var d = new ValueObjectWithAnotherValueObject() { SomeValueObjectProperty = b }; //Assert Assert.AreNotEqual(c.GetHashCode(), d.GetHashCode()); }
public void HasSamePropertyValuesThan_ReturnsTrue_WhenAllPropertiesAreEqual() { //Arrange var a = new SomeEntity() { Id = "dasjkl546jh", SomeIntProp = 1, SomeProp = "Val1" }; var b = new SomeEntity() { Id = "dasjkl546jh", SomeIntProp = 1, SomeProp = "Val1" }; var c = new SomeEntity() { Id = "98778", SomeIntProp = 9, SomeProp = "val" }; var d = new SomeValueObject() { AStringProp = "MyString" }; var e = new SomeValueObject() { AStringProp = "MyString" }; a.EntityProp = c; a.ValueObjectProp = d; b.EntityProp = c; b.ValueObjectProp = e; //Act Assert Assert.IsTrue(a.HasSamePropertyValuesThan(b), ""); }
public void UnitOfWorkWithRefValueObject( out SomeValueObject param, SomeValueObject other) { _ = other ?? throw new ArgumentNullException(); throw new NotImplementedException(); }
public void any_value_is_always_equal_to_itself() { var something = new SomeValueObject(1); ShouldBeEqualAccordingToEqualityOperators(something, something); ShouldBeEqualAccordingToEqualsMethods(something, something); }
private static void ShouldNotBeEqualAccordingToEqualityOperators(SomeValueObject first, SomeValueObject second) { (first == second).Should().BeFalse(); (first != second).Should().BeTrue(); (second == first).Should().BeFalse(); (second != first).Should().BeTrue(); }
public void AValueObject_IsNotEqualToAnotherOne_WhenHaveAnPropertyByReferenceWithDifferentInstances() { //Arrange var objectClass = new SomeClass() { MyProp = "Test" }; var objectClass2 = new SomeClass() { MyProp = "Test" }; var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString", SomeClassProperty = objectClass }; var b = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString", SomeClassProperty = objectClass2 }; //Assert Assert.IsTrue(a != b); }
public void two_nulls_are_always_equal() { SomeValueObject first = null; SomeValueObject second = null; ShouldBeEqualAccordingToEqualityOperators(first, second); ShouldBeEqualAccordingToEqualityOperators(second, first); }
public void any_value_is_never_equal_to_null() { var something = new SomeValueObject(1); SomeValueObject nothing = null; ShouldNotBeEqualAccordingToEqualityOperators(something, nothing); ShouldNotBeEqualAccordingToEqualsMethods(something, nothing); }
public void objects_are_equal_and_have_same_hash_code_when_their_fields_are_equal( int someInt, string someString, bool someBool) { var first = new SomeValueObject(someInt, someString, someBool); var second = new SomeValueObject(someInt, someString, someBool); first.Should().Be(second); first.GetHashCode().Should().Be(second.GetHashCode()); }
public void identical_objects_are_always_equal_equal() { var first = new SomeValueObject(1); var second = new SomeValueObject(1); ShouldBeEqualAccordingToEqualityOperators(first, second); ShouldBeEqualAccordingToEqualsMethods(first, second); ShouldBeEqualAccordingToEqualsMethods(second, first); }
public void different_objects_are_never_equal() { var first = new SomeValueObject(1); var second = new SomeValueObject(2); ShouldNotBeEqualAccordingToEqualityOperators(first, second); ShouldNotBeEqualAccordingToEqualsMethods(first, second); ShouldNotBeEqualAccordingToEqualsMethods(second, first); }
public void Equals_is_faster_than_boxing_primitives_and_calling_equals() { var valueObject1 = new SomeValueObject(1); var valueObject2 = new SomeValueObject(2); var results = Performance.Test(10_000_000, output, ("boxing", () => valueObject1.BoxingEquals(valueObject2)), ("direct", () => valueObject1.DirectEquals(valueObject2)), ("equals", () => valueObject1.ValueEquals(valueObject2))); results["equals"].Should().BeLessThan((long)(results["boxing"] / 2)); }
public void AValueObject_IsNotEqualToAnotherOne_WhenBothAValueObjectPropertyButWithDifferentValues() { //Arrange var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString" }; var b = new SomeValueObject() { SomeIntProp = 2, SomeStringProp = "MyString" }; //Assert Assert.IsTrue(a != b); }
public void AValueObject_IsEqualToAnotherOne_WhenBothAValueObjectPropertyWithSameValues() { //Arrange var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString" }; var b = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString" }; //Assert Assert.IsTrue(a == b); }
public void objects_are_not_equal_and_have_different_hash_codes_when_their_fields_are_not_equal( int firstInt, string firstString, bool firstBool, int secondInt, string secondString, bool secondBool) { Assume.That(firstInt != secondInt || firstString != secondString || firstBool != secondBool); var first = new SomeValueObject(firstInt, firstString, firstBool); var second = new SomeValueObject(secondInt, secondString, secondBool); first.Should().NotBe(second); // since there is a small chance of hash code collision, // we're kind of hoping for the best here first.GetHashCode().Should().NotBe(second.GetHashCode()); }
public void AValueObject_IsEqualToAnotherOne_WhenBothHaveSamePropertyValues() { //Arrange var objectClass = new SomeClass() { MyProp = "Test" }; var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString", SomeClassProperty = objectClass }; var b = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString", SomeClassProperty = objectClass }; //Assert Assert.IsTrue(a == b); }
public void AValueObject_IsNotEqualToAnotherOne_WhenOneOfThemHasNotValueButTheOtheroneYes() { //Arrange var objectClass = new SomeClass() { MyProp = "Test" }; var a = new SomeValueObject() { SomeIntProp = 1, SomeStringProp = "MyString", SomeClassProperty = objectClass }; var b = new SomeValueObject() { SomeStringProp = "MyString", SomeClassProperty = objectClass }; //Assert Assert.IsTrue(a != b); }
public bool BoxingEquals(SomeValueObject other) => ((object)Value).Equals((object)other.Value);
public bool ValueEquals(SomeValueObject other) => DeepEquals(this, other);
private static void ShouldNotBeEqualAccordingToEqualsMethods(SomeValueObject first, SomeValueObject second) { first.Equals((object)second).Should().BeFalse(); first.Equals(second).Should().BeFalse(); }
public void UnitOfWorkWithRefValueObject(ref SomeValueObject param) { Guard.AgainstNull(param, nameof(param)); throw new NotImplementedException(); }
public void two_different_types_are_never_equal() { var something = new SomeValueObject(1); something.Equals("some string").Should().BeFalse(); }
protected override bool EqualsNotNull(SomeValueObject notNullOther) => _value == notNullOther._value;
public bool DirectEquals(SomeValueObject other) => Value == other.Value;