Exemple #1
0
        public void IndexerTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterTypeTests).Assembly);
            var IndexerWithIntParameter     = TypeDefinitionData.FromType(typeof(IndexerWithIntParameter));
            var IndexerWithStringParameter  = TypeDefinitionData.FromType(typeof(IndexerWithStringParameter));
            var IndexerWithDynamicParameter = TypeDefinitionData.FromType(typeof(IndexerWithDynamicParameter));

            var breakingChanges = MetadataComparer.CompareTypes(IndexerWithIntParameter, IndexerWithStringParameter);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithIntParameter.GetMember("Item")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithStringParameter.GetMember("Item")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(IndexerWithStringParameter.GetMember("Item"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithStringParameter, IndexerWithIntParameter);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithStringParameter.GetMember("Item")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithIntParameter.GetMember("Item")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(IndexerWithIntParameter.GetMember("Item"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithIntParameter, IndexerWithDynamicParameter);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Parameter type changes to dynamic.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithDynamicParameter, IndexerWithIntParameter);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the Parameter type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithDynamicParameter.GetMember("Item")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithIntParameter.GetMember("Item")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(IndexerWithIntParameter.GetMember("Item"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithStringParameter, IndexerWithDynamicParameter);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Parameter type changes to dynamic.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithDynamicParameter, IndexerWithStringParameter);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the Parameter type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithDynamicParameter.GetMember("Item")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)IndexerWithStringParameter.GetMember("Item")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(IndexerWithStringParameter.GetMember("Item"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        public void IndexerTests()
        {
            var assembly                 = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly);
            var IndexerWithIntReturn     = TypeDefinitionData.FromType(typeof(IndexerWithIntReturn));
            var IndexerWithStringReturn  = TypeDefinitionData.FromType(typeof(IndexerWithStringReturn));
            var IndexerWithDynamicReturn = TypeDefinitionData.FromType(typeof(IndexerWithDynamicReturn));

            var breakingChanges = MetadataComparer.CompareTypes(IndexerWithIntReturn, IndexerWithStringReturn);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the Return type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(IndexerWithIntReturn.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(IndexerWithStringReturn.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithStringReturn, IndexerWithIntReturn);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the Return type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(IndexerWithStringReturn.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(IndexerWithIntReturn.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithIntReturn, IndexerWithDynamicReturn);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes to dynamic.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithDynamicReturn, IndexerWithIntReturn);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the Return type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(IndexerWithDynamicReturn.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(IndexerWithIntReturn.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithStringReturn, IndexerWithDynamicReturn);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes to dynamic.");

            breakingChanges = MetadataComparer.CompareTypes(IndexerWithDynamicReturn, IndexerWithStringReturn);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the Return type changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(IndexerWithDynamicReturn.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(IndexerWithStringReturn.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        public void TypeTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly);
            var InterfaceImplementingNothing                = TypeDefinitionData.FromType(typeof(InterfaceImplementingNothing));
            var InterfaceImplementingBase                   = TypeDefinitionData.FromType(typeof(InterfaceImplementingBase));
            var InterfaceImplementingDerived                = TypeDefinitionData.FromType(typeof(InterfaceImplementingDerived));
            var InterfaceImplementingDerivedAndBase         = TypeDefinitionData.FromType(typeof(InterfaceImplementingDerivedAndBase));
            var InterfaceImplementingInterfaceWithNoMembers = TypeDefinitionData.FromType(typeof(InterfaceImplementingInterfaceWithNoMembers));

            var breakingChanges = MetadataComparer.CompareTypes(InterfaceImplementingNothing, InterfaceImplementingBase);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an interface is added.");
            Assert.AreEqual(BreakingChangeKind.AddedBaseInterface, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(InterfaceImplementingNothing, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(InterfaceImplementingBase, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(BaseInterfaceWithMembers)), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(InterfaceImplementingNothing, InterfaceImplementingDerived);
            Assert.AreEqual(2, breakingChanges.Count, "There should be breaking changes when an interfaces are added.");
            // These might need to be reversed
            Assert.AreEqual(BreakingChangeKind.AddedBaseInterface, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(InterfaceImplementingNothing, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(InterfaceImplementingDerived, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(DerivedInterfaceWithMembers)), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
            Assert.AreEqual(BreakingChangeKind.AddedBaseInterface, breakingChanges[1].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(InterfaceImplementingNothing, breakingChanges[1].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(InterfaceImplementingDerived, breakingChanges[1].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(BaseInterfaceWithMembers)), breakingChanges[1].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(InterfaceImplementingBase, InterfaceImplementingDerived);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an interface is added.");
            Assert.AreEqual(BreakingChangeKind.AddedBaseInterface, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(InterfaceImplementingBase, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(InterfaceImplementingDerived, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(DerivedInterfaceWithMembers)), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(InterfaceImplementingDerived, InterfaceImplementingDerivedAndBase);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an interface already implemented is added.");

            breakingChanges = MetadataComparer.CompareTypes(InterfaceImplementingNothing, InterfaceImplementingInterfaceWithNoMembers);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an interface is added but contains no members.");
        }
        public void IndexerDataSetMethodAccessibilityTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var assembly = AssemblyData.FromAssembly(t.Assembly);
            var typeData = TypeDefinitionData.FromType(t);

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

            var readOnlyIndexer = (IndexerData)members[0];

            Assert.AreEqual(null, readOnlyIndexer.SetMethodAccessibility, "The SetMethodAccessibility of the read only property is incorrect.");

            var writeOnlyIndexer = (IndexerData)members[1];

            Assert.AreEqual(MemberAccessibility.Public, writeOnlyIndexer.SetMethodAccessibility, "The SetMethodAccessibility of the write only property is incorrect.");

            var readWriteIndexer = (IndexerData)members[2];

            Assert.AreEqual(MemberAccessibility.Protected, readWriteIndexer.SetMethodAccessibility, "The SetMethodAccessibility of the read write property is incorrect.");
        }
        public void MethodTests()
        {
            var assembly           = AssemblyData.FromAssembly(typeof(ChangedParameterDefaultValueTests).Assembly);
            var MethodWithDefault0 = TypeDefinitionData.FromType(typeof(MethodWithDefault0));
            var MethodWithDefault1 = TypeDefinitionData.FromType(typeof(MethodWithDefault1));

            var breakingChanges = MetadataComparer.CompareTypes(MethodWithDefault0, MethodWithDefault1);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterDefaultValue, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(MethodWithDefault0.GetMethod("Method").Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(MethodWithDefault1.GetMethod("Method").Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(MethodWithDefault1.GetMethod("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(MethodWithDefault1, MethodWithDefault0);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterDefaultValue, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(MethodWithDefault1.GetMethod("Method").Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(MethodWithDefault0.GetMethod("Method").Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(MethodWithDefault0.GetMethod("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        public void TypeTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterNameTests).Assembly);
            var delegateWithOldParameterName = TypeDefinitionData.FromType(typeof(DelegateWithOldParameterName));
            var delegateWithNewParameterName = TypeDefinitionData.FromType(typeof(DelegateWithNewParameterName));

            var breakingChanges = MetadataComparer.CompareTypes(delegateWithOldParameterName, delegateWithNewParameterName);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter name changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterName, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(delegateWithOldParameterName.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(delegateWithNewParameterName.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(delegateWithNewParameterName, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(delegateWithNewParameterName, delegateWithOldParameterName);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter name changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterName, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(delegateWithNewParameterName.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(delegateWithOldParameterName.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(delegateWithOldParameterName, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        public void MethodTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterNameTests).Assembly);
            var methodWithOldParameterName = TypeDefinitionData.FromType(typeof(MethodWithOldParameterName));
            var methodWithNewParameterName = TypeDefinitionData.FromType(typeof(MethodWithNewParameterName));

            var breakingChanges = MetadataComparer.CompareTypes(methodWithOldParameterName, methodWithNewParameterName);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter name changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterName, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithOldParameterName.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithNewParameterName.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(methodWithNewParameterName.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNewParameterName, methodWithOldParameterName);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter name changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterName, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithNewParameterName.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithOldParameterName.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(methodWithOldParameterName.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
Exemple #8
0
        public void MethodTests()
        {
            var assembly       = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly);
            var MethodInstance = TypeDefinitionData.FromType(typeof(MethodInstance));
            var MethodStatic   = TypeDefinitionData.FromType(typeof(MethodStatic));

            var breakingChanges = MetadataComparer.CompareTypes(MethodInstance, MethodStatic);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an instance member changes to static.");
            Assert.AreEqual(BreakingChangeKind.ChangedStaticOrInstanceStatus, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(MethodInstance.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(MethodStatic.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(MethodStatic, MethodInstance);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a static member changes to instance.");
            Assert.AreEqual(BreakingChangeKind.ChangedStaticOrInstanceStatus, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(MethodStatic.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(MethodInstance.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
Exemple #9
0
        public void TypeDefinitionDataMembersInClassTest()
        {
            var t        = typeof(TestClassDefinition);
            var assembly = AssemblyData.FromAssembly(t.Assembly);
            var typeData = TypeDefinitionData.FromType(t);

            Assert.IsNotNull(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");

            Assert.AreEqual(3, members.Count, "Incorrect number of constructors returned.");
            Assert.AreEqual(0, ((ConstructorData)members[0]).Parameters.Count, "The public constructor should have been returned.");
            Assert.AreEqual(2, ((ConstructorData)members[1]).Parameters.Count, "The protected constructor should have been returned.");
            Assert.AreEqual(3, ((ConstructorData)members[2]).Parameters.Count, "The protected internal constructor should have been returned.");

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

            members = typeData.GetMembers("Item");
            Assert.AreEqual(3, members.Count, "Incorrect number of indexers returned.");
            Assert.AreEqual(1, ((IndexerData)members[0]).Parameters.Count, "The public indexer should have been returned.");
            Assert.AreEqual(3, ((IndexerData)members[1]).Parameters.Count, "The protected indexer should have been returned.");
            Assert.AreEqual(4, ((IndexerData)members[2]).Parameters.Count, "The protected internal indexer should have been returned.");

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

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

            Assert.IsNotNull(member, "OperatorData instances should be returned.");

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

            TestUtilities.VerifyMember <TypeDefinitionData>(typeData, "NestedStruct");
        }
        public void TypeTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly);
            var interfaceWithNoMembers = TypeDefinitionData.FromType(typeof(InterfaceWithNoMembers));
            var interfaceWithEvent     = TypeDefinitionData.FromType(typeof(InterfaceWithEvent));
            var interfaceWithIndexer   = TypeDefinitionData.FromType(typeof(InterfaceWithIndexer));
            var interfaceWithMethod    = TypeDefinitionData.FromType(typeof(InterfaceWithMethod));
            var interfaceWithProperty  = TypeDefinitionData.FromType(typeof(InterfaceWithProperty));

            var breakingChanges = MetadataComparer.CompareTypes(interfaceWithNoMembers, interfaceWithEvent);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an interface member is added.");
            Assert.AreEqual(BreakingChangeKind.AddedInterfaceMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.IsNull(breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(interfaceWithEvent.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(interfaceWithNoMembers, interfaceWithIndexer);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an interface member is added.");
            Assert.AreEqual(BreakingChangeKind.AddedInterfaceMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.IsNull(breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(interfaceWithIndexer.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(interfaceWithNoMembers, interfaceWithMethod);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an interface member is added.");
            Assert.AreEqual(BreakingChangeKind.AddedInterfaceMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.IsNull(breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(interfaceWithMethod.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(interfaceWithNoMembers, interfaceWithProperty);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an interface member is added.");
            Assert.AreEqual(BreakingChangeKind.AddedInterfaceMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.IsNull(breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(interfaceWithProperty.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
Exemple #11
0
        public void GenericTypeParameterDataGenericParameterAttributesTest()
        {
            var t        = typeof(TestClassDefinition <, , , ,>);
            var assembly = AssemblyData.FromAssembly(t.Assembly);

            var typeData = TypeDefinitionData.FromType(t);

            var p1 = typeData.GenericParameters[0];

            Assert.AreEqual(GenericParameterAttributes.None, p1.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            var p2 = typeData.GenericParameters[1];

            Assert.AreEqual(GenericParameterAttributes.None, p2.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            var p3 = typeData.GenericParameters[2];

            Assert.AreEqual(GenericParameterAttributes.ReferenceTypeConstraint, p3.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            var p4 = typeData.GenericParameters[3];

            Assert.AreEqual(GenericParameterAttributes.NotNullableValueTypeConstraint | GenericParameterAttributes.DefaultConstructorConstraint, p4.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            var p5 = typeData.GenericParameters[4];

            Assert.AreEqual(GenericParameterAttributes.DefaultConstructorConstraint, p5.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            typeData = TypeDefinitionData.FromType(typeof(TestInterfaceDefinition <, ,>));

            p1 = typeData.GenericParameters[0];
            Assert.AreEqual(GenericParameterAttributes.None, p1.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            p2 = typeData.GenericParameters[1];
            Assert.AreEqual(GenericParameterAttributes.Contravariant, p2.GenericParameterAttributes, "The number of generic parameters is incorrect.");

            p3 = typeData.GenericParameters[2];
            Assert.AreEqual(GenericParameterAttributes.Covariant, p3.GenericParameterAttributes, "The number of generic parameters is incorrect.");
        }
        public void PropertyTests()
        {
            var assembly                = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly);
            var PropertyReadOnly        = TypeDefinitionData.FromType(typeof(PropertyReadOnly));
            var PropertyReadOnlyPublic  = TypeDefinitionData.FromType(typeof(PropertyReadOnlyPublic));
            var PropertyReadWrite       = TypeDefinitionData.FromType(typeof(PropertyReadWrite));
            var PropertyWriteOnly       = TypeDefinitionData.FromType(typeof(PropertyWriteOnly));
            var PropertyWriteOnlyPublic = TypeDefinitionData.FromType(typeof(PropertyWriteOnlyPublic));

            var breakingChanges = MetadataComparer.CompareTypes(PropertyReadWrite, PropertyReadOnly);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when changing a read/write Property to read-only.");
            Assert.AreEqual(BreakingChangeKind.RemovedPropertyAccessors, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(PropertyReadWrite.GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(PropertyReadOnly.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(PropertyReadWrite, PropertyReadOnlyPublic);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when changing a read/write Property to read-only.");
            Assert.AreEqual(BreakingChangeKind.RemovedPropertyAccessors, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(PropertyReadWrite.GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(PropertyReadOnlyPublic.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(PropertyReadWrite, PropertyWriteOnly);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when changing a read/write Property to write-only.");
            Assert.AreEqual(BreakingChangeKind.RemovedPropertyAccessors, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(PropertyReadWrite.GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(PropertyWriteOnly.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(PropertyReadWrite, PropertyWriteOnlyPublic);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when changing a read/write Property to write-only.");
            Assert.AreEqual(BreakingChangeKind.RemovedPropertyAccessors, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(PropertyReadWrite.GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(PropertyWriteOnlyPublic.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
Exemple #13
0
        public void TypeDefinitionDataBaseTypeTest()
        {
            var t        = typeof(TestClassDefinition);
            var assembly = AssemblyData.FromAssembly(t.Assembly);
            var testClassDefinitionData     = TypeDefinitionData.FromType(t);
            var testClassDefinitionBaseData = TypeDefinitionData.FromType(typeof(TestClassDefinitionBase));
            var marshalByRefObjectData      = TypeDefinitionData.FromType <MarshalByRefObject>();
            var objectData = TypeDefinitionData.FromType <Object>();

            DeclaringTypeData current = testClassDefinitionData;

            Assert.AreEqual(testClassDefinitionBaseData, current.BaseType, "The base type of " + current.Name + "is incorrect.");
            current = current.BaseType;
            Assert.AreEqual(marshalByRefObjectData, current.BaseType, "The base type of " + current.Name + "is incorrect.");
            current = current.BaseType;
            Assert.AreEqual(objectData, current.BaseType, "The base type of " + current.Name + "is incorrect.");
            current = current.BaseType;
            Assert.IsNull(current.BaseType, "The base type of " + current.Name + "is incorrect.");

            var testEnumDefinitionData = TypeDefinitionData.FromType(typeof(TestEnumDefinition));
            var intData       = TypeDefinitionData.FromType <int>();
            var valueTypeData = TypeDefinitionData.FromType <ValueType>();

            current = testEnumDefinitionData;
            Assert.AreEqual(intData, current.BaseType, "The base type of " + current.Name + "is incorrect.");
            current = current.BaseType;
            Assert.AreEqual(valueTypeData, current.BaseType, "The base type of " + current.Name + "is incorrect.");
            current = current.BaseType;
            Assert.AreEqual(objectData, current.BaseType, "The base type of " + current.Name + "is incorrect.");
            current = current.BaseType;
            Assert.IsNull(current.BaseType, "The base type of " + current.Name + "is incorrect.");

            var testInterfaceDefinitionData = TypeDefinitionData.FromType(typeof(TestInterfaceDefinition));

            current = testInterfaceDefinitionData;
            Assert.AreEqual(null, current.BaseType, "The base type of " + current.Name + "is incorrect.");
        }
Exemple #14
0
        public void ModiferRestrictionsTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterTypeTests).Assembly);
            var methodWithRefParameterBase    = TypeDefinitionData.FromType(typeof(MethodWithRefParameterBase));
            var methodWithRefParameterDerived = TypeDefinitionData.FromType(typeof(MethodWithRefParameterDerived));
            var methodWithOutParameterBase    = TypeDefinitionData.FromType(typeof(MethodWithOutParameterBase));
            var methodWithOutParameterDerived = TypeDefinitionData.FromType(typeof(MethodWithOutParameterDerived));

            var breakingChanges = MetadataComparer.CompareTypes(methodWithRefParameterBase, methodWithRefParameterDerived);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes at all on a ref parameter.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithRefParameterBase.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithRefParameterDerived.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(methodWithRefParameterDerived.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithRefParameterDerived, methodWithRefParameterBase);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes at all on a ref parameter.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithRefParameterDerived.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithRefParameterBase.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(methodWithRefParameterBase.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithOutParameterBase, methodWithOutParameterDerived);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes at all on an out parameter.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithOutParameterBase.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithOutParameterDerived.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(methodWithOutParameterDerived.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithOutParameterDerived, methodWithOutParameterBase);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes at all on an out parameter.");
            Assert.AreEqual(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithOutParameterDerived.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((IParameterizedItem)methodWithOutParameterBase.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(methodWithOutParameterBase.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
Exemple #15
0
        public void TypeTests()
        {
            var assembly      = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly);
            var unsealedClass = TypeDefinitionData.FromType(typeof(UnsealedClass));
            var unsealedClassWithInternalConstructor = TypeDefinitionData.FromType(typeof(UnsealedClassWithInternalConstructor));
            var sealedClass = TypeDefinitionData.FromType(typeof(SealedClass));

            var breakingChanges = MetadataComparer.CompareTypes(unsealedClass, sealedClass);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a type is sealed.");
            Assert.AreEqual(BreakingChangeKind.SealedClass, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(unsealedClass, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(sealedClass, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(unsealedClassWithInternalConstructor, sealedClass);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a type is sealed which couldn't be derived externally.");

            breakingChanges = MetadataComparer.CompareTypes(sealedClass, unsealedClass);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when unsealing a class.");

            breakingChanges = MetadataComparer.CompareTypes(sealedClass, unsealedClassWithInternalConstructor);
            Assert.AreEqual(0, breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.SealedClass).Count(), "There should be no breaking changes when unsealing a class.");
        }
        public void TypeTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly);
            var classImplementingBase    = TypeDefinitionData.FromType(typeof(ClassImplementingBase));
            var classImplementingDerived = TypeDefinitionData.FromType(typeof(ClassImplementingDerived));
            var classImplementingNothing = TypeDefinitionData.FromType(typeof(ClassImplementingNothing));

            var breakingChanges = MetadataComparer.CompareTypes(classImplementingBase, classImplementingDerived);

            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the new type implements a more specialized interface.");

            breakingChanges = MetadataComparer.CompareTypes(classImplementingBase, classImplementingNothing);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the new type does not implement the same interface.");
            Assert.AreEqual(BreakingChangeKind.RemovedImplementedInterface, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(classImplementingBase, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(classImplementingNothing, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(BaseInterface)), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(classImplementingDerived, classImplementingBase);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the new type implements a less specialized interface.");
            Assert.AreEqual(BreakingChangeKind.RemovedImplementedInterface, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(classImplementingDerived, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(classImplementingBase, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(DerivedInterface)), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(classImplementingDerived, classImplementingNothing);
            Assert.AreEqual(2, breakingChanges.Count, "There should be one breaking change when the new type does not implement the same interface.");
            Assert.AreEqual(BreakingChangeKind.RemovedImplementedInterface, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(classImplementingDerived, breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(classImplementingNothing, breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(DerivedInterface)), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
            Assert.AreEqual(BreakingChangeKind.RemovedImplementedInterface, breakingChanges[1].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(classImplementingDerived, breakingChanges[1].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(classImplementingNothing, breakingChanges[1].NewItem, "The NewItem is incorrect.");
            Assert.AreEqual(TypeDefinitionData.FromType(typeof(BaseInterface)), breakingChanges[1].AssociatedData, "The AssociatedData is incorrect.");
        }
Exemple #17
0
        public void NestedTypeTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly);
            var nestedInterfaceWithNonVariantParam    = TypeDefinitionData.FromType(typeof(NestedInterfaceWithNonVariantParam));
            var nestedInterfaceWithCovariantParam     = TypeDefinitionData.FromType(typeof(NestedInterfaceWithCovariantParam));
            var nestedInterfaceWithContravariantParam = TypeDefinitionData.FromType(typeof(NestedInterfaceWithContravariantParam));

            var breakingChanges = MetadataComparer.CompareTypes(nestedInterfaceWithNonVariantParam, nestedInterfaceWithCovariantParam);

            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a type parameter changes from invariant to variant.");

            breakingChanges = MetadataComparer.CompareTypes(nestedInterfaceWithNonVariantParam, nestedInterfaceWithContravariantParam);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a type parameter changes from invariant to variant.");

            breakingChanges = MetadataComparer.CompareTypes(nestedInterfaceWithCovariantParam, nestedInterfaceWithNonVariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedInterfaceWithCovariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedInterfaceWithNonVariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(nestedInterfaceWithCovariantParam, nestedInterfaceWithContravariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedInterfaceWithCovariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedInterfaceWithContravariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(nestedInterfaceWithContravariantParam, nestedInterfaceWithNonVariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedInterfaceWithContravariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedInterfaceWithNonVariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(nestedInterfaceWithContravariantParam, nestedInterfaceWithCovariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedInterfaceWithContravariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedInterfaceWithCovariantParam.GetNestedType("Interface`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            var nestedDelegateWithNonVariantParam    = TypeDefinitionData.FromType(typeof(NestedDelegateWithNonVariantParam));
            var nestedDelegateWithCovariantParam     = TypeDefinitionData.FromType(typeof(NestedDelegateWithCovariantParam));
            var nestedDelegateWithContravariantParam = TypeDefinitionData.FromType(typeof(NestedDelegateWithContravariantParam));

            breakingChanges = MetadataComparer.CompareTypes(nestedDelegateWithNonVariantParam, nestedDelegateWithCovariantParam);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a type parameter changes from invariant to variant.");

            breakingChanges = MetadataComparer.CompareTypes(nestedDelegateWithNonVariantParam, nestedDelegateWithContravariantParam);
            Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a type parameter changes from invariant to variant.");

            breakingChanges = MetadataComparer.CompareTypes(nestedDelegateWithCovariantParam, nestedDelegateWithNonVariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedDelegateWithCovariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedDelegateWithNonVariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(nestedDelegateWithCovariantParam, nestedDelegateWithContravariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedDelegateWithCovariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedDelegateWithContravariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(nestedDelegateWithContravariantParam, nestedDelegateWithNonVariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedDelegateWithContravariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedDelegateWithNonVariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(nestedDelegateWithContravariantParam, nestedDelegateWithCovariantParam);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter variance changes.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterVariance, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(nestedDelegateWithContravariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(nestedDelegateWithCovariantParam.GetNestedType("Delegate`1").GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }
        public void MethodTests()
        {
            var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly);
            var methodWithNoConstraints              = TypeDefinitionData.FromType(typeof(MethodWithNoConstraints));
            var methodWithNewConstraint              = TypeDefinitionData.FromType(typeof(MethodWithNewConstraint));
            var methodWithStructConstraint           = TypeDefinitionData.FromType(typeof(MethodWithStructConstraint));
            var methodWithClassConstraint            = TypeDefinitionData.FromType(typeof(MethodWithClassConstraint));
            var methodWithClassNewConstraints        = TypeDefinitionData.FromType(typeof(MethodWithClassNewConstraints));
            var methodWithBaseInterfaceConstraint    = TypeDefinitionData.FromType(typeof(MethodWithBaseInterfaceConstraint));
            var methodWithDerivedInterfaceConstraint = TypeDefinitionData.FromType(typeof(MethodWithDerivedInterfaceConstraint));
            var methodWithBaseTypeContraint          = TypeDefinitionData.FromType(typeof(MethodWithBaseTypeContraint));

            var breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithNewConstraint);

            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNewConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithStructConstraint);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithStructConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithClassConstraint);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithClassConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithClassNewConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithClassNewConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithBaseInterfaceConstraint);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithBaseInterfaceConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithDerivedInterfaceConstraint);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithDerivedInterfaceConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithNoConstraints, methodWithBaseTypeContraint);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithBaseTypeContraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            // Do the same tests in reverse order
            breakingChanges = MetadataComparer.CompareTypes(methodWithNewConstraint, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNewConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithStructConstraint, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithStructConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithClassConstraint, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithClassConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithClassNewConstraints, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithClassNewConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithBaseInterfaceConstraint, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithBaseInterfaceConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithDerivedInterfaceConstraint, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithDerivedInterfaceConstraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");

            breakingChanges = MetadataComparer.CompareTypes(methodWithBaseTypeContraint, methodWithNoConstraints);
            Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when type parameter constraints change.");
            Assert.AreEqual(BreakingChangeKind.ChangedGenericTypeParameterConstraints, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect.");
            Assert.AreEqual(((MethodData)methodWithBaseTypeContraint.GetMember("Method")).GenericParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect.");
            Assert.AreEqual(((MethodData)methodWithNoConstraints.GetMember("Method")).GenericParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect.");
            Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect.");
        }