public void ValueObjectParameterHashingTests() { SomeValueClass someValueObject1A = new SomeValueClass { IntProperty = 1, StringProperty = "1" }; SomeValueClass someValueObject1B = new SomeValueClass { IntProperty = 1, StringProperty = "1" }; SomeValueClass someValueObject1C = new SomeValueClass { IntProperty = 1, StringProperty = "1" }; SomeValueClass someValueObject2 = new SomeValueClass { IntProperty = 2, StringProperty = "2" }; SomeValueClass someValueObject3 = new SomeValueClass { IntProperty = 3, StringProperty = "3" }; someValueObject1A.ChildrenProperty = new List <SomeValueClass> { someValueObject2, someValueObject3 }; someValueObject1B.ChildrenProperty = new List <SomeValueClass> { someValueObject2, someValueObject3 }; someValueObject1C.ChildrenProperty = new List <SomeValueClass> { someValueObject2, someValueObject3, someValueObject2, someValueObject3 }; Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A))); // NB! Value equality Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1B))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1C))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject2))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject3))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1B), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1B))); // NB! Value equality Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1B), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1B, someValueObject1A))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1C), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1C, someValueObject1A))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject2), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject2))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject2), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1A))); }
public override bool Equals(object otherObject) { if (ReferenceEquals(null, otherObject)) { return(false); } if (ReferenceEquals(this, otherObject)) { return(true); } if (!(otherObject is SomeValueClass)) { return(false); } SomeValueClass otherSomeValueClass = otherObject as SomeValueClass; return(this.IntProperty.Equals(otherSomeValueClass.IntProperty) && this.StringProperty.Equals(otherSomeValueClass.StringProperty) && this.ChildrenProperty.Equals(otherSomeValueClass.ChildrenProperty)); }
public void ValueObjectParameterHashingTests() { SomeValueClass someValueObject1A = new SomeValueClass { IntProperty = 1, StringProperty = "1" }; SomeValueClass someValueObject1B = new SomeValueClass { IntProperty = 1, StringProperty = "1" }; SomeValueClass someValueObject1C = new SomeValueClass { IntProperty = 1, StringProperty = "1" }; SomeValueClass someValueObject2 = new SomeValueClass { IntProperty = 2, StringProperty = "2" }; SomeValueClass someValueObject3 = new SomeValueClass { IntProperty = 3, StringProperty = "3" }; someValueObject1A.ChildrenProperty = new List<SomeValueClass> { someValueObject2, someValueObject3 }; someValueObject1B.ChildrenProperty = new List<SomeValueClass> { someValueObject2, someValueObject3 }; someValueObject1C.ChildrenProperty = new List<SomeValueClass> { someValueObject2, someValueObject3, someValueObject2, someValueObject3 }; Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A))); // NB! Value equality Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1B))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1C))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject2))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject3))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1B), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1B))); // NB! Value equality Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1B), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1B, someValueObject1A))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1C), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1C, someValueObject1A))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject2), Is.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject2))); Assert.That(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject2), Is.Not.EqualTo(MemoizerHelper.CreateParameterHash(someValueObject1A, someValueObject1A))); }