static void Asserts(ProjectionHarvester harvester)
        {
            IFieldHarvester fh = (IFieldHarvester)harvester;

            Assert.IsTrue(fh.CanHandleType(typeof(A)));
            var fields = fh.GetFields(typeof(A)).Select(x => x.SanitizedName);

            CollectionAssert.AreEquivalent(new[] { "Name" }, fields);

            Assert.IsTrue(fh.CanHandleType(typeof(B)));
            fields = fh.GetFields(typeof(B)).Select(x => x.SanitizedName);
            CollectionAssert.AreEquivalent(new[] { "Name", "Age" }, fields);

            Assert.IsFalse(fh.CanHandleType(typeof(C)));
        }
            public void Include_Fieldsarr_WorksForTypesAndSubtypes()
            {
                var harvester = new ProjectionHarvester();

                harvester.Include <B>(x => x.Name, x => x.Age);

                IFieldHarvester fh = (IFieldHarvester)harvester;

                Assert.IsFalse(fh.CanHandleType(typeof(A)));
                Assert.IsTrue(fh.CanHandleType(typeof(B)));
                var fields = fh.GetFields(typeof(B)).Select(x => x.SanitizedName);

                CollectionAssert.AreEquivalent(new[] { "Name", "Age" }, fields);

                Assert.IsFalse(fh.CanHandleType(typeof(C)));
            }
Esempio n. 3
0
            public void Exclude_FieldInSuperclass_WorksForTypesAndSubtypes()
            {
                var harvester = new SelectiveHarvester();

                harvester.Exclude <B>(x => x.Name);

                IFieldHarvester fh = (IFieldHarvester)harvester;

                Assert.IsFalse(fh.CanHandleType(typeof(A)));

                Assert.IsTrue(fh.CanHandleType(typeof(B)));
                var fields = fh.GetFields(typeof(B)).Select(x => x.SanitizedName);

                CollectionAssert.AreEquivalent(new[] { "X", "Y", "Age" }, fields);

                Assert.IsFalse(fh.CanHandleType(typeof(C)));
            }