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(); } }
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); }
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(); }
public void FindMatchesThrowsExceptionWithNullNewItems() { var oldItems = Array.Empty <AttributeDefinition>(); var sut = new AttributeEvaluator(); Action action = () => sut.FindMatches(oldItems, null !); action.Should().Throw <ArgumentNullException>(); }
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(); } }