public void UpdateAttributeWithValuesSpecifiedUpdatesOnlyEntriesForTheAttributeWithSpecifiedValuesForMembers() { const string inputCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Public Sub Foo(bar As String) Attribute Foo.VB_Ext_Key = ""Key"", ""Value"" Attribute Foo.VB_Ext_Key = ""OtherKey"", ""Value"" Attribute Foo.VB_Description = ""Desc"" bar = vbNullString End Sub "; const string expectedCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Public Sub Foo(bar As String) Attribute Foo.VB_Ext_Key = ""AnotherKey"", ""AnotherValue"" Attribute Foo.VB_Ext_Key = ""OtherKey"", ""Value"" Attribute Foo.VB_Description = ""Desc"" bar = vbNullString End Sub "; var attributesToRemove = "Foo.VB_Ext_Key"; var oldValues = new List <string> { "\"Key\"", "\"Value\"" }; var newValues = new List <string> { "\"AnotherKey\"", "\"AnotherValue\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo"); var attributesUpdater = new AttributesUpdater(state); attributesUpdater.UpdateAttribute(rewriteSession, fooDeclaration, attributesToRemove, newValues, oldValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void UpdateAttributeWithoutValuesSpecifiedUpdatesFirstEntryForTheAttributeAndRemovesTheRestForModules() { const string inputCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Attribute VB_Ext_Key = ""Key"", ""Value"" Attribute VB_Ext_Key = ""OtherKey"", ""Value"" Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Attribute VB_Ext_Key = ""AnotherKey"", ""AnotherValue"" Public Sub Foo(bar As String) bar = vbNullString End Sub "; var attributesToRemove = "VB_Ext_Key"; var newValues = new List <string> { "\"AnotherKey\"", "\"AnotherValue\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ProceduralModule) .First(); var attributesUpdater = new AttributesUpdater(state); attributesUpdater.UpdateAttribute(rewriteSession, moduleDeclaration, attributesToRemove, newValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }