示例#1
0
        public void FindMatchesReturnsSingleAttributeMatchingByName(string firstName, string secondName, bool expected)
        {
            var oldAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>()
                               .Set(x => x.Name = firstName);
            var oldAttributes = new[]
            {
                oldAttribute
            };
            var newAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>()
                               .Set(x => { x.Name = secondName; });
            var newAttributes = new[]
            {
                newAttribute
            };

            var sut = new AttributeEvaluator();

            var results = sut.FindMatches(oldAttributes, newAttributes);

            if (expected)
            {
                results.MatchingItems.Should().HaveCount(1);
                results.MatchingItems.First().OldItem.Should().Be(oldAttribute);
                results.MatchingItems.First().NewItem.Should().Be(newAttribute);
                results.ItemsAdded.Should().BeEmpty();
                results.ItemsRemoved.Should().BeEmpty();
            }
            else
            {
                results.MatchingItems.Should().BeEmpty();
            }
        }
示例#2
0
        public void FindMatchesIdentifiesAttributesNotMatching()
        {
            var oldAttribute         = Model.UsingModule <ConfigurationModule>().Create <IAttributeDefinition>();
            var newAttribute         = Model.UsingModule <ConfigurationModule>().Create <IAttributeDefinition>();
            var oldMatchingAttribute = Model.UsingModule <ConfigurationModule>().Create <IAttributeDefinition>();
            var oldAttributes        = new[]
            {
                oldAttribute, oldMatchingAttribute
            };
            var newMatchingAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>()
                                       .Set(x =>
            {
                x.Name      = oldMatchingAttribute.Name;
                x.Arguments = oldMatchingAttribute.Arguments;
            });
            var newAttributes = new[]
            {
                newMatchingAttribute, newAttribute
            };

            var sut = new AttributeEvaluator();

            var results = sut.FindMatches(oldAttributes, newAttributes);

            results.MatchingItems.Should().HaveCount(1);
            results.MatchingItems.First().OldItem.Should().Be(oldMatchingAttribute);
            results.MatchingItems.First().NewItem.Should().Be(newMatchingAttribute);
            results.ItemsAdded.Should().HaveCount(1);
            results.ItemsAdded.First().Should().Be(newAttribute);
            results.ItemsRemoved.Should().HaveCount(1);
            results.ItemsRemoved.First().Should().Be(oldAttribute);
        }
示例#3
0
        public void FindMatchesReturnsSingleAttributeMatchingByNameIgnoringAttributeSuffix()
        {
            var oldAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>()
                               .Set(x => x.Name = "SomethingAttribute");
            var oldAttributes = new[]
            {
                oldAttribute
            };
            var newAttribute = Model.UsingModule <ConfigurationModule>().Create <TestAttributeDefinition>()
                               .Set(x => x.Name = "Something");
            var newAttributes = new[]
            {
                newAttribute
            };

            var sut = new AttributeEvaluator();

            var results = sut.FindMatches(oldAttributes, newAttributes);

            results.MatchingItems.Should().HaveCount(1);
            results.MatchingItems.First().OldItem.Should().Be(oldAttribute);
            results.MatchingItems.First().NewItem.Should().Be(newAttribute);
            results.ItemsAdded.Should().BeEmpty();
            results.ItemsRemoved.Should().BeEmpty();
        }
示例#4
0
        public void FindMatchesThrowsExceptionWithNullNewItems()
        {
            var oldItems = Array.Empty <AttributeDefinition>();

            var sut = new AttributeEvaluator();

            Action action = () => sut.FindMatches(oldItems, null !);

            action.Should().Throw <ArgumentNullException>();
        }
示例#5
0
        public async Task FindMatchesReturnsMatchesByArguments(string oldCode, string newCode,
                                                               bool expected, string scenario)
        {
            _output.WriteLine(scenario);

            var oldNode = await TestNode
                          .FindNode <AttributeSyntax>(AttributeDefinitionCode.SimpleAttribute.Replace("SimpleAttribute", oldCode))
                          .ConfigureAwait(false);

            var oldAttribute  = new AttributeDefinition(oldNode);
            var oldAttributes = new[]
            {
                oldAttribute
            };
            var newNode = await TestNode
                          .FindNode <AttributeSyntax>(AttributeDefinitionCode.SimpleAttribute.Replace("SimpleAttribute", newCode))
                          .ConfigureAwait(false);

            var newAttribute  = new AttributeDefinition(newNode);
            var newAttributes = new[]
            {
                newAttribute
            };

            var sut = new AttributeEvaluator();

            var results = sut.FindMatches(oldAttributes, newAttributes);

            if (expected)
            {
                results.MatchingItems.Should().HaveCount(1);
                results.MatchingItems.First().OldItem.Should().Be(oldAttribute);
                results.MatchingItems.First().NewItem.Should().Be(newAttribute);
                results.ItemsAdded.Should().BeEmpty();
                results.ItemsRemoved.Should().BeEmpty();
            }
            else
            {
                results.MatchingItems.Should().BeEmpty();
            }
        }