public void MergeResultsCopiesAcrossResultsFromAggregator()
        {
            var childResults = new List <ComparisonResult>
            {
                new(SemVerChangeType.Feature, null, new TestClassDefinition(), Guid.NewGuid().ToString()),
                new(SemVerChangeType.Breaking, new TestInterfaceDefinition(), null, Guid.NewGuid().ToString()),
                new(
                    SemVerChangeType.Feature,
                    new TestPropertyDefinition(), new TestPropertyDefinition(),
                    Guid.NewGuid().ToString()),
                new(
                    SemVerChangeType.Breaking,
                    new TestFieldDefinition(), new TestFieldDefinition(),
                    Guid.NewGuid().ToString()),
            };
            var aggregator = new ChangeResultAggregator
            {
                ExitNodeAnalysis = true
            };

            aggregator.AddResults(childResults);

            var sut = new ChangeResultAggregator();

            sut.MergeResults(aggregator);

            var actual = sut.Results;

            actual.Should().BeEquivalentTo(childResults);
            sut.ExitNodeAnalysis.Should().Be(aggregator.ExitNodeAnalysis);
        }
        public void AssignsDefaultValuesWhenCreated()
        {
            var sut = new ChangeResultAggregator();

            sut.ExitNodeAnalysis.Should().BeFalse();
            sut.Results.Should().BeEmpty();
        }
        public void ResultsReturnsAddedResults()
        {
            var first  = new ComparisonResult(SemVerChangeType.Feature, null, new TestPropertyDefinition(), Guid.NewGuid().ToString());
            var second = new ComparisonResult(SemVerChangeType.Breaking, new TestFieldDefinition(), null, Guid.NewGuid().ToString());
            var set    = new List <ComparisonResult>
            {
                new(SemVerChangeType.Feature, null, new TestClassDefinition(), Guid.NewGuid().ToString()),
                new(SemVerChangeType.Breaking, new TestInterfaceDefinition(), null, Guid.NewGuid().ToString()),
                new(
                    SemVerChangeType.Feature,
                    new TestPropertyDefinition(), new TestPropertyDefinition(),
                    Guid.NewGuid().ToString()),
                new(
                    SemVerChangeType.Breaking,
                    new TestAttributeDefinition(), new TestAttributeDefinition(),
                    Guid.NewGuid().ToString()),
            };
            var expected = new List <ComparisonResult>
            {
                first
            };

            expected.AddRange(set);
            expected.Add(second);

            var sut = new ChangeResultAggregator();

            sut.AddResult(first);
            sut.AddResults(set);
            sut.AddResult(second);

            var actual = sut.Results;

            actual.Should().BeEquivalentTo(expected);
        }
        public void MergeResultsThrowsExceptionWithNullResult()
        {
            var sut = new ChangeResultAggregator();

            Action action = () => sut.MergeResults(null !);

            action.Should().Throw <ArgumentNullException>();
        }
        public void OverallChangeTypeReturnsNoneWhenNoResultsEntered()
        {
            var sut = new ChangeResultAggregator();

            var actual = sut.OverallChangeType;

            actual.Should().Be(SemVerChangeType.None);
        }
        public IEnumerable <ComparisonResult> CompareMatch(ItemMatch <IGenericTypeElement> match, ComparerOptions options)
        {
            match   = match ?? throw new ArgumentNullException(nameof(match));
            options = options ?? throw new ArgumentNullException(nameof(options));

            var oldTypeParameters = match.OldItem.GenericTypeParameters.FastToList();
            var newTypeParameters = match.NewItem.GenericTypeParameters.FastToList();

            if (oldTypeParameters.Count == 0 &&
                newTypeParameters.Count == 0)
            {
                return(Array.Empty <ComparisonResult>());
            }

            var typeParameterShift = oldTypeParameters.Count - newTypeParameters.Count;

            var aggregator = new ChangeResultAggregator();

            if (typeParameterShift != 0)
            {
                var changeLabel = typeParameterShift > 0 ? "removed" : "added";
                var shiftAmount = Math.Abs(typeParameterShift);

                // One or more generic type parameters have been removed
                var suffix = shiftAmount == 1 ? "" : "s";
                var args   = new FormatArguments(
                    $"{{DefinitionType}} {{Identifier}} has {changeLabel} {shiftAmount} generic type parameter{suffix}",
                    match.NewItem.FullName,
                    null,
                    null);

                aggregator.AddElementChangedResult(SemVerChangeType.Breaking, match, options.MessageFormatter, args);

                // No need to look into how the generic type has changed
                return(aggregator.Results);
            }

            // We have the same number of generic types, evaluate the constraints
            for (var index = 0; index < oldTypeParameters.Count; index++)
            {
                var oldName = oldTypeParameters[index];
                var newName = newTypeParameters[index];

                var oldConstraints = match.OldItem.GenericConstraints.FirstOrDefault(x => x.Name == oldName);
                var newConstraints = match.NewItem.GenericConstraints.FirstOrDefault(x => x.Name == newName);

                EvaluateGenericConstraints(match, oldConstraints, newConstraints, options, aggregator);
            }

            return(aggregator.Results);
        }
        public void OverallChangeTypeReturnsHighestResult(SemVerChangeType firstType,
                                                          SemVerChangeType secondType, SemVerChangeType expected)
        {
            var firstItem  = new TestPropertyDefinition();
            var secondItem = new TestPropertyDefinition();
            var match      = new ItemMatch <IPropertyDefinition>(firstItem, secondItem);

            var firstResult  = new ComparisonResult(firstType, match.OldItem, match.NewItem, Guid.NewGuid().ToString());
            var secondResult =
                new ComparisonResult(secondType, match.OldItem, match.NewItem, Guid.NewGuid().ToString());

            var sut = new ChangeResultAggregator();

            sut.AddResult(firstResult);
            sut.AddResult(secondResult);

            var actual = sut.OverallChangeType;

            actual.Should().Be(expected);
        }
示例#8
0
        public IEnumerable <ComparisonResult> CompareMatch(ItemMatch <IAttributeDefinition> match,
                                                           ComparerOptions options)
        {
            match   = match ?? throw new ArgumentNullException(nameof(match));
            options = options ?? throw new ArgumentNullException(nameof(options));

            if (match.OldItem.Arguments.Count == 0 &&
                match.NewItem.Arguments.Count == 0)
            {
                // The attributes do not have any arguments
                // These attributes match each other
                return(Array.Empty <ComparisonResult>());
            }

            var aggregator = new ChangeResultAggregator();

            EvaluateArgumentDefinitionChanges(match, options, aggregator);

            return(aggregator.Results);
        }