示例#1
0
 private void LoadFromObject(object expected, TestMemberFilter filter)
 {
     foreach (var f in filter.GetMembers(expected.GetType().GetTypeInfo()))
     {
         IMemberAccessor accessor;
         accessor = MemberAccessors.PropertyOrField(f);
         object specified = accessor.GetValue(expected);
         _items.Add(f.Name, new ExpectedAccessorData(
                        f.Name,
                        specified,
                        Matcher(specified),
                        accessor
                        ));
     }
 }
示例#2
0
                public ExpectedAccessors(bool untypedTarget, object expected, TestMemberFilter filter)
                {
                    if (expected is null)
                    {
                        return;
                    }

                    // If the target is untyped, then we can't use the field or property directly
                    // because it could mismatch, so we have to evaluate it now
                    if (untypedTarget)
                    {
                        LoadFromKvp(GetFieldsAndProperties(expected, filter));
                    }
                    else
                    {
                        LoadFromObject(expected, filter);
                    }
                }
 public MemberwiseEqualMatcher(T expected, params TestMemberFilter[] memberFilters)
 {
     Expected     = expected;
     MemberFilter = TestMemberFilter.Compose(memberFilters);
 }
 private static IEnumerable <string> Names(TestMemberFilter filter)
 {
     return(filter.GetMembers(typeof(PObject).GetTypeInfo()).Select(p => p.Name));
 }
示例#5
0
 private IEnumerable <KeyValuePair <string, object> > GetFieldsAndProperties(object expected, TestMemberFilter filter)
 {
     foreach (var f in filter.GetMembers(expected.GetType().GetTypeInfo()))
     {
         if (f is FieldInfo field)
         {
             yield return(new KeyValuePair <string, object>(f.Name, field.GetValue(expected)));
         }
         else
         {
             yield return(new KeyValuePair <string, object>(f.Name, ((PropertyInfo)f).GetValue(expected)));
         }
     }
 }