예제 #1
0
        public void Create_from_property_should_yield_items_from_lists(string property)
        {
            var prop = Property(property);
            var ctxt = SelfTestUtility.NewTestContext(new FakeTheory(fakeTestMethod), new FakeRunner());

            Assert.Equal(2, TestData.Create(ctxt, MemberAccessors.Property(prop)).Count());
        }
예제 #2
0
        public void Create_from_property_should_yield_singleton_return_type(string property)
        {
            var prop   = Property(property);
            var ctxt   = SelfTestUtility.NewTestContext(new FakeTheory(fakeTestMethod), new FakeRunner());
            var actual = TestData.Create(ctxt, MemberAccessors.Property(prop));

            Assert.Equal(1, actual.Count());
            Assert.Equal("420", actual.First()[0]);
        }
예제 #3
0
        public static ITestDataProvider FromPropertyInfo(PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }
            var accessor = MemberAccessors.Property(property);

            return(FromMemberAccessor(accessor));
        }
예제 #4
0
        public static ITestDataProvider FromFieldInfo(FieldInfo field)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }
            var accessor = MemberAccessors.Field(field);

            return(FromMemberAccessor(accessor));
        }
예제 #5
0
 private void LoadFromKvp(IEnumerable <KeyValuePair <string, object> > expected)
 {
     foreach (var kvp in expected)
     {
         IMemberAccessor accessor  = MemberAccessors.PropertyOrField(kvp.Key);
         object          specified = kvp.Value;
         _items.Add(kvp.Key, new ExpectedAccessorData(
                        kvp.Key,
                        specified,
                        Matcher(specified),
                        accessor
                        ));
     }
 }
예제 #6
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
                        ));
     }
 }
예제 #7
0
        private List <IMemberAccessor> FindAccessors()
        {
            var result = new List <IMemberAccessor>();
            var fields = _type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            var props  = _type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var all    = fields.Concat <MemberInfo>(props);

            foreach (var mem in all)
            {
                var attr   = mem.GetCustomAttribute <DebuggerBrowsableAttribute>();
                var access = MemberAccessors.PropertyOrField(mem);

                if (attr == null)
                {
                    result.Add(access);
                    continue;
                }

                switch (attr.State)
                {
                case DebuggerBrowsableState.Never:
                    break;

                case DebuggerBrowsableState.Collapsed:
                    result.Add(new CollapsedImpl(mem.Name));
                    break;

                case DebuggerBrowsableState.RootHidden:
                    IList <IMemberAccessor> accessors;
                    try {
                        accessors = DisplayActualSchema.Create(access.ReturnType).Accessors;
                    } catch (InvalidOperationException) {
                        // There was a circular dependency in the type dependency graph because
                        // we tried to resolve the factory value of a schema that is already in
                        // progress of being written.  Handle this by collapsing
                        result.Add(new CollapsedImpl(mem.Name));
                        break;
                    }
                    result.AddRange(
                        accessors.Select(a => HideRoot(access, a))
                        );
                    break;
                }
            }
            result.Sort((x, y) => x.Name.CompareTo(y.Name));
            return(result);
        }
예제 #8
0
        IEnumerable <TestData> ITestDataProvider.GetData(TestContext context)
        {
            TestUnit unit          = context.TestUnit;
            var      declaringType = ((TestTheory)unit).TestMethod.DeclaringType;
            var      all           = new List <IMemberAccessor>();

            foreach (var f in _fields)
            {
                var fld = declaringType.GetField(f, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (fld == null)
                {
                    throw SpecFailure.CannotFindDataField(f);
                }
                all.Add(MemberAccessors.Field(fld));
            }
            return(this.WithNames(TestDataProvider.FromMemberAccessors(all).GetData(context), _tags.TestTags));
        }
예제 #9
0
        IEnumerable <TestData> ITestDataProvider.GetData(TestContext context)
        {
            TestUnit unit          = context.TestUnit;
            var      declaringType = ((TestTheory)unit).TestMethod.DeclaringType;
            var      all           = new List <IMemberAccessor>();

            foreach (var p in _properties)
            {
                var prop = declaringType.GetProperty(p, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (prop == null)
                {
                    throw SpecFailure.CannotFindDataProperty(p);
                }

                if (prop.GetMethod == null)
                {
                    throw SpecFailure.DataPropertyIncorrectGetter();
                }
                all.Add(MemberAccessors.Property(prop));
            }
            return(this.WithNames(TestDataProvider.FromMemberAccessors(all).GetData(context), _tags.TestTags));
        }
예제 #10
0
 public static IMemberAccessor GetAccessor(this MemberInfo member)
 {
     return(MemberAccessors.Make(member));
 }