public void CompareMatchReturnsBreakingWhenOrdinalArgumentValueChanged() { var oldArgument = Model.UsingModule <ConfigurationModule>().Create <TestArgumentDefinition>() .Set(x => x.ArgumentType = ArgumentType.Ordinal); var oldArguments = new[] { oldArgument }; var oldAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>() .Set(x => x.Arguments = oldArguments); var newArgument = Model.UsingModule <ConfigurationModule>().Create <TestArgumentDefinition>().Set( x => { x.ArgumentType = ArgumentType.Ordinal; }); var newArguments = new[] { newArgument }; var newAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>() .Set(x => x.Arguments = newArguments); var match = new ItemMatch <IAttributeDefinition>(oldAttribute, newAttribute); var options = OptionsFactory.BuildOptions(); var sut = new AttributeComparer(); var actual = sut.CompareMatch(match, options).ToList(); _output.WriteResults(actual); actual.Should().HaveCount(1); actual[0].ChangeType.Should().Be(SemVerChangeType.Breaking); actual[0].OldItem.Should().BeAssignableTo <IArgumentDefinition>(); actual[0].NewItem.Should().BeAssignableTo <IArgumentDefinition>(); }
public async Task EvaluatesChangeOfGenericTypeDefinitionsOnDeclaringType( string oldClass, string newClass, string oldSignature, string newSignature, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(NoParameters .Replace("public class MyClass", "public class " + oldClass) .Replace("public string MyMethod()", "public string " + oldSignature)) }; var newCode = new List <CodeSource> { new(NoParameters .Replace("public class MyClass", "public class " + newClass) .Replace("public string MyMethod()", "public string " + newSignature)) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }
public void CompareMatchThrowsExceptionWithNullMatch() { var options = OptionsFactory.BuildOptions(); var sut = new AttributeComparer(); Action action = () => sut.CompareMatch(null !, options); action.Should().Throw <ArgumentNullException>(); }
public void CompareMatchReturnsEmptyChangesWhenAttributesDoNotHaveArguments() { var oldItem = Model.UsingModule <ConfigurationModule>().Ignoring <TestAttributeDefinition>(x => x.Arguments) .Create <TestAttributeDefinition>(); var newItem = Model.UsingModule <ConfigurationModule>().Ignoring <TestAttributeDefinition>(x => x.Arguments) .Create <TestAttributeDefinition>(); var match = new ItemMatch <IAttributeDefinition>(oldItem, newItem); var options = OptionsFactory.BuildOptions(); var sut = new AttributeComparer(); var actual = sut.CompareMatch(match, options); actual.Should().BeEmpty(); }
public async Task ReturnsFeatureWhenClassAdded() { var oldCode = Array.Empty <CodeSource>(); var newCode = new List <CodeSource> { new(SingleClass) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Feature); }
public async Task EvaluatesFeatureWhenPropertyAdded() { var oldCode = new List <CodeSource> { new(NoProperty) }; var newCode = new List <CodeSource> { new(SingleProperty) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Feature); }
public async Task ReturnsNoneWhenMatchingSameInterface() { var oldCode = new List <CodeSource> { new(SingleInterface) }; var newCode = new List <CodeSource> { new(SingleInterface) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.None); }
public async Task EvaluatesBreakingWhenPropertyChangesName() { var oldCode = new List <CodeSource> { new(SingleProperty) }; var newCode = new List <CodeSource> { new(SingleProperty.Replace("MyProperty", "MyNewProperty")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public async Task ReturnsBreakingWhenClassChangesTypeDefinition() { var oldCode = new List <CodeSource> { new(SingleClass) }; var newCode = new List <CodeSource> { new(SingleClass.Replace("class", "interface")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public async Task ReturnsBreakingWhenPartialClassChangesName() { var oldCode = new List <CodeSource> { new(PartialClasses) }; var newCode = new List <CodeSource> { new(PartialClasses.Replace("MyClass", "MyNewClass")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public async Task EvaluatesNoChangeWhenReturnTypeIsRenamedGenericTypeParameter() { var oldCode = new List <CodeSource> { new(FieldOnTypeWithMultipleGenericTypeParameters) }; var newCode = new List <CodeSource> { new(FieldOnTypeWithMultipleGenericTypeParameters.Replace("TKey", "TMyKey")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.None); }
public async Task ReturnsNoneWhenSplittingPartialClass() { var oldCode = new List <CodeSource> { new(SingleClass) }; var newCode = new List <CodeSource> { new(PartialClasses) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.None); }
public async Task EvaluatesBreakingWhenAbstractMethodAdded() { var oldCode = new List <CodeSource> { new(NoMethod) }; var newCode = new List <CodeSource> { new(NoParameters.Replace("public string MyMethod", "public abstract string MyMethod")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public async Task ReturnsBreakingWhenReturnTypeChanged() { var oldCode = new List <CodeSource> { new(SingleField) }; var newCode = new List <CodeSource> { new(SingleField.Replace("string MyField", "bool MyField")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public async Task ReturnsBreakingWhenInterfaceAddsProperty() { var oldCode = new List <CodeSource> { new(EmptyInterface) }; var newCode = new List <CodeSource> { new(InterfaceWithProperty) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public async Task ReturnsBreakingWhenChangingGenericTypeConstraints() { var oldCode = new List <CodeSource> { new(TypeDefinitionCode.ClassWithMultipleGenericConstraints) }; var newCode = new List <CodeSource> { new( TypeDefinitionCode.ClassWithMultipleGenericConstraints.Replace("struct", "class")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.Breaking); }
public RewriteRule(int lineNumber, string line) { LineNumber = lineNumber; var m = RewriteRulePattern.Match(line); if (!m.Success) { throw new Exception("FAIL: '" + line + "'"); } //if (lines[0] == "RewriteRule") MatchPattern = CleanRegexFordotNet(m.Groups["match"].Value); ReplacePattern = m.Groups["replace"].Value; if (m.Groups["options"].Success) { Options = OptionsFactory.BuildOptions(m.Groups["options"].Value); } }
public async Task ReturnsNoneWhenRenamingGenericTypeParameter() { var oldCode = new List <CodeSource> { new(TypeDefinitionCode.ClassWithMultipleGenericConstraints) }; var newCode = new List <CodeSource> { new( TypeDefinitionCode.ClassWithMultipleGenericConstraints.Replace("TValue", "TUpdatedValue")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.None); }
public async Task EvaluatesChangeOfModifiers(string oldModifiers, string newModifiers, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(SingleField.Replace("string MyField", oldModifiers + " string MyField")) }; var newCode = new List <CodeSource> { new(SingleField.Replace("string MyField", newModifiers + " string MyField")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }
public async Task NoChangeFoundWhenMatchingSameCode() { var oldCode = new List <CodeSource> { new(TestNode.ClassProperty), new(TestNode.Field) }; var newCode = new List <CodeSource> { new(TestNode.ClassProperty), new(TestNode.Field) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(SemVerChangeType.None); }
public async Task EvaluatesAddingSetAccessorWithAccessModifiers( string modifiers, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(SingleProperty.Replace("set;", string.Empty)) }; var newCode = new List <CodeSource> { new(SingleProperty.Replace("set;", modifiers + " set;")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }
public void CompareMatchReturnsBreakingWhenArgumentsRemoved() { var oldItem = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>(); var newItem = Model.UsingModule <ConfigurationModule>().Ignoring <TestAttributeDefinition>(x => x.Arguments) .Create <IAttributeDefinition>(); var match = new ItemMatch <IAttributeDefinition>(oldItem, newItem); var options = OptionsFactory.BuildOptions(); var sut = new AttributeComparer(); var actual = sut.CompareMatch(match, options).ToList(); _output.WriteResults(actual); actual.Should().HaveCount(1); actual[0].ChangeType.Should().Be(SemVerChangeType.Breaking); actual[0].OldItem.Should().Be(oldItem); actual[0].NewItem.Should().Be(newItem); }
public async Task EvaluatesChangesToAttribute(string updatedValue, AttributeCompareOption compareOption, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(SingleProperty) }; var newCode = new List <CodeSource> { new(SingleProperty.Replace("[PropertyAttribute(344, true, myName: \"on the property\")]", updatedValue)) }; var options = OptionsFactory.BuildOptions().Set(x => x.CompareAttributes = compareOption); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }
public async Task ReturnsResultBasedOnAttributesOnClass(string updatedValue, AttributeCompareOption compareOption, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(TypeDefinitionCode.ClassWithAttribute) }; var newCode = new List <CodeSource> { new( TypeDefinitionCode.ClassWithAttribute.Replace("[JsonPropertyName(\"item\")]", updatedValue)) }; var options = OptionsFactory.BuildOptions().Set(x => x.CompareAttributes = compareOption); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }
public async Task EvaluatesChangeOfReturnType( string oldValue, string newValue, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(NoParameters.Replace("public string MyMethod()", "public " + oldValue + "()")) }; var newCode = new List <CodeSource> { new(NoParameters.Replace("public string MyMethod()", "public " + newValue + "()")) }; var options = OptionsFactory.BuildOptions(); var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }
public void CompareMatchReturnsEmptyResultsWhenNoChangeFound() { var ordinalArgument = Model.UsingModule <ConfigurationModule>().Create <TestArgumentDefinition>() .Set(x => x.ArgumentType = ArgumentType.Ordinal); var namedArgument = Model.UsingModule <ConfigurationModule>().Create <TestArgumentDefinition>() .Set(x => x.ArgumentType = ArgumentType.Named); var oldArguments = new[] { ordinalArgument, namedArgument }; var attribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>() .Set(x => x.Arguments = oldArguments); var match = new ItemMatch <IAttributeDefinition>(attribute, attribute); var options = OptionsFactory.BuildOptions(); var sut = new AttributeComparer(); var actual = sut.CompareMatch(match, options).ToList(); actual.Should().BeEmpty(); }
public async Task EvaluatesChangeOfMethodAttribute( string oldAttribute, string newAttribute, AttributeCompareOption compareOptions, SemVerChangeType expected) { var oldCode = new List <CodeSource> { new(NoParameters.Replace("public string MyMethod", oldAttribute + " public string MyMethod")) }; var newCode = new List <CodeSource> { new(NoParameters.Replace("public string MyMethod", newAttribute + " public string MyMethod")) }; var options = OptionsFactory.BuildOptions(); options.CompareAttributes = compareOptions; var result = await _calculator.CalculateChanges(oldCode, newCode, options, CancellationToken.None) .ConfigureAwait(false); result.ChangeType.Should().Be(expected); }