/// <summary> /// Initializes a new instance of the <see cref="ParentEqualityRule{TParent, TValue}"/> class. /// </summary> /// <param name="valueProvider">A service which gets the value to be compared from the parent object.</param> /// <param name="valueRule">A equality rule which tests the 'child' value.</param> public ParentEqualityRule(IGetsValueFromParent <TParent, TValue> valueProvider, IEqualityRule <TValue> valueRule) { this.valueProvider = valueProvider ?? throw new ArgumentNullException(nameof(valueProvider)); this.valueRule = valueRule ?? throw new ArgumentNullException(nameof(valueRule)); resultFactory = new EqualityResultFactory(); }
/// <summary> /// Initializes a new instance of the /// <see cref="ReflectionFieldValueProvider{TParent, TValue}"/> class. /// </summary> /// <param name="field">The field.</param> public ReflectionFieldValueProvider(FieldInfo field) { if (field == null) { throw new ArgumentNullException(nameof(field)); } provider = new DelegateValueProvider <TParent, TValue>(parent => (TValue)field.GetValue(parent)); }
/// <summary> /// Initializes a new instance of the /// <see cref="ReflectionPropertyValueProvider{TParent, TValue}"/> class. /// </summary> /// <param name="property">The property.</param> public ReflectionPropertyValueProvider(PropertyInfo property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } provider = new DelegateValueProvider <TParent, TValue>(GetGetterDelegate(property)); }
public void GetHashCode_uses_value_provider_to_get_value_and_passes_to_wrapped_rule([Frozen] IGetsValueFromParent <EmptyClass, string> valueProvider, [Frozen] IEqualityRule <string> rule, ParentEqualityRule <EmptyClass, string> sut, EmptyClass obj, string str, int hashCode) { Mock.Get(valueProvider).Setup(x => x.GetValue(obj)).Returns(str); Mock.Get(rule).Setup(x => x.GetHashCode(str)).Returns(hashCode); var result = sut.GetHashCode(obj); Mock.Get(rule).Verify(x => x.GetHashCode(str), Times.Once); Assert.That(result, Is.EqualTo(hashCode)); }
public void Equals_uses_value_provider_to_get_values_and_passes_to_wrapped_rule([Frozen] IGetsValueFromParent <EmptyClass, string> valueProvider, [Frozen] IEqualityRule <string> rule, ParentEqualityRule <EmptyClass, string> sut, EmptyClass obj1, EmptyClass obj2, string str1, string str2) { Mock.Get(valueProvider).Setup(x => x.GetValue(obj1)).Returns(str1); Mock.Get(valueProvider).Setup(x => x.GetValue(obj2)).Returns(str2); Mock.Get(rule).Setup(x => x.GetEqualityResult(str1, str2)).Returns(EqualityResult.Equal); var result = sut.Equals(obj1, obj2); Mock.Get(rule).Verify(x => x.GetEqualityResult(str1, str2), Times.Once); Assert.That(result, Is.True); }