public void GetCustomAttributes_DuplicateAttributesWereAddedToTable_TableAttributesDisallowingMultipleOverwritesExistingAttributes()
        {
            ReflectionTableBuilder builder = new ReflectionTableBuilder();

            builder.ForType <DecoratedTypes.Base>()
            .AddTypeAttributes(new InheritedSingleAttribute("Q"), new InheritedMultiAttribute("Q"), new NonInheritedSingleAttribute("Q"), new NonInheritedMultiAttribute("Q"))
            ;

            var table   = builder.CreateTable();
            var context = new TableReflectionContext(table, TableReflectionContextOptions.Default);

            var originalType = typeof(DecoratedTypes.Base);
            var mappedType   = context.MapType(originalType);

            var expected = new Attribute[] {
                new InheritedMultiAttribute("Q"),
                new InheritedSingleAttribute("Q"),
                new NonInheritedMultiAttribute("Q"),
                new NonInheritedSingleAttribute("Q"),
                new InheritedMultiAttribute(nameof(DecoratedTypes.Base)),
                new NonInheritedMultiAttribute(nameof(DecoratedTypes.Base))
            };

            var actual = FilterAttributes(mappedType.GetCustomAttributes(true));

            SequenceAssert.AreEquivalent(expected, actual);
        }
        public void GetCustomAttributes_ChainedReflectionContexts_ReturnsExpectedAttributes()
        {
            ReflectionTableBuilder builderA = new ReflectionTableBuilder();

            builderA.ForType <DecoratedTypes.Base>()
            .AddTypeAttributes(new InheritedSingleAttribute("Q"), new InheritedMultiAttribute("Q"), new NonInheritedSingleAttribute("Q"), new NonInheritedMultiAttribute("Q"))
            .AddMemberAttributes(t => t.OverriddenProperty, new InheritedSingleAttribute("Q"), new InheritedMultiAttribute("Q"), new NonInheritedSingleAttribute("Q"), new NonInheritedMultiAttribute("Q"))
            ;

            var tableA   = builderA.CreateTable();
            var contextA = new TableReflectionContext(tableA, TableReflectionContextOptions.Default);

            var originalType = typeof(DecoratedTypes.Base);
            var mappedTypeA  = contextA.MapType(originalType);

            ReflectionTableBuilder builderB = new ReflectionTableBuilder();

            builderB.ForType <DecoratedTypes.Base>()
            .AddTypeAttributes(new InheritedSingleAttribute("2"), new InheritedMultiAttribute("2"), new NonInheritedSingleAttribute("2"), new NonInheritedMultiAttribute("2"))
            .AddMemberAttributes(t => t.OverriddenProperty, new InheritedSingleAttribute("2"), new InheritedMultiAttribute("2"), new NonInheritedSingleAttribute("2"), new NonInheritedMultiAttribute("2"))
            ;

            var tableB   = builderB.CreateTable();
            var contextB = new TableReflectionContext(tableB, TableReflectionContextOptions.Default);

            var mappedTypeComposite = contextB.MapType(mappedTypeA);

            var actual   = FilterAttributes(mappedTypeComposite.GetCustomAttributes());
            var expected = new Attribute[]
            {
                new NonInheritedMultiAttribute(nameof(DecoratedTypes.Base)),
                new InheritedMultiAttribute(nameof(DecoratedTypes.Base)),
                new InheritedMultiAttribute("Q"),
                new NonInheritedMultiAttribute("Q"),
                new InheritedSingleAttribute("2"),
                new InheritedMultiAttribute("2"),
                new NonInheritedSingleAttribute("2"),
                new NonInheritedMultiAttribute("2")
            };

            SequenceAssert.AreEquivalent(expected, actual);

            actual   = FilterAttributes(mappedTypeComposite.GetProperty(nameof(UndecoratedTypes.Base.OverriddenProperty)).GetCustomAttributes());
            expected = new Attribute[]
            {
                new NonInheritedMultiAttribute(nameof(DecoratedTypes.Base)),
                new InheritedMultiAttribute(nameof(DecoratedTypes.Base)),
                new InheritedMultiAttribute("Q"),
                new NonInheritedMultiAttribute("Q"),
                new InheritedSingleAttribute("2"),
                new InheritedMultiAttribute("2"),
                new NonInheritedSingleAttribute("2"),
                new NonInheritedMultiAttribute("2")
            };

            SequenceAssert.AreEquivalent(expected, actual);
        }
        private void TestAll(Action <TestInfo> action)
        {
            TableReflectionContext context = new TableReflectionContext(CreateTable(), TableReflectionContextOptions.Default);

            TestAll(action, context);

            context = new TableReflectionContext(CreateTable(), TableReflectionContextOptions.HonorPropertyAttributeInheritance | TableReflectionContextOptions.HonorEventAttributeInheritance);
            TestAll(action, context);
        }
        public void Test()
        {
            TableReflectionContext context = new TableReflectionContext(CreateTable(), TableReflectionContextOptions.Default);
            var elementType = context.MapType(typeof(UndecoratedTypes.Derived));

            Assert.IsTrue(typeof(UndecoratedTypes.Derived).Equals(elementType));
            //var ifcType = context.MapType(typeof(IEnumerable<>)).MakeGenericType(elementType);
            //var ifcs = ifcType.GetInterfaces();
        }
 private void TestAll(Action <TestInfo> action, TableReflectionContext context)
 {
     action(TestInfo.Create <DecoratedTypes.IBase1, UndecoratedTypes.IBase1>(context));
     action(TestInfo.Create <DecoratedTypes.IBase2, UndecoratedTypes.IBase2>(context));
     action(TestInfo.Create <DecoratedTypes.IComposite, UndecoratedTypes.IComposite>(context));
     action(TestInfo.Create <DecoratedTypes.Base, UndecoratedTypes.Base>(context));
     action(TestInfo.Create <DecoratedTypes.Derived, UndecoratedTypes.Derived>(context));
     action(TestInfo.Create <DecoratedTypes.SubDerived, UndecoratedTypes.SubDerived>(context));
     action(TestInfo.Create(typeof(DecoratedTypes.GenericDerived <>), typeof(UndecoratedTypes.GenericDerived <>), context));
     action(TestInfo.Create(typeof(DecoratedTypes.GenericDerived), typeof(UndecoratedTypes.GenericDerived), context));
 }
        public void GetCustomAttributes_SpecificAttributeType_CorrectlyFiltersAttributes()
        {
            ReflectionTableBuilder builderA = new ReflectionTableBuilder();

            builderA.ForType <UndecoratedTypes.Base>()
            .AddTypeAttributes(CreateTestAttributes(nameof(UndecoratedTypes.Base)));

            var tableA   = builderA.CreateTable();
            var contextA = new TableReflectionContext(tableA, TableReflectionContextOptions.Default);

            var actual   = contextA.MapType(typeof(UndecoratedTypes.Base)).GetCustomAttributes(typeof(InheritedSingleAttribute), true);
            var expected = typeof(DecoratedTypes.Base).GetCustomAttributes(typeof(InheritedSingleAttribute), true);

            Assert.AreEqual(expected.GetType(), actual.GetType());
            SequenceAssert.AreEquivalent(expected, actual);
        }
 public static TestInfo Create(Type sourceType, Type targetType, TableReflectionContext reflectionContext)
 {
     return(new TestInfo(sourceType, reflectionContext.MapType(targetType), reflectionContext));
 }
 public static TestInfo Create <SourceType, TargetType>(TableReflectionContext reflectionContext)
 {
     return(new TestInfo(typeof(SourceType), reflectionContext.MapType(typeof(TargetType)), reflectionContext));
 }
 public TestInfo(Type sourceType, Type targetType, TableReflectionContext reflectionContext)
 {
     SourceType        = sourceType;
     TargetType        = targetType;
     ReflectionContext = reflectionContext;
 }