public void PropertyTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly); var publicProperty = TypeDefinitionData.FromType(typeof(PublicProperty)); var protectedProperty = TypeDefinitionData.FromType(typeof(ProtectedProperty)); var protectedInternalProperty = TypeDefinitionData.FromType(typeof(ProtectedInternalProperty)); var breakingChanges = MetadataComparer.CompareTypes(publicProperty, protectedProperty); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a constant is changed from public to protected"); Assert.AreEqual(BreakingChangeKind.ChangedAccessibilityFromPublicToProtected, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(PublicProperty)).GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(ProtectedProperty)).GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(publicProperty, protectedInternalProperty); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a property is changed from public to protected internal"); Assert.AreEqual(BreakingChangeKind.ChangedAccessibilityFromPublicToProtected, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(PublicProperty)).GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(ProtectedInternalProperty)).GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(protectedProperty, publicProperty); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a property is changed from protected to public"); breakingChanges = MetadataComparer.CompareTypes(protectedProperty, protectedInternalProperty); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a property is changed from protected to protected internal"); breakingChanges = MetadataComparer.CompareTypes(protectedInternalProperty, publicProperty); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a property is changed from protected internal to public"); breakingChanges = MetadataComparer.CompareTypes(protectedInternalProperty, protectedProperty); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a property is changed from protected internal to protected"); }
public void GenericParameterRenameTest() { var assembly = AssemblyData.FromAssembly(typeof(MiscellaneousTests).Assembly); var typeData1 = TypeDefinitionData.FromType(typeof(GenericParameter1 <>)); var typeData2 = TypeDefinitionData.FromType(typeof(GenericParameter2 <>)); var typeData3 = TypeDefinitionData.FromType(typeof(GenericParameter3 <,>)); var typeData4 = TypeDefinitionData.FromType(typeof(GenericParameter4 <,>)); var breakingChanges = MetadataComparer.CompareTypes(typeData1, typeData2); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes for renaming a class's generic type parameter."); breakingChanges = MetadataComparer.CompareTypes(typeData3, typeData4); Assert.AreEqual(1, breakingChanges.Count, "There should be a breaking changes for using a different generic type parameter position as a return type."); Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "There should be a breaking changes for using a different generic type parameter position as a return type."); typeData1 = TypeDefinitionData.FromType(typeof(GenericMethodParameter1)); typeData2 = TypeDefinitionData.FromType(typeof(GenericMethodParameter2)); typeData3 = TypeDefinitionData.FromType(typeof(GenericMethodParameter3)); typeData4 = TypeDefinitionData.FromType(typeof(GenericMethodParameter4)); breakingChanges = MetadataComparer.CompareTypes(typeData1, typeData2); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes for renaming a class's generic type parameter."); breakingChanges = MetadataComparer.CompareTypes(typeData3, typeData4); Assert.AreEqual(1, breakingChanges.Count, "There should be a breaking changes for using a different generic type parameter position as a return type."); Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "There should be a breaking changes for using a different generic type parameter position as a return type."); }
public void OperatorTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterNameTests).Assembly); var OperatorWithOldParameterName = TypeDefinitionData.FromType(typeof(OperatorWithOldParameterName)); var OperatorWithNewParameterName = TypeDefinitionData.FromType(typeof(OperatorWithNewParameterName)); var breakingChanges = MetadataComparer.CompareTypes(OperatorWithOldParameterName, OperatorWithNewParameterName); Assert.AreEqual(0, breakingChanges.Count, "There should be one breaking change when the parameter name changes."); }
public void OperatorTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterNameTests)); var OperatorWithOldParameterName = context.GetTypeDefinitionData(typeof(OperatorWithOldParameterName)); var OperatorWithNewParameterName = context.GetTypeDefinitionData(typeof(OperatorWithNewParameterName)); var breakingChanges = MetadataComparer.CompareTypes(OperatorWithOldParameterName, OperatorWithNewParameterName); AssertX.Equal(0, breakingChanges.Count, "There should be one breaking change when the parameter name changes."); }
public void EventTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(SealedMemberTests)); var EventVirtual = context.GetTypeDefinitionData(typeof(EventVirtual)); var EventAbstract = context.GetTypeDefinitionData(typeof(EventAbstract)); var EventVirtualOverride = context.GetTypeDefinitionData(typeof(EventVirtualOverride)); var EventAbstractOverride = context.GetTypeDefinitionData(typeof(EventAbstractOverride)); var EventVirtualNoOverride = context.GetTypeDefinitionData(typeof(EventVirtualNoOverride)); var EventAbstractNoOverride = context.GetTypeDefinitionData(typeof(EventAbstractNoOverride)); var EventVirtualSealedOverride = context.GetTypeDefinitionData(typeof(EventVirtualSealedOverride)); var EventAbstractSealedOverride = context.GetTypeDefinitionData(typeof(EventAbstractSealedOverride)); var EventVirtualSealedOverrideSealed = context.GetTypeDefinitionData(typeof(EventVirtualSealedOverrideSealed)); var EventAbstractSealedOverrideSealed = context.GetTypeDefinitionData(typeof(EventAbstractSealedOverrideSealed)); var breakingChanges = MetadataComparer.CompareTypes(EventVirtualOverride, EventVirtualSealedOverride); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); AssertX.Equal(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(EventVirtualOverride.GetMember("Event"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(EventVirtualSealedOverride.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(EventVirtualOverride, EventVirtualSealedOverrideSealed); AssertX.Equal(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); breakingChanges = MetadataComparer.CompareTypes(EventAbstractOverride, EventAbstractSealedOverride); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); AssertX.Equal(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(EventAbstractOverride.GetMember("Event"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(EventAbstractSealedOverride.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(EventAbstractOverride, EventAbstractSealedOverrideSealed); AssertX.Equal(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); breakingChanges = MetadataComparer.CompareTypes(EventVirtualNoOverride, EventVirtualSealedOverride); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); AssertX.Equal(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(EventVirtual.GetMember("Event"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(EventVirtualSealedOverride.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(EventVirtualNoOverride, EventVirtualSealedOverrideSealed); AssertX.Equal(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); breakingChanges = MetadataComparer.CompareTypes(EventAbstractNoOverride, EventAbstractSealedOverride); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); AssertX.Equal(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(EventAbstract.GetMember("Event"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(EventAbstractSealedOverride.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(EventAbstractNoOverride, EventAbstractSealedOverrideSealed); AssertX.Equal(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); }
public void IndexerTests() { var assembly = AssemblyData.FromAssembly(typeof(SealedMemberTests).Assembly); var IndexerVirtual = TypeDefinitionData.FromType(typeof(IndexerVirtual)); var IndexerAbstract = TypeDefinitionData.FromType(typeof(IndexerAbstract)); var IndexerVirtualOverride = TypeDefinitionData.FromType(typeof(IndexerVirtualOverride)); var IndexerAbstractOverride = TypeDefinitionData.FromType(typeof(IndexerAbstractOverride)); var IndexerVirtualNoOverride = TypeDefinitionData.FromType(typeof(IndexerVirtualNoOverride)); var IndexerAbstractNoOverride = TypeDefinitionData.FromType(typeof(IndexerAbstractNoOverride)); var IndexerVirtualSealedOverride = TypeDefinitionData.FromType(typeof(IndexerVirtualSealedOverride)); var IndexerAbstractSealedOverride = TypeDefinitionData.FromType(typeof(IndexerAbstractSealedOverride)); var IndexerVirtualSealedOverrideSealed = TypeDefinitionData.FromType(typeof(IndexerVirtualSealedOverrideSealed)); var IndexerAbstractSealedOverrideSealed = TypeDefinitionData.FromType(typeof(IndexerAbstractSealedOverrideSealed)); var breakingChanges = MetadataComparer.CompareTypes(IndexerVirtualOverride, IndexerVirtualSealedOverride); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); Assert.AreEqual(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerVirtualOverride.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(IndexerVirtualSealedOverride.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerVirtualOverride, IndexerVirtualSealedOverrideSealed); Assert.AreEqual(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstractOverride, IndexerAbstractSealedOverride); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); Assert.AreEqual(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerAbstractOverride.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(IndexerAbstractSealedOverride.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstractOverride, IndexerAbstractSealedOverrideSealed); Assert.AreEqual(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); breakingChanges = MetadataComparer.CompareTypes(IndexerVirtualNoOverride, IndexerVirtualSealedOverride); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); Assert.AreEqual(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerVirtual.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(IndexerVirtualSealedOverride.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerVirtualNoOverride, IndexerVirtualSealedOverrideSealed); Assert.AreEqual(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstractNoOverride, IndexerAbstractSealedOverride); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a sealed override is added to an unsealed class."); Assert.AreEqual(BreakingChangeKind.SealedMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerAbstract.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(IndexerAbstractSealedOverride.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstractNoOverride, IndexerAbstractSealedOverrideSealed); Assert.AreEqual(1, breakingChanges.Count, "There should be no breaking changes when a sealed override is added to a sealed class."); }
public void ReturnTypeCovarianceTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly); var methodWithReturnBase = TypeDefinitionData.FromType(typeof(MethodWithReturnBase)); var methodWithReturnDerived = TypeDefinitionData.FromType(typeof(MethodWithReturnDerived)); var breakingChanges = MetadataComparer.CompareTypes(methodWithReturnDerived, methodWithReturnBase); 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(methodWithReturnDerived.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(methodWithReturnBase.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(methodWithReturnBase, methodWithReturnDerived); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes to a base type."); // Read/write fields cannot change type at all because they can be used in out or ref parameters var FieldWithReturnBase = TypeDefinitionData.FromType(typeof(FieldWithReturnBase)); var FieldWithReturnDerived = TypeDefinitionData.FromType(typeof(FieldWithReturnDerived)); var FieldWithReadonlyReturnBase = TypeDefinitionData.FromType(typeof(FieldWithReadonlyReturnBase)); breakingChanges = MetadataComparer.CompareTypes(FieldWithReturnDerived, FieldWithReturnBase); 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(FieldWithReturnDerived.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithReturnBase.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithReturnBase, FieldWithReturnDerived); 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(FieldWithReturnBase.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithReturnDerived.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithReadonlyReturnBase, FieldWithReturnDerived); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the read-only field type changes to a base type."); var EventWithReturnBase = TypeDefinitionData.FromType(typeof(EventWithReturnBase)); var EventWithReturnDerived = TypeDefinitionData.FromType(typeof(EventWithReturnDerived)); breakingChanges = MetadataComparer.CompareTypes(EventWithReturnDerived, EventWithReturnBase); 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(EventWithReturnDerived.GetMember("Event"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(EventWithReturnBase.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(EventWithReturnBase, EventWithReturnDerived); 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(EventWithReturnBase.GetMember("Event"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(EventWithReturnDerived.GetMember("Event"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void FieldTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedMemberTypeTests)); var FieldWithIntReturn = context.GetTypeDefinitionData(typeof(FieldWithIntReturn)); var FieldWithStringReturn = context.GetTypeDefinitionData(typeof(FieldWithStringReturn)); var FieldWithDynamicReturn = context.GetTypeDefinitionData(typeof(FieldWithDynamicReturn)); var breakingChanges = MetadataComparer.CompareTypes(FieldWithIntReturn, FieldWithStringReturn); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Return type changes."); AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithStringReturn, FieldWithIntReturn); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Return type changes."); AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithIntReturn, FieldWithDynamicReturn); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Return type changes."); AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithDynamicReturn, FieldWithIntReturn); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Return type changes."); AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithStringReturn, FieldWithDynamicReturn); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Return type changes."); AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithDynamicReturn, FieldWithStringReturn); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Return type changes."); AssertX.Equal(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void ConstructorTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterModifierTests).Assembly); var ConstructorWithUnmodifiedParameter = TypeDefinitionData.FromType(typeof(ConstructorWithUnmodifiedParameter)); var ConstructorWithRefParameter = TypeDefinitionData.FromType(typeof(ConstructorWithRefParameter)); var ConstructorWithOutParameter = TypeDefinitionData.FromType(typeof(ConstructorWithOutParameter)); var breakingChanges = MetadataComparer.CompareTypes(ConstructorWithUnmodifiedParameter, ConstructorWithRefParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithUnmodifiedParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithRefParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(ConstructorWithRefParameter.GetMember(".ctor"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithRefParameter, ConstructorWithUnmodifiedParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithRefParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithUnmodifiedParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(ConstructorWithUnmodifiedParameter.GetMember(".ctor"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithUnmodifiedParameter, ConstructorWithOutParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithUnmodifiedParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithOutParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(ConstructorWithOutParameter.GetMember(".ctor"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithOutParameter, ConstructorWithUnmodifiedParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithOutParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithUnmodifiedParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(ConstructorWithUnmodifiedParameter.GetMember(".ctor"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithRefParameter, ConstructorWithOutParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithRefParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithOutParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(ConstructorWithOutParameter.GetMember(".ctor"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithOutParameter, ConstructorWithRefParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithOutParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(((IParameterizedItem)ConstructorWithRefParameter.GetMember(".ctor")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(ConstructorWithRefParameter.GetMember(".ctor"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void TypeTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterModifierTests).Assembly); var DelegateWithUnmodifiedParameter = TypeDefinitionData.FromType(typeof(DelegateWithUnmodifiedParameter)); var DelegateWithRefParameter = TypeDefinitionData.FromType(typeof(DelegateWithRefParameter)); var DelegateWithOutParameter = TypeDefinitionData.FromType(typeof(DelegateWithOutParameter)); var breakingChanges = MetadataComparer.CompareTypes(DelegateWithUnmodifiedParameter, DelegateWithRefParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(DelegateWithUnmodifiedParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(DelegateWithRefParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(DelegateWithRefParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithRefParameter, DelegateWithUnmodifiedParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(DelegateWithRefParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(DelegateWithUnmodifiedParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(DelegateWithUnmodifiedParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithUnmodifiedParameter, DelegateWithOutParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(DelegateWithUnmodifiedParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(DelegateWithOutParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(DelegateWithOutParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithOutParameter, DelegateWithUnmodifiedParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(DelegateWithOutParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(DelegateWithUnmodifiedParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(DelegateWithUnmodifiedParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithRefParameter, DelegateWithOutParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(DelegateWithRefParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(DelegateWithOutParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(DelegateWithOutParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithOutParameter, DelegateWithRefParameter); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(DelegateWithOutParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(DelegateWithRefParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(DelegateWithRefParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void MethodTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterModifierTests)); var MethodWithUnmodifiedParameter = context.GetTypeDefinitionData(typeof(MethodWithUnmodifiedParameter)); var MethodWithRefParameter = context.GetTypeDefinitionData(typeof(MethodWithRefParameter)); var MethodWithOutParameter = context.GetTypeDefinitionData(typeof(MethodWithOutParameter)); var breakingChanges = MetadataComparer.CompareTypes(MethodWithUnmodifiedParameter, MethodWithRefParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithUnmodifiedParameter.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithRefParameter.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(MethodWithRefParameter.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(MethodWithRefParameter, MethodWithUnmodifiedParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithRefParameter.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithUnmodifiedParameter.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(MethodWithUnmodifiedParameter.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(MethodWithUnmodifiedParameter, MethodWithOutParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithUnmodifiedParameter.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithOutParameter.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(MethodWithOutParameter.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(MethodWithOutParameter, MethodWithUnmodifiedParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithOutParameter.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithUnmodifiedParameter.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(MethodWithUnmodifiedParameter.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(MethodWithRefParameter, MethodWithOutParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithRefParameter.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithOutParameter.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(MethodWithOutParameter.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(MethodWithOutParameter, MethodWithRefParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithOutParameter.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)MethodWithRefParameter.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(MethodWithRefParameter.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void FieldTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly); var FieldWithIntReturn = TypeDefinitionData.FromType(typeof(FieldWithIntReturn)); var FieldWithStringReturn = TypeDefinitionData.FromType(typeof(FieldWithStringReturn)); var FieldWithDynamicReturn = TypeDefinitionData.FromType(typeof(FieldWithDynamicReturn)); var breakingChanges = MetadataComparer.CompareTypes(FieldWithIntReturn, FieldWithStringReturn); 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(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithStringReturn, FieldWithIntReturn); 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(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithIntReturn, FieldWithDynamicReturn); 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(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithDynamicReturn, FieldWithIntReturn); 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(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithIntReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithStringReturn, FieldWithDynamicReturn); 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(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(FieldWithDynamicReturn, FieldWithStringReturn); 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(FieldWithDynamicReturn.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldWithStringReturn.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void NestedTypeTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterModifierTests)); var NestedDelegateWithUnmodifiedParameter = context.GetTypeDefinitionData(typeof(NestedDelegateWithUnmodifiedParameter)); var NestedDelegateWithRefParameter = context.GetTypeDefinitionData(typeof(NestedDelegateWithRefParameter)); var NestedDelegateWithOutParameter = context.GetTypeDefinitionData(typeof(NestedDelegateWithOutParameter)); var breakingChanges = MetadataComparer.CompareTypes(NestedDelegateWithUnmodifiedParameter, NestedDelegateWithRefParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedDelegateWithUnmodifiedParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedDelegateWithRefParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(NestedDelegateWithRefParameter.GetNestedType("Delegate"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(NestedDelegateWithRefParameter, NestedDelegateWithUnmodifiedParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedDelegateWithRefParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedDelegateWithUnmodifiedParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(NestedDelegateWithUnmodifiedParameter.GetNestedType("Delegate"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(NestedDelegateWithUnmodifiedParameter, NestedDelegateWithOutParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedDelegateWithUnmodifiedParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedDelegateWithOutParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(NestedDelegateWithOutParameter.GetNestedType("Delegate"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(NestedDelegateWithOutParameter, NestedDelegateWithUnmodifiedParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedDelegateWithOutParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedDelegateWithUnmodifiedParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(NestedDelegateWithUnmodifiedParameter.GetNestedType("Delegate"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(NestedDelegateWithRefParameter, NestedDelegateWithOutParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedDelegateWithRefParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedDelegateWithOutParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(NestedDelegateWithOutParameter.GetNestedType("Delegate"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(NestedDelegateWithOutParameter, NestedDelegateWithRefParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter modifier changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedDelegateWithOutParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedDelegateWithRefParameter.GetNestedType("Delegate").DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(NestedDelegateWithRefParameter.GetNestedType("Delegate"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void OperatorTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly); var OperatorWithIntReturn = TypeDefinitionData.FromType(typeof(OperatorWithIntReturn)); var OperatorWithStringReturn = TypeDefinitionData.FromType(typeof(OperatorWithStringReturn)); var OperatorWithDynamicReturn = TypeDefinitionData.FromType(typeof(OperatorWithDynamicReturn)); var breakingChanges = MetadataComparer.CompareTypes(OperatorWithIntReturn, OperatorWithStringReturn); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedMemberType).ToList(); 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(OperatorWithIntReturn.GetMember("op_Addition"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(OperatorWithStringReturn.GetMember("op_Addition"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithStringReturn, OperatorWithIntReturn); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedMemberType).ToList(); 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(OperatorWithStringReturn.GetMember("op_Addition"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(OperatorWithIntReturn.GetMember("op_Addition"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithIntReturn, OperatorWithDynamicReturn); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedMemberType).ToList(); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes to dynamic."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithDynamicReturn, OperatorWithIntReturn); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedMemberType).ToList(); 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(OperatorWithDynamicReturn.GetMember("op_Addition"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(OperatorWithIntReturn.GetMember("op_Addition"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithStringReturn, OperatorWithDynamicReturn); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedMemberType).ToList(); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes to dynamic."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithDynamicReturn, OperatorWithStringReturn); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedMemberType).ToList(); 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(OperatorWithDynamicReturn.GetMember("op_Addition"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(OperatorWithStringReturn.GetMember("op_Addition"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void OperatorTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterTypeTests)); var OperatorWithIntParameter = context.GetTypeDefinitionData(typeof(OperatorWithIntParameter)); var OperatorWithStringParameter = context.GetTypeDefinitionData(typeof(OperatorWithStringParameter)); var OperatorWithDynamicParameter = context.GetTypeDefinitionData(typeof(OperatorWithDynamicParameter)); var breakingChanges = MetadataComparer.CompareTypes(OperatorWithIntParameter, OperatorWithStringParameter); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedParameterType).ToList(); AssertX.Equal(2, breakingChanges.Count, "There should be one breaking change when the parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithIntParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithStringParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(OperatorWithStringParameter.GetMember("op_Addition"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithStringParameter, OperatorWithIntParameter); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedParameterType).ToList(); AssertX.Equal(2, breakingChanges.Count, "There should be one breaking change when the parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithStringParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithIntParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(OperatorWithIntParameter.GetMember("op_Addition"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithIntParameter, OperatorWithDynamicParameter); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedParameterType).ToList(); AssertX.Equal(1, breakingChanges.Count, "There should be no breaking changes when the Parameter type changes to dynamic."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithDynamicParameter, OperatorWithIntParameter); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedParameterType).ToList(); AssertX.Equal(2, breakingChanges.Count, "There should be one breaking change when the Parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithDynamicParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithIntParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(OperatorWithIntParameter.GetMember("op_Addition"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithStringParameter, OperatorWithDynamicParameter); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedParameterType).ToList(); AssertX.Equal(1, breakingChanges.Count, "There should be no breaking changes when the Parameter type changes to dynamic."); breakingChanges = MetadataComparer.CompareTypes(OperatorWithDynamicParameter, OperatorWithStringParameter); breakingChanges = breakingChanges.Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedParameterType).ToList(); AssertX.Equal(2, breakingChanges.Count, "There should be one breaking change when the Parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithDynamicParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)OperatorWithStringParameter.GetMember("op_Addition")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(OperatorWithStringParameter.GetMember("op_Addition"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void MethodTests() { var assembly = AssemblyData.FromAssembly(typeof(AddedAbstractMemberTests).Assembly); var methodVirtual = TypeDefinitionData.FromType(typeof(MethodVirtual)); var methodAbstract = TypeDefinitionData.FromType(typeof(MethodAbstract)); var breakingChanges = MetadataComparer.CompareTypes(methodVirtual, methodAbstract); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a virtual member changes to abstract."); Assert.AreEqual(BreakingChangeKind.ChangedMemberToAbstract, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(methodVirtual.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(methodAbstract.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(methodAbstract, methodVirtual); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an abstract member changes to virtual."); }
public void ParameterTypeContravarianceTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterTypeTests)); var methodWithParameterBase = context.GetTypeDefinitionData(typeof(MethodWithParameterBase)); var methodWithParameterDerived = context.GetTypeDefinitionData(typeof(MethodWithParameterDerived)); var breakingChanges = MetadataComparer.CompareTypes(methodWithParameterBase, methodWithParameterDerived); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(((IParameterizedItem)methodWithParameterBase.GetMember("Method")).Parameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(((IParameterizedItem)methodWithParameterDerived.GetMember("Method")).Parameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(methodWithParameterDerived.GetMember("Method"), breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(methodWithParameterDerived, methodWithParameterBase); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the parameter type changes to a base type."); }
public void PropertyTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(AddedAbstractMemberTests)); var PropertyNotDeclared = context.GetTypeDefinitionData <PropertyNotDeclared>(); var PropertyAbstract = context.GetTypeDefinitionData <PropertyAbstract>(); var breakingChanges = MetadataComparer.CompareTypes(PropertyNotDeclared, PropertyAbstract); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when an abstract member is added."); AssertX.Equal(BreakingChangeKind.AddedAbstractMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Null(breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(PropertyAbstract.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(PropertyAbstract, PropertyNotDeclared).Where(b => b.BreakingChangeKind == BreakingChangeKind.AddedAbstractMember).ToList(); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an abstract member changes to virtual."); }
public void FieldTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly); var FieldReadOnly = TypeDefinitionData.FromType(typeof(FieldReadOnly)); var FieldReadWrite = TypeDefinitionData.FromType(typeof(FieldReadWrite)); var breakingChanges = MetadataComparer.CompareTypes(FieldReadOnly, FieldReadWrite); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when changing a read-only field to read/write."); breakingChanges = MetadataComparer.CompareTypes(FieldReadWrite, FieldReadOnly); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when changing a read/write field to read-only."); Assert.AreEqual(BreakingChangeKind.ChangedFieldToReadOnly, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(FieldReadWrite.GetMember("Field"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(FieldReadOnly.GetMember("Field"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void MethodTests() { var assembly = AssemblyData.FromAssembly(typeof(AddedAbstractMemberTests).Assembly); var MethodNotDeclared = TypeDefinitionData.FromType <MethodNotDeclared>(); var MethodAbstract = TypeDefinitionData.FromType <MethodAbstract>(); var breakingChanges = MetadataComparer.CompareTypes(MethodNotDeclared, MethodAbstract); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an abstract member is added."); Assert.AreEqual(BreakingChangeKind.AddedAbstractMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.IsNull(breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(MethodAbstract.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(MethodAbstract, MethodNotDeclared).Where(b => b.BreakingChangeKind == BreakingChangeKind.AddedAbstractMember).ToList(); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an abstract member changes to virtual."); }
public void ConstructorTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedParameterCountTests).Assembly); var ConstructorWithFewerParameters = TypeDefinitionData.FromType(typeof(ConstructorWithFewerParameters)); var ConstructorWithMoreParameters = TypeDefinitionData.FromType(typeof(ConstructorWithMoreParameters)); var ConstructorWithOptionalParameter = TypeDefinitionData.FromType(typeof(ConstructorWithOptionalParameter)); var ConstructorWithParamsParameter = TypeDefinitionData.FromType(typeof(ConstructorWithParamsParameter)); var breakingChanges = MetadataComparer.CompareTypes(ConstructorWithFewerParameters, ConstructorWithMoreParameters); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(ConstructorWithFewerParameters.GetMember(".ctor"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(ConstructorWithMoreParameters.GetMember(".ctor"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithMoreParameters, ConstructorWithFewerParameters); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(ConstructorWithMoreParameters.GetMember(".ctor"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(ConstructorWithFewerParameters.GetMember(".ctor"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithMoreParameters, ConstructorWithOptionalParameter); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a required parameter is made optional."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithFewerParameters, ConstructorWithOptionalParameter); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an optional parameter is added."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithOptionalParameter, ConstructorWithMoreParameters); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(ConstructorWithOptionalParameter.GetMember(".ctor"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(ConstructorWithMoreParameters.GetMember(".ctor"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithFewerParameters, ConstructorWithParamsParameter); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an params parameter is added."); breakingChanges = MetadataComparer.CompareTypes(ConstructorWithParamsParameter, ConstructorWithMoreParameters); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); Assert.AreEqual(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(ConstructorWithParamsParameter.GetMember(".ctor"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(ConstructorWithMoreParameters.GetMember(".ctor"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void PropertyTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(AddedAbstractMemberTests)); var PropertyVirtual = context.GetTypeDefinitionData(typeof(PropertyVirtual)); var PropertyAbstract = context.GetTypeDefinitionData(typeof(PropertyAbstract)); var breakingChanges = MetadataComparer.CompareTypes(PropertyVirtual, PropertyAbstract); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a virtual member changes to abstract."); AssertX.Equal(BreakingChangeKind.ChangedMemberToAbstract, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(PropertyVirtual.GetMember("Property"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(PropertyAbstract.GetMember("Property"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(PropertyAbstract, PropertyVirtual); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an abstract member changes to virtual."); }
public void IndexerTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterCountTests)); var IndexerWithFewerParameters = context.GetTypeDefinitionData(typeof(IndexerWithFewerParameters)); var IndexerWithMoreParameters = context.GetTypeDefinitionData(typeof(IndexerWithMoreParameters)); var IndexerWithOptionalParameter = context.GetTypeDefinitionData(typeof(IndexerWithOptionalParameter)); var IndexerWithParamsParameter = context.GetTypeDefinitionData(typeof(IndexerWithParamsParameter)); var breakingChanges = MetadataComparer.CompareTypes(IndexerWithFewerParameters, IndexerWithMoreParameters); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(IndexerWithFewerParameters.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(IndexerWithMoreParameters.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerWithMoreParameters, IndexerWithFewerParameters); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(IndexerWithMoreParameters.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(IndexerWithFewerParameters.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerWithMoreParameters, IndexerWithOptionalParameter); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a required parameter is made optional."); breakingChanges = MetadataComparer.CompareTypes(IndexerWithFewerParameters, IndexerWithOptionalParameter); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an optional parameter is added."); breakingChanges = MetadataComparer.CompareTypes(IndexerWithOptionalParameter, IndexerWithMoreParameters); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(IndexerWithOptionalParameter.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(IndexerWithMoreParameters.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerWithFewerParameters, IndexerWithParamsParameter); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an params parameter is added."); breakingChanges = MetadataComparer.CompareTypes(IndexerWithParamsParameter, IndexerWithMoreParameters); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the required parameter count changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterCount, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(IndexerWithParamsParameter.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(IndexerWithMoreParameters.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void MethodTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(RemovedExtensionMethodModifierTests)); var ClassWithExtensionMethod = context.GetTypeDefinitionData(typeof(ClassWithExtensionMethod)); var ClassWithoutExtensionMethod = context.GetTypeDefinitionData(typeof(ClassWithoutExtensionMethod)); var breakingChanges = MetadataComparer.CompareTypes(ClassWithExtensionMethod, ClassWithoutExtensionMethod); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when an extension method is turned into a normal method."); AssertX.Equal(BreakingChangeKind.RemovedExtensionMethodModifier, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(ClassWithExtensionMethod.GetMember("Method"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(ClassWithoutExtensionMethod.GetMember("Method"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ClassWithoutExtensionMethod, ClassWithExtensionMethod); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when an normal method is turned into an extension method."); }
public void NestedTypeTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedAccessibilityFromPublicToProtectedTests)); var NestedClass = context.GetTypeDefinitionData(typeof(NestedClass)); var NestedClassWithInternalConstructor = context.GetTypeDefinitionData(typeof(NestedClassWithInternalConstructor)); var NestedAbstractClass = context.GetTypeDefinitionData(typeof(NestedAbstractClass)); var breakingChanges = MetadataComparer.CompareTypes(NestedClass, NestedAbstractClass).Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedClassToAbstract).ToList(); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when a class is made abstract."); AssertX.Equal(BreakingChangeKind.ChangedClassToAbstract, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(NestedClass.GetMember("Class"), breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(NestedAbstractClass.GetMember("Class"), breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Null(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(NestedClassWithInternalConstructor, NestedAbstractClass); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when a class with no public constructors is made abstract."); }
public void ChangeVoidToNonVoidAllowedTest() { var assembly = AssemblyData.FromAssembly(typeof(ChangedMemberTypeTests).Assembly); var MethodWithIntReturn = TypeDefinitionData.FromType(typeof(MethodWithIntReturn)); var MethodWithStringReturn = TypeDefinitionData.FromType(typeof(MethodWithStringReturn)); var MethodWithDynamicReturn = TypeDefinitionData.FromType(typeof(MethodWithDynamicReturn)); var MethodWithVoidReturn = TypeDefinitionData.FromType(typeof(MethodWithVoidReturn)); var breakingChanges = MetadataComparer.CompareTypes(MethodWithVoidReturn, MethodWithIntReturn); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes from void to non-void."); breakingChanges = MetadataComparer.CompareTypes(MethodWithVoidReturn, MethodWithStringReturn); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes from void to non-void."); breakingChanges = MetadataComparer.CompareTypes(MethodWithVoidReturn, MethodWithDynamicReturn); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes from void to non-void."); }
public void ChangeVoidToNonVoidAllowedTest() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedMemberTypeTests)); var MethodWithIntReturn = context.GetTypeDefinitionData(typeof(MethodWithIntReturn)); var MethodWithStringReturn = context.GetTypeDefinitionData(typeof(MethodWithStringReturn)); var MethodWithDynamicReturn = context.GetTypeDefinitionData(typeof(MethodWithDynamicReturn)); var MethodWithVoidReturn = context.GetTypeDefinitionData(typeof(MethodWithVoidReturn)); var breakingChanges = MetadataComparer.CompareTypes(MethodWithVoidReturn, MethodWithIntReturn); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes from void to non-void."); breakingChanges = MetadataComparer.CompareTypes(MethodWithVoidReturn, MethodWithStringReturn); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes from void to non-void."); breakingChanges = MetadataComparer.CompareTypes(MethodWithVoidReturn, MethodWithDynamicReturn); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the Return type changes from void to non-void."); }
public void TypeTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly); var Class = TypeDefinitionData.FromType(typeof(Class)); var ClassWithInternalConstructor = TypeDefinitionData.FromType(typeof(ClassWithInternalConstructor)); var AbstractClass = TypeDefinitionData.FromType(typeof(AbstractClass)); var breakingChanges = MetadataComparer.CompareTypes(Class, AbstractClass).Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedClassToAbstract).ToList(); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a class is made abstract."); Assert.AreEqual(BreakingChangeKind.ChangedClassToAbstract, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(Class, breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(AbstractClass, breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ClassWithInternalConstructor, AbstractClass); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a class with no public constructors is made abstract."); }
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 TypeTests() { var context = MetadataResolutionContext.CreateFromTypes(typeof(ChangedParameterTypeTests)); var DelegateWithIntParameter = context.GetTypeDefinitionData(typeof(DelegateWithIntParameter)); var DelegateWithStringParameter = context.GetTypeDefinitionData(typeof(DelegateWithStringParameter)); var DelegateWithDynamicParameter = context.GetTypeDefinitionData(typeof(DelegateWithDynamicParameter)); var breakingChanges = MetadataComparer.CompareTypes(DelegateWithIntParameter, DelegateWithStringParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(DelegateWithIntParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(DelegateWithStringParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(DelegateWithStringParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithStringParameter, DelegateWithIntParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(DelegateWithStringParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(DelegateWithIntParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(DelegateWithIntParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithIntParameter, DelegateWithDynamicParameter); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the Parameter type changes to dynamic."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithDynamicParameter, DelegateWithIntParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(DelegateWithDynamicParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(DelegateWithIntParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(DelegateWithIntParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithStringParameter, DelegateWithDynamicParameter); AssertX.Equal(0, breakingChanges.Count, "There should be no breaking changes when the Parameter type changes to dynamic."); breakingChanges = MetadataComparer.CompareTypes(DelegateWithDynamicParameter, DelegateWithStringParameter); AssertX.Equal(1, breakingChanges.Count, "There should be one breaking change when the Parameter type changes."); AssertX.Equal(BreakingChangeKind.ChangedParameterType, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); AssertX.Equal(DelegateWithDynamicParameter.DelegateParameters[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); AssertX.Equal(DelegateWithStringParameter.DelegateParameters[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); AssertX.Equal(DelegateWithStringParameter, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }