示例#1
0
        public void FindMatchesIdentifiesPropertiesNotMatching()
        {
            var oldProperty         = new TestPropertyDefinition();
            var newProperty         = new TestPropertyDefinition();
            var oldMatchingProperty = new TestPropertyDefinition();
            var oldProperties       = new[]
            {
                oldProperty, oldMatchingProperty
            };
            var newMatchingProperty = oldMatchingProperty.JsonClone();
            var newProperties       = new[]
            {
                newMatchingProperty, newProperty
            };

            var sut = new PropertyEvaluator();

            var results = sut.FindMatches(oldProperties, newProperties);

            results.MatchingItems.Should().HaveCount(1);
            results.MatchingItems.First().OldItem.Should().Be(oldMatchingProperty);
            results.MatchingItems.First().NewItem.Should().Be(newMatchingProperty);
            results.ItemsAdded.Should().HaveCount(1);
            results.ItemsAdded.First().Should().Be(newProperty);
            results.ItemsRemoved.Should().HaveCount(1);
            results.ItemsRemoved.First().Should().Be(oldProperty);
        }
示例#2
0
        public void ThrowsExceptionWhenCreatedWithNullOldItem()
        {
            var newItem = new TestPropertyDefinition();

            // ReSharper disable once ObjectCreationAsStatement
            Action action = () => new ItemMatch <IPropertyDefinition>(null !, newItem);

            action.Should().Throw <ArgumentNullException>();
        }
示例#3
0
        public void PropertiesReturnConstructorValues()
        {
            var oldItem = new TestPropertyDefinition();
            var newItem = new TestPropertyDefinition();

            var sut = new ItemMatch <IPropertyDefinition>(oldItem, newItem);

            sut.OldItem.Should().Be(oldItem);
            sut.NewItem.Should().Be(newItem);
        }
        public void CompareMatchReturnsEmptyWhenNoChangeFound()
        {
            var options    = new ComparerOptions();
            var oldElement = new TestPropertyDefinition();
            var newElement = new TestPropertyDefinition();
            var match      = new ItemMatch <IElementDefinition>(oldElement, newElement);

            var changeTable = Substitute.For <IAccessModifiersChangeTable>();

            changeTable.CalculateChange(oldElement.AccessModifiers, newElement.AccessModifiers)
            .Returns(SemVerChangeType.None);

            var sut = new Wrapper(changeTable);

            var actual = sut.RunCompareMatch(match, AccessModifiers.Internal, AccessModifiers.Private, options);

            actual.Should().BeEmpty();
        }
        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);
        }
示例#6
0
        public void FindMatchesReturnsSinglePropertyMatchingByName()
        {
            var oldProperty   = new TestPropertyDefinition();
            var oldProperties = new[]
            {
                oldProperty
            };
            var newProperty   = oldProperty.JsonClone();
            var newProperties = new[]
            {
                newProperty
            };

            var sut = new PropertyEvaluator();

            var results = sut.FindMatches(oldProperties, newProperties);

            results.MatchingItems.Should().HaveCount(1);
            results.MatchingItems.First().OldItem.Should().Be(oldProperty);
            results.MatchingItems.First().NewItem.Should().Be(newProperty);
            results.ItemsAdded.Should().BeEmpty();
            results.ItemsRemoved.Should().BeEmpty();
        }
        public void CompareReturnsEmptyWhenPropertyReturnTypeIsRenamedGenericTypeOnParentType()
        {
            var oldGrandparent =
                new TestClassDefinition().Set(x => x.GenericTypeParameters = new List <string> {
                "TOld"
            }.AsReadOnly());
            var oldParent = new TestClassDefinition().Set(x => x.DeclaringType = oldGrandparent);
            var oldMember = new TestPropertyDefinition().Set(x =>
            {
                x.DeclaringType = oldParent;
                x.ReturnType    = "TOld";
            });
            var newGrandparent =
                new TestClassDefinition().Set(x => x.GenericTypeParameters = new List <string> {
                "TNew"
            }.AsReadOnly());
            var newParent = new TestClassDefinition().Set(x => x.DeclaringType = newGrandparent);
            var newMember = new TestPropertyDefinition().Set(x =>
            {
                x.DeclaringType = newParent;
                x.ReturnType    = "TNew";
            });
            var match   = new ItemMatch <TestPropertyDefinition>(oldMember, newMember);
            var options = ComparerOptions.Default;

            var accessModifiersComparer = Substitute.For <IAccessModifiersComparer>();
            var attributeProcessor      = Substitute.For <IAttributeMatchProcessor>();

            var sut = Substitute.ForPartsOf <MemberComparer <TestPropertyDefinition> >(accessModifiersComparer,
                                                                                       attributeProcessor);

            var actual = sut.CompareMatch(match, options).ToList();

            _output.WriteResults(actual);

            actual.Should().BeEmpty();
        }
        public void CalculateChangesReturnsResultsForAddedElementDefinitions(PropertyModifiers modifiers,
                                                                             SemVerChangeType expected)
        {
            var oldItems = Array.Empty <IPropertyDefinition>();
            var newItem  = new TestPropertyDefinition().Set(x =>
            {
                x.IsVisible = true;
                x.Modifiers = modifiers;
            });
            var newItems = new List <IPropertyDefinition>
            {
                newItem
            };
            var options      = ComparerOptions.Default;
            var matchResults = new MatchResults <IPropertyDefinition>(Array.Empty <IPropertyDefinition>(),
                                                                      newItems);

            Service <IPropertyEvaluator>().FindMatches(oldItems, newItems).Returns(matchResults);

            var actual = SUT.CalculateChanges(oldItems, newItems, options).ToList();

            actual.Should().HaveCount(1);
            actual[0].ChangeType.Should().Be(expected);
        }
        public void CalculateChangesReturnsBreakingWhenAddingMethodToInterface()
        {
            var declaringType = new TestInterfaceDefinition();
            var oldItems      = Array.Empty <IPropertyDefinition>();
            var newItem       = new TestPropertyDefinition().Set(x =>
            {
                x.IsVisible     = true;
                x.DeclaringType = declaringType;
            });
            var newItems = new List <IPropertyDefinition>
            {
                newItem
            };
            var options      = ComparerOptions.Default;
            var matchResults = new MatchResults <IPropertyDefinition>(Array.Empty <IPropertyDefinition>(),
                                                                      newItems);

            Service <IPropertyEvaluator>().FindMatches(oldItems, newItems).Returns(matchResults);

            var actual = SUT.CalculateChanges(oldItems, newItems, options).ToList();

            actual.Should().HaveCount(1);
            actual[0].ChangeType.Should().Be(SemVerChangeType.Breaking);
        }