示例#1
0
        public void GenericParameterRenameTest()
        {
            var context   = MetadataResolutionContext.CreateFromTypes(typeof(MiscellaneousTests));
            var typeData1 = context.GetTypeDefinitionData(typeof(GenericParameter1 <>));
            var typeData2 = context.GetTypeDefinitionData(typeof(GenericParameter2 <>));
            var typeData3 = context.GetTypeDefinitionData(typeof(GenericParameter3 <,>));
            var typeData4 = context.GetTypeDefinitionData(typeof(GenericParameter4 <,>));

            var breakingChanges = MetadataComparer.CompareTypes(typeData1, typeData2);

            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes for renaming a class's generic type parameter.");

            breakingChanges = MetadataComparer.CompareTypes(typeData3, typeData4);
            AssertX.Equal(1, breakingChanges.Count, "There should be a breaking changes for using a different generic type parameter position as a return type.");
            AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "There should be a breaking changes for using a different generic type parameter position as a return type.");

            typeData1 = context.GetTypeDefinitionData(typeof(GenericMethodParameter1));
            typeData2 = context.GetTypeDefinitionData(typeof(GenericMethodParameter2));
            typeData3 = context.GetTypeDefinitionData(typeof(GenericMethodParameter3));
            typeData4 = context.GetTypeDefinitionData(typeof(GenericMethodParameter4));

            breakingChanges = MetadataComparer.CompareTypes(typeData1, typeData2);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes for renaming a class's generic type parameter.");

            breakingChanges = MetadataComparer.CompareTypes(typeData3, typeData4);
            AssertX.Equal(1, breakingChanges.Count, "There should be a breaking changes for using a different generic type parameter position as a return type.");
            AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "There should be a breaking changes for using a different generic type parameter position as a return type.");
        }
示例#2
0
        public void TypeDefinitionDataMembersInStructTest()
        {
            var t        = typeof(TestStructDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            AssertX.NotNull(typeData, "Unable to create a TypeDefinitionData instance from the TestClassDefinition type.");

            TestUtilities.VerifyMember <ConstantData>(typeData, "Constant");
            TestUtilities.VerifyInstanceAndStaticMember <FieldData>(typeData, "Field");
            TestUtilities.VerifyInstanceAndStaticMember <FieldData>(typeData, "FieldReadOnly");

            var members = typeData.GetMembers(".ctor");

            AssertX.Equal(2, members.Count, "Incorrect number of constructors returned.");
            AssertX.Equal(0, ((ConstructorData)members[0]).Parameters.Count, "The default constructor should have been returned.");
            AssertX.Equal(1, ((ConstructorData)members[1]).Parameters.Count, "The public constructor should have been returned.");

            TestUtilities.VerifyInstanceAndStaticMember <EventData>(typeData, "Event");
            TestUtilities.VerifyInstanceAndStaticMember <EventData>(typeData, "EventCustom");

            members = typeData.GetMembers("Item");
            AssertX.Equal(1, members.Count, "Incorrect number of indexers returned.");
            AssertX.Equal(1, ((IndexerData)members[0]).Parameters.Count, "The public indexer should have been returned.");

            TestUtilities.VerifyInstanceAndStaticMember <MethodData>(typeData, "Method");

            var member = (OperatorData)typeData.GetMember("op_Addition");

            AssertX.NotNull(member, "OperatorData instances should be returned.");

            TestUtilities.VerifyInstanceAndStaticMember <PropertyData>(typeData, "Property");

            TestUtilities.VerifyMember <TypeDefinitionData>(typeData, "NestedStruct");
        }
        internal AssemblyData(
            MetadataResolutionContext context,
            string fullName,
            string name,
            string versionComparisonName,
            IEnumerable <KeyValuePair <string, string> > namespaceRenames)
        {
            Context = context;

            _constructedGenericsToFinalizeAfterLoad = new List <ConstructedGenericTypeData>();
            _forwardedTypeSources         = new Dictionary <TypeDefinitionData, List <AssemblyData> >();
            _forwardedTypeSourcesOnTarget = new Dictionary <TypeDefinitionData, string>();
            _methodOwnedGenericParameters = new Dictionary <Tuple <MethodSignature, int>, GenericTypeParameterData>();
            _namespaceRenames             = new Dictionary <string, string>();
            _referencedAssemblies         = new HashSet <AssemblyData>();
            _typeDefinitions            = new Dictionary <string, TypeDefinitionData>();
            _typeOwnedGenericParameters = new Dictionary <Tuple <string, int>, GenericTypeParameterData>();

            FullName = fullName;
            Name     = name;
            VersionComparisonName = versionComparisonName;

            if (namespaceRenames != null)
            {
                foreach (var namespaceRename in namespaceRenames)
                {
                    _namespaceRenames[namespaceRename.Key] = namespaceRename.Value;
                }
            }
        }
        public void MethodTests()
        {
            var context                = MetadataResolutionContext.CreateFromTypes(typeof(RemovedOverrideOfAbstractMemberTests));
            var MethodVirtual          = context.GetTypeDefinitionData(typeof(MethodVirtual));
            var MethodAbstract         = context.GetTypeDefinitionData(typeof(MethodAbstract));
            var MethodVirtualOverride  = context.GetTypeDefinitionData(typeof(MethodVirtualOverride));
            var MethodAbstractOverride = context.GetTypeDefinitionData(typeof(MethodAbstractOverride));
            var MethodVirtualOverrideInternalConstructor  = context.GetTypeDefinitionData(typeof(MethodVirtualOverrideInternalConstructor));
            var MethodAbstractOverrideInternalConstructor = context.GetTypeDefinitionData(typeof(MethodAbstractOverrideInternalConstructor));
            var MethodVirtualNoOverride  = context.GetTypeDefinitionData(typeof(MethodVirtualNoOverride));
            var MethodAbstractNoOverride = context.GetTypeDefinitionData(typeof(MethodAbstractNoOverride));

            var breakingChanges = MetadataComparer.CompareTypes(MethodVirtualOverride, MethodVirtualNoOverride);

            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an override of a virtual member is removed.");

            breakingChanges = MetadataComparer.CompareTypes(MethodVirtualOverrideInternalConstructor, MethodVirtualNoOverride);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an override of a virtual member is removed and there are no externally visible constructors.");

            breakingChanges = MetadataComparer.CompareTypes(MethodAbstractOverride, MethodAbstractNoOverride);
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when an override of an abstract member is removed.");
            AssertX.Equal(BreakingChangeKind.RemovedOverrideOfAbstractMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(MethodAbstractOverride.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Null(breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Equal(MethodAbstractNoOverride, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(MethodAbstractOverrideInternalConstructor, MethodAbstractNoOverride);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an override of an abstract member is removed and there are no externally visible constructors.");
        }
示例#5
0
        public void PropertyDataMemberFlagsTest()
        {
            var t        = typeof(OverloadedMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            var eventData = (PropertyData)typeData.GetMember("PropertyInstance");

            AssertX.Equal(MemberFlags.None, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyStatic");
            AssertX.Equal(MemberFlags.Static, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceAbstract");
            AssertX.Equal(MemberFlags.Abstract, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceVirtual");
            AssertX.Equal(MemberFlags.Virtual, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceOverrideAbstract");
            AssertX.Equal(MemberFlags.Override, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceOverrideAbstractSealed");
            AssertX.Equal(MemberFlags.Override | MemberFlags.Sealed, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceOverrideAbstractAbstract");
            AssertX.Equal(MemberFlags.Override | MemberFlags.Abstract, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceOverrideVirtual");
            AssertX.Equal(MemberFlags.Override, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceOverrideVirtualSealed");
            AssertX.Equal(MemberFlags.Override | MemberFlags.Sealed, eventData.MemberFlags, "The Flags value of the member is wrong.");
            eventData = (PropertyData)typeData.GetMember("PropertyInstanceOverrideVirtualAbstract");
            AssertX.Equal(MemberFlags.Override | MemberFlags.Abstract, eventData.MemberFlags, "The Flags value of the member is wrong.");
        }
示例#6
0
        public void IndexerDataMemberFlagsTest()
        {
            var t        = typeof(OverloadedMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            var members = typeData.GetMembers("Item");

            AssertX.Equal(9, members.Count, "Incorrect number of indexers");

            var indexerData = (IndexerData)members[0];

            AssertX.Equal(MemberFlags.None, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[1];
            AssertX.Equal(MemberFlags.Abstract, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[2];
            AssertX.Equal(MemberFlags.Virtual, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[3];
            AssertX.Equal(MemberFlags.Override, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[4];
            AssertX.Equal(MemberFlags.Override | MemberFlags.Sealed, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[5];
            AssertX.Equal(MemberFlags.Override | MemberFlags.Abstract, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[6];
            AssertX.Equal(MemberFlags.Override, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[7];
            AssertX.Equal(MemberFlags.Override | MemberFlags.Sealed, indexerData.MemberFlags, "The Flags value of the member is wrong.");
            indexerData = (IndexerData)members[8];
            AssertX.Equal(MemberFlags.Override | MemberFlags.Abstract, indexerData.MemberFlags, "The Flags value of the member is wrong.");
        }
        public void ConstructorTests()
        {
            var context                      = MetadataResolutionContext.CreateFromTypes(typeof(ChangedAccessibilityFromPublicToProtectedTests));
            var publicConstructor            = context.GetTypeDefinitionData(typeof(PublicConstructor));
            var protectedConstructor         = context.GetTypeDefinitionData(typeof(ProtectedConstructor));
            var protectedInternalConstructor = context.GetTypeDefinitionData(typeof(ProtectedInternalConstructor));

            var breakingChanges = MetadataComparer.CompareTypes(publicConstructor, protectedConstructor);

            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a constant is changed from public to protected");
            AssertX.Equal(BreakingChangeKind.ChangedAccessibilityFromPublicToProtected, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(context.GetTypeDefinitionData(typeof(PublicConstructor)).GetMembers(".ctor")[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(context.GetTypeDefinitionData(typeof(ProtectedConstructor)).GetMembers(".ctor")[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(publicConstructor, protectedInternalConstructor);
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a constructor is changed from public to protected internal");
            AssertX.Equal(BreakingChangeKind.ChangedAccessibilityFromPublicToProtected, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(context.GetTypeDefinitionData(typeof(PublicConstructor)).GetMembers(".ctor")[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(context.GetTypeDefinitionData(typeof(ProtectedInternalConstructor)).GetMembers(".ctor")[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(protectedConstructor, publicConstructor);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected to public");

            breakingChanges = MetadataComparer.CompareTypes(protectedConstructor, protectedInternalConstructor);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected to protected internal");

            breakingChanges = MetadataComparer.CompareTypes(protectedInternalConstructor, publicConstructor);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected internal to public");

            breakingChanges = MetadataComparer.CompareTypes(protectedInternalConstructor, protectedConstructor);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected internal to protected");
        }
        public void OperatorDataAllOperatorsTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            Assert.NotNull(typeData.GetMember("op_Implicit"));
            Assert.NotNull(typeData.GetMember("op_Explicit"));
            Assert.NotNull(typeData.GetMember("op_Addition"));
            Assert.NotNull(typeData.GetMember("op_Subtraction"));
            Assert.NotNull(typeData.GetMember("op_Multiply"));
            Assert.NotNull(typeData.GetMember("op_Division"));
            Assert.NotNull(typeData.GetMember("op_Modulus"));
            Assert.NotNull(typeData.GetMember("op_ExclusiveOr"));
            Assert.NotNull(typeData.GetMember("op_BitwiseAnd"));
            Assert.NotNull(typeData.GetMember("op_BitwiseOr"));
            Assert.NotNull(typeData.GetMember("op_LeftShift"));
            Assert.NotNull(typeData.GetMember("op_RightShift"));
            Assert.NotNull(typeData.GetMember("op_Equality"));
            Assert.NotNull(typeData.GetMember("op_GreaterThan"));
            Assert.NotNull(typeData.GetMember("op_LessThan"));
            Assert.NotNull(typeData.GetMember("op_Inequality"));
            Assert.NotNull(typeData.GetMember("op_GreaterThanOrEqual"));
            Assert.NotNull(typeData.GetMember("op_LessThanOrEqual"));
            Assert.NotNull(typeData.GetMember("op_Decrement"));
            Assert.NotNull(typeData.GetMember("op_Increment"));
            Assert.NotNull(typeData.GetMember("op_UnaryNegation"));
            Assert.NotNull(typeData.GetMember("op_UnaryPlus"));
            Assert.NotNull(typeData.GetMember("op_OnesComplement"));
            Assert.NotNull(typeData.GetMember("op_LogicalNot"));
            Assert.NotNull(typeData.GetMember("op_True"));
            Assert.NotNull(typeData.GetMember("op_False"));
        }
        public void MethodTests()
        {
            var context          = MetadataResolutionContext.CreateFromTypes(typeof(AddedAbstractMemberTests));
            var MethodNonVirtual = context.GetTypeDefinitionData(typeof(MethodNonVirtual));
            var MethodVirtual    = context.GetTypeDefinitionData(typeof(MethodVirtual));
            var MethodAbstract   = context.GetTypeDefinitionData(typeof(MethodAbstract));

            var breakingChanges = MetadataComparer.CompareTypes(MethodVirtual, MethodNonVirtual);

            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a virtual member changes to non-virtual.");
            AssertX.Equal(BreakingChangeKind.ChangedMemberToNonVirtual, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(MethodVirtual.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(MethodNonVirtual.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(MethodAbstract, MethodNonVirtual);
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when an abstract member changes to non-virtual.");
            AssertX.Equal(BreakingChangeKind.ChangedMemberToNonVirtual, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(MethodAbstract.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(MethodNonVirtual.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(MethodNonVirtual, MethodVirtual);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a non-virtual member changes to virtual.");
        }
示例#10
0
        public void TypeDefinitionDataTests()
        {
            var context = MetadataResolutionContext.CreateFromTypes(typeof(object));

            Assert.Equal("object", context.GetTypeData <object>().DisplayName);
            Assert.Equal("System.Collections.Generic.IEnumerable<out T>", context.GetTypeData(typeof(IEnumerable <>)).DisplayName);
        }
示例#11
0
        public void TypeTests()
        {
            var context                    = MetadataResolutionContext.CreateFromTypes(typeof(ChangedAccessibilityFromPublicToProtectedTests));
            var derivedFromBase            = context.GetTypeDefinitionData(typeof(DerivedFromBase));
            var derivedFromSpecializedBase = context.GetTypeDefinitionData(typeof(DerivedFromSpecializedBase));
            var derivedFromOtherBase       = context.GetTypeDefinitionData(typeof(DerivedFromOtherBase));

            var breakingChanges = MetadataComparer.CompareTypes(derivedFromBase, derivedFromSpecializedBase);

            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the new type derives from a more specialized base class.");

            breakingChanges = MetadataComparer.CompareTypes(derivedFromBase, derivedFromOtherBase);
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the new type derives from a different base class.");
            AssertX.Equal(BreakingChangeKind.IncompatibleClassHierarchy, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(derivedFromBase, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(derivedFromOtherBase, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(derivedFromSpecializedBase, derivedFromBase);
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the new type derives from a less specialized base class.");
            AssertX.Equal(BreakingChangeKind.IncompatibleClassHierarchy, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(derivedFromSpecializedBase, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(derivedFromBase, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(derivedFromSpecializedBase, derivedFromOtherBase);
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the new type derives from a different base class.");
            AssertX.Equal(BreakingChangeKind.IncompatibleClassHierarchy, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(derivedFromSpecializedBase, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(derivedFromOtherBase, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        private static void TestAssignability(Type a, Type b, MetadataResolutionContext context)
        {
            var aData = a.IsGenericParameter ? context.GetGenericTypeParameterData(a) : context.GetTypeData(a);
            var bData = b.IsGenericParameter ? context.GetGenericTypeParameterData(b) : context.GetTypeData(b);

            if (aData == null || bData == null)
            {
                AssertX.Inconclusive("Unable to get one of the types");
            }

            if (a.IsImplicitlyAssignableFrom(b))
            {
                Assert.True(aData.IsAssignableFromNew(bData), string.Format("The type should be assignable: {0} <- {1}", aData.Name, bData.Name));
            }
            else
            {
                Assert.False(aData.IsAssignableFromNew(bData), string.Format("The type should not be assignable: {0} <- {1}", aData.Name, bData.Name));
            }

            if (b.IsImplicitlyAssignableFrom(a))
            {
                Assert.True(bData.IsAssignableFromNew(aData), string.Format("The type should be assignable: {0} <- {1}", bData.Name, aData.Name));
            }
            else
            {
                Assert.False(bData.IsAssignableFromNew(aData), string.Format("The type should not be assignable: {0} <- {1}", bData.Name, aData.Name));
            }
        }
示例#13
0
        public void GenericTypeParameterDataContraintsTest()
        {
            var t       = typeof(TestClassDefinition <, , , ,>);
            var context = MetadataResolutionContext.CreateFromTypes(t);
            var testClassDefinitionData     = context.GetTypeDefinitionData(t);
            var equatableInterfaceData      = context.GetConstructedGenericTypeData <IEquatable <TestClassDefinition> >();
            var testInterfaceDefinitionData = context.GetTypeDefinitionData <TestInterfaceDefinition>();
            var valueTypeData = context.GetTypeDefinitionData <ValueType>();

            var p1 = testClassDefinitionData.GenericParameters[0];

            AssertX.Equal(0, p1.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");

            var p2 = testClassDefinitionData.GenericParameters[1];

            AssertX.Equal(2, p2.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");
            // Note: these may need to be reversed
            AssertX.Equal(equatableInterfaceData, p2.Constraints[0], "The reported type is not correct.");
            AssertX.Equal(testInterfaceDefinitionData, p2.Constraints[1], "The reported type is not correct.");

            var p3 = testClassDefinitionData.GenericParameters[2];

            AssertX.Equal(0, p3.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");

            var p4 = testClassDefinitionData.GenericParameters[3];

            AssertX.Equal(0, p4.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");

            var p5 = testClassDefinitionData.GenericParameters[4];

            AssertX.Equal(0, p5.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");
        }
        public void TypeTests()
        {
            var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedClassToStaticTests));
            var Class   = context.GetTypeDefinitionData(typeof(Class));
            var ClassWithInternalConstructor  = context.GetTypeDefinitionData(typeof(ClassWithInternalConstructor));
            var ClassWithProtectedConstructor = context.GetTypeDefinitionData(typeof(ClassWithProtectedConstructor));
            var StaticClass = context.GetTypeDefinitionData(typeof(StaticClass));

            var breakingChanges = MetadataComparer.CompareTypes(Class, StaticClass).Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedClassToStatic).ToList();

            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a class is made static.");
            AssertX.Equal(BreakingChangeKind.ChangedClassToStatic, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(Class, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(StaticClass, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(ClassWithInternalConstructor, StaticClass);
            AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a class with no public constructors is made abstract.");

            breakingChanges = MetadataComparer.CompareTypes(ClassWithProtectedConstructor, StaticClass).Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedClassToStatic).ToList();
            AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a class is made static.");
            AssertX.Equal(BreakingChangeKind.ChangedClassToStatic, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            AssertX.Equal(ClassWithProtectedConstructor, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            AssertX.Equal(StaticClass, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        public void CustomConstructionTest()
        {
            var context   = MetadataResolutionContext.CreateFromTypes(typeof(ConstructedGenericTypeDataTests));
            var type      = context.GetTypeDefinitionData(typeof(List <>));
            var addMethod = type.GetMethod("Add");

            Assert.Equal("T", addMethod.Parameters[0].Type.Name);

            var constructedType = type.GetConstructedGenericTypeData(new[] { context.GetTypeData <TestTypeArgument>() });

            addMethod = constructedType.GetMethod("Add");
            Assert.Equal("TestTypeArgument", addMethod.Parameters[0].Type.Name);


            type            = context.GetTypeDefinitionData(typeof(TestGenericTypeDefinition <>));
            constructedType = type.GetConstructedGenericTypeData(new[] { context.GetTypeData <TestTypeArgument>() });

            var constructor = (ConstructorData)constructedType.GetMember(".ctor");

            Assert.Equal("TestTypeArgument?", constructor.Parameters[0].Type.GetDisplayName(fullyQualify: false));
            var _event = (EventData)constructedType.GetMember("Event");

            Assert.Equal("EventHandler<TestTypeArgument>", _event.Type.GetDisplayName(fullyQualify: false));
            var field = (FieldData)constructedType.GetMember("Field");

            Assert.Equal("TestTypeArgument[]", field.Type.GetDisplayName(fullyQualify: false));
            var indexer = (IndexerData)constructedType.GetMember("Item");

            Assert.Equal("IList<TestTypeArgument>", indexer.Type.GetDisplayName(fullyQualify: false));
            Assert.Equal("TestTypeArgument[]", indexer.Parameters[0].Type.GetDisplayName(fullyQualify: false));
            var method = (MethodData)constructedType.GetMember("Method");

            Assert.Equal("TestTypeArgument?", method.Type.GetDisplayName(fullyQualify: false));
            Assert.Equal("TestTypeArgument", method.Parameters[0].Type.GetDisplayName(fullyQualify: false));
            Assert.Equal("U", method.Parameters[1].Type.GetDisplayName(fullyQualify: false));
            Assert.Equal("Dictionary<TestTypeArgument[], U[]>", method.Parameters[2].Type.GetDisplayName(fullyQualify: false));
            var _operator = (OperatorData)constructedType.GetMember("op_Addition");

            Assert.Equal("KeyValuePair<TestTypeArgument, object>", _operator.Type.GetDisplayName(fullyQualify: false));
            Assert.Equal("TestGenericTypeDefinition<TestTypeArgument>", _operator.Parameters[0].Type.GetDisplayName(fullyQualify: false));
            Assert.Equal("TestTypeArgument", _operator.Parameters[1].Type.GetDisplayName(fullyQualify: false));
            var property = (PropertyData)constructedType.GetMember("Property");

            Assert.Equal("IComparer<TestTypeArgument>", property.Type.GetDisplayName(fullyQualify: false));
            var nestedType = (ConstructedGenericTypeData)constructedType.GetMember("NestedType`1");

            Assert.Null(nestedType);

            type            = context.GetTypeDefinitionData(typeof(TestGenericTypeDefinition <> .NestedType <>));
            constructedType = type.GetConstructedGenericTypeData(new[] { context.GetTypeData <TestTypeArgument>(), context.GetTypeData <double>() });
            Assert.Equal("NestedType<double>", constructedType.GetDisplayName(fullyQualify: false));
            Assert.Equal("BreakingChangesDetector.UnitTests.MetadataTypesTests.ConstructedGenericTypeDataTests.TestGenericTypeDefinition<TestTypeArgument>.NestedType<double>", constructedType.GetDisplayName());
            Assert.Equal("Tuple<int, TestTypeArgument[], double>", constructedType.BaseType.GetDisplayName(fullyQualify: false));

            type            = context.GetTypeDefinitionData(typeof(TestGenericTypeDefinition <> .NestedType <> .FurtherNestedType <>));
            constructedType = type.GetConstructedGenericTypeData(new[] { context.GetTypeData <int>(), context.GetTypeData <TestTypeArgument>(), context.GetTypeData <double>() });
            Assert.Equal("FurtherNestedType<double>", constructedType.GetDisplayName(fullyQualify: false));
            Assert.Equal("BreakingChangesDetector.UnitTests.MetadataTypesTests.ConstructedGenericTypeDataTests.TestGenericTypeDefinition<int>.NestedType<TestTypeArgument>.FurtherNestedType<double>", constructedType.GetDisplayName());
            Assert.Equal("Dictionary<int, Tuple<TestTypeArgument, double>>", constructedType.BaseType.GetDisplayName(fullyQualify: false));
        }
示例#16
0
        public void GenericTypeParameterDataTests()
        {
            var context = MetadataResolutionContext.CreateFromTypes(typeof(object));

            Assert.Equal("T", context.GetTypeDefinitionData(typeof(IEnumerable <>)).GenericParameters[0].DisplayName);
            Assert.Equal("TKey", context.GetTypeDefinitionData(typeof(Dictionary <,>)).GenericParameters[0].DisplayName);
            Assert.Equal("TValue", context.GetTypeDefinitionData(typeof(Dictionary <,>)).GenericParameters[1].DisplayName);
        }
示例#17
0
        public void TypeDefinitionDataNameTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            AssertX.Equal(t.Name, typeData.Name, "The Name is not assigned correctly.");
        }
        public void OnlyReferenceAndIdentityConversionsInVariancesTest()
        {
            var context = MetadataResolutionContext.CreateFromTypes(typeof(IEnumerable <object>));

            Assert.False(context.GetConstructedGenericTypeData <IEnumerable <object> >().IsAssignableFromNew(context.GetConstructedGenericTypeData <IEnumerable <int> >()));
            Assert.False(context.GetConstructedGenericTypeData <IEnumerable <int> >().IsAssignableFromNew(context.GetConstructedGenericTypeData <IEnumerable <byte> >()));
            Assert.False(context.GetConstructedGenericTypeData <IEnumerable <int?> >().IsAssignableFromNew(context.GetConstructedGenericTypeData <IEnumerable <int> >()));
        }
示例#19
0
        public void FieldDataAccessibilityTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            TestUtilities.VerifyAccessibility(typeData, "FieldInstance");
        }
示例#20
0
        public void NullableIntDefaultValueTests()
        {
            var context  = MetadataResolutionContext.CreateFromTypes(typeof(DefaultValueInfoTests));
            var typeData = context.GetTypeDefinitionData(typeof(MethodWithDefaultValues));
            var method   = typeData.GetMethod("MethodWithInts");

            Assert.Null(method.Parameters[0].DefaultValue);
            Assert.Equal(0, method.Parameters[1].DefaultValue);
        }
示例#21
0
        public void PropertyDataDeclaringTypeTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var member   = (PropertyData)typeData.GetMember("PropertyReadOnly");

            AssertX.Equal(typeData, member.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
示例#22
0
 public MethodSignature(MetadataResolutionContext context, IMethodSymbol methodSymbol)
 {
     _declaringTypeName  = methodSymbol.ContainingType.GetFullName();
     _typeParameterCount = methodSymbol.TypeParameters.Length;
     _methodName         = methodSymbol.Name;
     _parameters         = methodSymbol.Parameters
                           .Select(p => new ParameterKey(TypeKey.Create(context, p), p.RefKind))
                           .ToArray();
 }
示例#23
0
        public void FieldDataNameTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var field    = typeData.GetMember("FieldInstance");

            AssertX.Equal("FieldInstance", field.Name, "The Name of the member is incorrect.");
        }
示例#24
0
        public void FieldDataDeclaringTypeTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var field    = typeData.GetMember("FieldInstance");

            AssertX.Equal(typeData, field.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
        public void OperatorDataNameTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var method   = typeData.GetMember("op_Addition");

            AssertX.Equal("op_Addition", method.Name, "The Name of the member is incorrect.");
        }
        public void OperatorDataDeclaringTypeTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var method   = typeData.GetMember("op_Addition");

            AssertX.Equal(typeData, method.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
示例#27
0
        public void IndexerDataNameTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var indexer  = typeData.GetMembers("Item")[0];

            AssertX.Equal("Item", indexer.Name, "The Name of the member is incorrect.");
        }
        public void OperatorDataAccessibilityTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var member   = typeData.GetMember("op_Addition");

            AssertX.Equal(Accessibility.Public, member.Accessibility, "Incorrect Accessibility");
        }
        public void OperatorDataParametersTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var method   = (OperatorData)typeData.GetMember("op_Addition");

            AssertX.Equal(2, method.Parameters.Count, "The public method has the wrong number of parameters.");
        }
示例#30
0
        public void IndexerDataDeclaringTypeTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var indexer  = typeData.GetMembers("Item")[0];

            AssertX.Equal(typeData, indexer.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }