Beispiel #1
0
        private ReflectionWrapper FindMember(ReflectionWrapper other)
        {
            var fields = this.GetSubExtendedMemberInfosFields();

            foreach (var info in fields)
            {
                if (other.NameInSource == info.NameInSource)
                {
                    return(info);
                }
            }

            return(null);
        }
Beispiel #2
0
        private void MapFields(
            ReflectionWrapper expected,
            ICollection <object> scanned,
            int depth, Func <ReflectionWrapper, ReflectionWrapper, int, bool> mapFunction)
        {
            if (!mapFunction(this, expected, depth))
            {
                // no need to recurse
                return;
            }

            if (this.Value != null)
            {
                // logic recursion prevention, only for (non null) reference type
                if (scanned.Contains(this.Value))
                {
                    return;
                }

                scanned.Add(this.Value);
            }

            // we recurse
            var nextDepth = depth - 1;

            foreach (var member in this.GetSubExtendedMemberInfosFields())
            {
                member.MapFields(expected.FindMember(member), scanned, nextDepth, mapFunction);
            }

            // we deal with missing fields (unless asked to ignore them)
            if (this.Criteria.IgnoreExtra)
            {
                return;
            }

            foreach (var expectedField in expected.GetSubExtendedMemberInfosFields())
            {
                if (this.FindMember(expectedField) == null)
                {
                    mapFunction(null, expectedField, nextDepth);
                }
            }
        }
Beispiel #3
0
        private static AggregatedDifference AnonymousTypeDifference <TA, TE>(TA actual, TE expected, Type type,
                                                                             AggregatedDifference result)
        {
            var criteria = new ClassMemberCriteria(BindingFlags.Instance);

            criteria.SetPublic();
            criteria.CaptureProperties();
            criteria.CaptureFields();
            // use field based comparison
            var wrapper       = ReflectionWrapper.BuildFromInstance(type, expected, criteria);
            var actualWrapped = ReflectionWrapper.BuildFromInstance(actual.GetType(), actual, criteria);

            foreach (var match in actualWrapped.MemberMatches(wrapper).Where(match => !match.DoValuesMatches))
            {
                result.Add(DifferenceDetails.FromMatch(match));
            }

            return(result);
        }
Beispiel #4
0
        private void MapFields(
            ReflectionWrapper actual,
            ICollection <object> scanned,
            int depth, Func <ReflectionWrapper, ReflectionWrapper, int, bool> mapFunction)
        {
            if (this.ValueType.IsClass() && this.Value != null)
            {
                // logic recursion prevention, only for (non null) reference type
                if (scanned.Contains(this.Value))
                {
                    return;
                }

                scanned.Add(this.Value);
            }

            if (!mapFunction(this, actual, depth))
            {
                // no need to recurse
                return;
            }

            // we recurse
            foreach (var member in this.GetSubExtendedMemberInfosFields())
            {
                member.MapFields(actual.FindMember(member), scanned, depth - 1, mapFunction);
            }

            // we deal with missing fields
            if (this.Criteria.IgnoreExtra)
            {
                return;
            }

            foreach (var actualFields in actual.GetSubExtendedMemberInfosFields())
            {
                if (this.FindMember(actualFields) == null)
                {
                    mapFunction(null, actualFields, depth - 1);
                }
            }
        }
Beispiel #5
0
        internal List <MemberMatch> MemberMatches <TU>(TU expectedValue)
        {
            var expectedWrapped =
                ReflectionWrapper.BuildFromInstance(expectedValue?.GetType() ?? typeof(TU), expectedValue, this.Criteria);

            var result = new List <MemberMatch>();

            expectedWrapped.MapFields(this, 1, (expected, actual, depth) =>
            {
                if (actual?.Value == null || expected?.Value == null)
                {
                    result.Add(new MemberMatch(expected, actual));
                    return(false);
                }

                if (depth <= 0 && expected.ValueType.ImplementsEquals())
                {
                    result.Add(new MemberMatch(expected, actual));
                    return(false);
                }

                if (!expected.IsArray)
                {
                    return(true);
                }

                if (actual.IsArray && ((Array)expected.Value).Length == ((Array)actual.Value).Length)
                {
                    return(true);
                }

                result.Add(new MemberMatch(expected, actual));
                return(false);
            });
            return(result);
        }
Beispiel #6
0
        private ReflectionWrapper FindMember(ReflectionWrapper other)
        {
            var fields = this.GetSubExtendedMemberInfosFields();

            return(fields.FirstOrDefault(info => other.NameInSource == info.NameInSource));
        }
Beispiel #7
0
 internal void MapFields(ReflectionWrapper other,
                         int depth, Func <ReflectionWrapper, ReflectionWrapper, int, bool> mapFunction)
 {
     this.MapFields(other, new List <object>(), depth, mapFunction);
 }
Beispiel #8
0
 public MemberMatch(ReflectionWrapper expected, ReflectionWrapper actual)
 {
     this.Actual   = actual;
     this.Expected = expected;
 }