/// <summary>
        /// Builds and returns a collection of <see cref="IEqualityRule{T}"/>.
        /// </summary>
        /// <returns>The rules.</returns>
        /// <param name="allBuilders">A collection of all rule-builders.</param>
        public override IEnumerable <IEqualityRule <TParent> > GetRules(IEnumerable <RuleBuilder <TParent> > allBuilders)
        {
            var delegateRule  = new EqualityRule <TValue>(Comparer(), Name);
            var valueProvider = new DelegateValueProvider <TParent, TValue>(Delegate);
            var parentRule    = new ParentEqualityRule <TParent, TValue>(valueProvider, delegateRule);

            return(new[] { parentRule });
        }
Esempio n. 2
0
        /// <summary>
        /// Builds and returns a collection of <see cref="IEqualityRule{T}"/>.
        /// </summary>
        /// <returns>The rules.</returns>
        /// <param name="allBuilders">A collection of all rule-builders.</param>
        public override IEnumerable <IEqualityRule <TParent> > GetRules(IEnumerable <RuleBuilder <TParent> > allBuilders)
        {
            var fieldRule     = new EqualityRule <object>(Comparer(), Name);
            var valueProvider = new ReflectionFieldValueProvider <TParent, object>(Field);
            var parentRule    = new ParentEqualityRule <TParent, object>(valueProvider, fieldRule);

            return(new[] { parentRule });
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }