public void GetCustomAttributes_ChainedReflectionContextsMappedMultipleTimes_DuplicateMappingsIgnoredAndReturnsExpectedAttributes()
        {
            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 = contextA.MapType(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);
        }
        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 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();
        }
        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));
 }