public void GenerateXml_InterfaceDynamicallyImplemented()
        {
            var targetType = new InvolvedType(typeof(TargetClass3));

            var mixinConfiguration = MixinConfiguration.BuildNew().ForClass <TargetClass3> ().AddMixin <Mixin4> ().BuildConfiguration();

            targetType.ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.First());
            targetType.TargetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(targetType.Type, mixinConfiguration));
            var mixinContext    = targetType.ClassContext.GetProperty("Mixins").First();
            var mixinDefinition = targetType.TargetClassDefinition.CallMethod("GetMixinByConfiguredType", mixinContext.GetProperty("MixinType").To <Type> ());

            var assemblyIdentifierGenerator = new IdentifierGenerator <Assembly> ();

            var output = new TargetCallDependenciesReportGenerator(mixinDefinition, assemblyIdentifierGenerator,
                                                                   _remotionReflector, _outputFormatter).GenerateXml();

            var expectedOutput = new XElement("TargetCallDependencies",
                                              new XElement("Dependency",
                                                           new XAttribute("assembly-ref", "0"),
                                                           new XAttribute("namespace", "System"),
                                                           new XAttribute("name", "IDisposable"),
                                                           new XAttribute("is-interface", true),
                                                           new XAttribute("is-implemented-by-target", false),
                                                           new XAttribute("is-added-by-mixin", false),
                                                           new XAttribute("is-implemented-dynamically", true)));

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_TargetClassWithOverriddenBaseClassMember()
        {
            var type = typeof(InheritatedTargetClass);
            var mixinConfiguration =
                MixinConfiguration.BuildNew().ForClass <InheritatedTargetClass> ().AddMixin <MixinOverridesTargetClassMember> ().BuildConfiguration();
            var targetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(type, mixinConfiguration));

            var involvedType = new InvolvedType(type)
            {
                TargetClassDefinition = targetClassDefinition
            };

            var reportGenerator = CreateMemberReportGenerator(type, involvedType);
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("InheritatedTargetClass", new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "1"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "MyBaseClassMethod"),
                    new XAttribute("is-declared-by-this-class", false),
                    _outputFormatter.CreateModifierMarkup("", "public virtual"),
                    _outputFormatter.CreateMethodMarkup("MyBaseClassMethod", typeof(void), new ParameterInfo[0]),
                    GenerateOverrides("Mixin-Reference", "0", "MixinOverridesTargetClassMember")
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "2"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "MyNewMethod"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public virtual"),
                    _outputFormatter.CreateMethodMarkup("MyNewMethod", typeof(void), new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "3"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "MyNonRelevantBaseClassMethod"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public override"),
                    _outputFormatter.CreateMethodMarkup("MyNonRelevantBaseClassMethod", typeof(void), new ParameterInfo[0]),
                    GenerateOverrides("Mixin-Reference", "0", "MixinOverridesTargetClassMember")
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_PropertyWithGetAndSet_Overridden()
        {
            var reportGenerator = CreateMemberReportGenerator(typeof(ClassWithProperty), new InvolvedType(typeof(ClassWithProperty)));
            var property        = typeof(ClassWithProperty).GetProperty("PropertyName");
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("ClassWithProperty", new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "1"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "DoSomething"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public override"),
                    _outputFormatter.CreateMethodMarkup("DoSomething", typeof(void), new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "2"),
                    new XAttribute("type", MemberTypes.Property),
                    new XAttribute("name", "PropertyName"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public override"),
                    _outputFormatter.CreatePropertyMarkup("PropertyName", typeof(string)),
                    new XElement(
                        "SubMember",
                        new XAttribute("id", "3"),
                        new XAttribute("type", MemberTypes.Method),
                        new XAttribute("name", "get_PropertyName"),
                        _outputFormatter.CreateModifierMarkup("", "public override"),
                        _outputFormatter.CreateMethodMarkup("get_PropertyName", typeof(string), new ParameterInfo[0])
                        ),
                    new XElement(
                        "SubMember",
                        new XAttribute("id", "4"),
                        new XAttribute("type", MemberTypes.Method),
                        new XAttribute("name", "set_PropertyName"),
                        _outputFormatter.CreateModifierMarkup("", "public override"),
                        _outputFormatter.CreateMethodMarkup("set_PropertyName", typeof(void), property.GetSetMethod().GetParameters())
                        )
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml()
        {
            var type = typeof(MemberOverrideTestClass.Target);
            var mixinConfiguration =
                MixinConfiguration.BuildNew().ForClass <MemberOverrideTestClass.Target> ().AddMixin <MemberOverrideTestClass.Mixin1> ().BuildConfiguration();
            var targetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(type, mixinConfiguration));
            var involvedType          = new InvolvedType(type);

            involvedType.TargetClassDefinition = targetClassDefinition;

            var memberIdentifierGenerator = new IdentifierGenerator <MemberInfo> ();

            var reportGenerator = new MemberReportGenerator(type, involvedType, new IdentifierGenerator <Type> (), memberIdentifierGenerator, _outputFormatter);

            var output         = reportGenerator.GenerateXml();
            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("Target", new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "1"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "OverriddenMethod"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public virtual"),
                    _outputFormatter.CreateMethodMarkup("OverriddenMethod", typeof(void), new ParameterInfo[0]),
                    GenerateOverrides("Mixin-Reference", "0", "MemberOverrideTestClass+Mixin1")
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "3"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "TemplateMethod"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("OverrideMixin ", "public"),
                    _outputFormatter.CreateMethodMarkup("TemplateMethod", typeof(void), new ParameterInfo[0]),
                    GenerateOverriddenMember("2", "TemplateMethod", "Void TemplateMethod()")
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_InterfaceWithMembers()
        {
            var reportGenerator = CreateMemberReportGenerator(typeof(IDisposable), null);
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "Dispose"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public abstract"),
                    _outputFormatter.CreateMethodMarkup("Dispose", typeof(void), new ParameterInfo[0])
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_MixinWithOverriddenClassMember()
        {
            var mixinType  = typeof(MixinWithInheritedMethod);
            var targetType = typeof(ClassOverridingInheritedMixinMethod);
            var mixin      = new InvolvedType(mixinType);
            var target     = new InvolvedType(targetType);

            var mixinConfiguration =
                MixinConfiguration.BuildNew().ForClass <ClassOverridingInheritedMixinMethod> ().AddMixin <MixinWithInheritedMethod> ().BuildConfiguration();
            var targetClassDefinition = TargetClassDefinitionUtility.GetConfiguration(targetType, mixinConfiguration);

            mixin.TargetTypes.Add(target, new ReflectedObject(targetClassDefinition.GetMixinByConfiguredType(mixinType)));

            var reportGenerator = CreateMemberReportGenerator(mixinType, mixin);
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("MixinWithInheritedMethod", new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "1"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "ProtectedInheritedMethod"),
                    new XAttribute("is-declared-by-this-class", false),
                    _outputFormatter.CreateModifierMarkup("", "protected virtual"),
                    _outputFormatter.CreateMethodMarkup("ProtectedInheritedMethod", typeof(string), new ParameterInfo[0]),
                    GenerateOverrides("Target-Reference", "0", "ClassOverridingInheritedMixinMethod")
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_ForInterface()
        {
            var involvedType1 = new InvolvedType(typeof(IUseless));

            var reportGenerator = CreateInvolvedTypeReportGenerator(involvedType1);
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "InvolvedTypes",
                new XElement(
                    "InvolvedType",
                    new XAttribute("id", "0"),
                    new XAttribute("assembly-ref", "0"),
                    new XAttribute("namespace", "MixinXRef.UnitTests.TestDomain"),
                    new XAttribute("name", "IUseless"),
                    new XAttribute("base", "none"),
                    new XAttribute("base-ref", "none"),
                    new XAttribute("is-target", false),
                    new XAttribute("is-mixin", false),
                    new XAttribute("is-unusedmixin", false),
                    new XAttribute("is-generic-definition", false),
                    new XAttribute("is-interface", true),
                    _outputFormatter.CreateModifierMarkup("", _typeModifierUtility.GetTypeModifiers(involvedType1.Type)),
                    _summaryPicker.GetSummary(involvedType1.Type),
                    new MemberReportGenerator(involvedType1.Type, null, null, _memberIdentifierGenerator, _outputFormatter).
                    GenerateXml(),
                    new InterfaceReferenceReportGenerator(involvedType1, _interfaceIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new AttributeReferenceReportGenerator(involvedType1.Type, _attributeIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new MixinReferenceReportGenerator(
                        involvedType1, _assemblyIdentifierGenerator,
                        _readOnlyInvolvedTypeIdentifierGenerator,
                        _interfaceIdentifierGenerator,
                        _attributeIdentifierGenerator,
                        _remotionReflector,
                        _outputFormatter).
                    GenerateXml(),
                    new TargetReferenceReportGenerator(involvedType1, _readOnlyInvolvedTypeIdentifierGenerator).GenerateXml()
                    ));

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_ObjectWithoutOwnMembers()
        {
            var reportGenerator = CreateMemberReportGenerator(typeof(UselessObject), new InvolvedType(typeof(UselessObject)));

            var output = reportGenerator.GenerateXml();

            // enhancement: surpress output of default constructor if generated by compiler
            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("UselessObject", new ParameterInfo[0])
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public void GenerateXml_InvolvedTypes()
        {
            var mixinConfiguration = MixinConfiguration.BuildNew()
                                     .ForClass <TargetClass1> ().AddMixin <Mixin1> ()
                                     .ForClass <TargetClass2> ().AddMixin <Mixin2> ()
                                     .BuildConfiguration();

            var involvedType1 = new InvolvedType(typeof(TargetClass1));

            involvedType1.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First());
            SetTargetClassDefinition(involvedType1, mixinConfiguration);

            var involvedType2 = new InvolvedType(typeof(TargetClass2));

            involvedType2.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.Last());
            SetTargetClassDefinition(involvedType2, mixinConfiguration);

            var involvedType3 = new InvolvedType(typeof(Mixin1));

            involvedType3.TargetTypes.Add(new InvolvedType(typeof(TargetClass1)), null);
            var involvedType4 = new InvolvedType(typeof(Mixin2));

            involvedType4.TargetTypes.Add(new InvolvedType(typeof(TargetClass2)), null);

            var reportGenerator = CreateInvolvedTypeReportGenerator(involvedType1, involvedType2, involvedType3, involvedType4);
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "InvolvedTypes",
                new XElement(
                    "InvolvedType",
                    new XAttribute("id", "0"),
                    new XAttribute("assembly-ref", "0"),
                    new XAttribute("namespace", "MixinXRef.UnitTests.TestDomain"),
                    new XAttribute("name", "TargetClass1"),
                    new XAttribute("base", "Object"),
                    new XAttribute("base-ref", "none"),
                    new XAttribute("is-target", true),
                    new XAttribute("is-mixin", false),
                    new XAttribute("is-unusedmixin", false),
                    new XAttribute("is-generic-definition", false),
                    new XAttribute("is-interface", false),
                    _outputFormatter.CreateModifierMarkup("", _typeModifierUtility.GetTypeModifiers(involvedType1.Type)),
                    _summaryPicker.GetSummary(involvedType1.Type),
                    new MemberReportGenerator(involvedType1.Type, involvedType1, _involvedTypeIdentifierGenerator, _memberIdentifierGenerator, _outputFormatter).
                    GenerateXml(),
                    new InterfaceReferenceReportGenerator(involvedType1, _interfaceIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new AttributeReferenceReportGenerator(involvedType1.Type, _attributeIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new MixinReferenceReportGenerator(
                        involvedType1, _assemblyIdentifierGenerator,
                        _readOnlyInvolvedTypeIdentifierGenerator,
                        _interfaceIdentifierGenerator,
                        _attributeIdentifierGenerator,
                        _remotionReflector,
                        _outputFormatter).
                    GenerateXml(),
                    new TargetReferenceReportGenerator(involvedType1, _readOnlyInvolvedTypeIdentifierGenerator).GenerateXml()
                    ),
                new XElement(
                    "InvolvedType",
                    new XAttribute("id", "1"),
                    new XAttribute("assembly-ref", "0"),
                    new XAttribute("namespace", "MixinXRef.UnitTests.TestDomain"),
                    new XAttribute("name", "TargetClass2"),
                    new XAttribute("base", "Object"),
                    new XAttribute("base-ref", "none"),
                    new XAttribute("is-target", true),
                    new XAttribute("is-mixin", false),
                    new XAttribute("is-unusedmixin", false),
                    new XAttribute("is-generic-definition", false),
                    new XAttribute("is-interface", false),
                    _outputFormatter.CreateModifierMarkup("", _typeModifierUtility.GetTypeModifiers(involvedType2.Type)),
                    _summaryPicker.GetSummary(involvedType2.Type),
                    new MemberReportGenerator(involvedType2.Type, involvedType2, _involvedTypeIdentifierGenerator, _memberIdentifierGenerator, _outputFormatter).
                    GenerateXml(),
                    new InterfaceReferenceReportGenerator(involvedType2, _interfaceIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new AttributeReferenceReportGenerator(involvedType2.Type, _attributeIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new MixinReferenceReportGenerator(
                        involvedType2, _assemblyIdentifierGenerator,
                        _readOnlyInvolvedTypeIdentifierGenerator,
                        _interfaceIdentifierGenerator,
                        _attributeIdentifierGenerator,
                        _remotionReflector,
                        _outputFormatter).
                    GenerateXml(),
                    new TargetReferenceReportGenerator(involvedType2, _readOnlyInvolvedTypeIdentifierGenerator).GenerateXml()
                    ),
                new XElement(
                    "InvolvedType",
                    new XAttribute("id", "2"),
                    new XAttribute("assembly-ref", "0"),
                    new XAttribute("namespace", "MixinXRef.UnitTests.TestDomain"),
                    new XAttribute("name", "Mixin1"),
                    new XAttribute("base", "Object"),
                    new XAttribute("base-ref", "none"),
                    new XAttribute("is-target", false),
                    new XAttribute("is-mixin", true),
                    new XAttribute("is-unusedmixin", false),
                    new XAttribute("is-generic-definition", false),
                    new XAttribute("is-interface", false),
                    _outputFormatter.CreateModifierMarkup("", _typeModifierUtility.GetTypeModifiers(involvedType3.Type)),
                    _summaryPicker.GetSummary(involvedType3.Type),
                    new MemberReportGenerator(involvedType3.Type, involvedType3, _involvedTypeIdentifierGenerator, _memberIdentifierGenerator, _outputFormatter).
                    GenerateXml(),
                    new InterfaceReferenceReportGenerator(involvedType3, _interfaceIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new AttributeReferenceReportGenerator(involvedType3.Type, _attributeIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new MixinReferenceReportGenerator(
                        involvedType3, _assemblyIdentifierGenerator,
                        _readOnlyInvolvedTypeIdentifierGenerator,
                        _interfaceIdentifierGenerator,
                        _attributeIdentifierGenerator,
                        _remotionReflector,
                        _outputFormatter).
                    GenerateXml(),
                    new TargetReferenceReportGenerator(involvedType3, _readOnlyInvolvedTypeIdentifierGenerator).GenerateXml()
                    ),
                new XElement(
                    "InvolvedType",
                    new XAttribute("id", "3"),
                    new XAttribute("assembly-ref", "0"),
                    new XAttribute("namespace", "MixinXRef.UnitTests.TestDomain"),
                    new XAttribute("name", "Mixin2"),
                    new XAttribute("base", "Object"),
                    new XAttribute("base-ref", "none"),
                    new XAttribute("is-target", false),
                    new XAttribute("is-mixin", true),
                    new XAttribute("is-unusedmixin", false),
                    new XAttribute("is-generic-definition", false),
                    new XAttribute("is-interface", false),
                    _outputFormatter.CreateModifierMarkup("", _typeModifierUtility.GetTypeModifiers(involvedType4.Type)),
                    _summaryPicker.GetSummary(involvedType4.Type),
                    new MemberReportGenerator(involvedType4.Type, involvedType4, _involvedTypeIdentifierGenerator, _memberIdentifierGenerator, _outputFormatter).
                    GenerateXml(),
                    new InterfaceReferenceReportGenerator(involvedType4, _interfaceIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new AttributeReferenceReportGenerator(involvedType4.Type, _attributeIdentifierGenerator, _remotionReflector).GenerateXml(),
                    new MixinReferenceReportGenerator(
                        involvedType4, _assemblyIdentifierGenerator,
                        _readOnlyInvolvedTypeIdentifierGenerator,
                        _interfaceIdentifierGenerator,
                        _attributeIdentifierGenerator,
                        _remotionReflector,
                        _outputFormatter).
                    GenerateXml(),
                    new TargetReferenceReportGenerator(involvedType4, _readOnlyInvolvedTypeIdentifierGenerator).GenerateXml()
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }