public void MultipleAddAttributeWorkForModules()
        {
            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)
    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_Exposed = False
Attribute VB_Description = ""Module Description""
Public Sub Foo(bar As String)
    bar = vbNullString
End Sub
";
            var firstAttributeToAdd  = "VB_Exposed";
            var firstAttributeValues = new List <string> {
                "False"
            };
            var secondAttributeToAdd  = "VB_Description";
            var secondAttributeValues = new List <string> {
                "\"Module Description\""
            };

            string actualCode;

            var(component, rewriteSession, state) = TestSetup(inputCode);
            using (state)
            {
                var moduleDeclaration = state.DeclarationFinder
                                        .UserDeclarations(DeclarationType.ProceduralModule)
                                        .First();
                var attributesUpdater = new AttributesUpdater(state);

                attributesUpdater.AddAttribute(rewriteSession, moduleDeclaration, firstAttributeToAdd, firstAttributeValues);
                attributesUpdater.AddAttribute(rewriteSession, moduleDeclaration, secondAttributeToAdd, secondAttributeValues);
                rewriteSession.TryRewrite();

                actualCode = component.CodeModule.Content();
            }
            Assert.AreEqual(expectedCode, actualCode);
        }
        public void MultipleAddAttributeWorkForMembers()
        {
            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)
    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_Description = ""The MyFunc Description""
Attribute Foo.VB_HelpID = 2
    bar = vbNullString
End Sub
";
            var firstAttributeToAdd  = "Foo.VB_Description";
            var firstAttributeValues = new List <string> {
                "\"The MyFunc Description\""
            };
            var secondAttributeToAdd  = "Foo.VB_HelpID";
            var secondAttributeValues = new List <string> {
                "2"
            };

            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.AddAttribute(rewriteSession, fooDeclaration, firstAttributeToAdd, firstAttributeValues);
                attributesUpdater.AddAttribute(rewriteSession, fooDeclaration, secondAttributeToAdd, secondAttributeValues);
                rewriteSession.TryRewrite();

                actualCode = component.CodeModule.Content();
            }
            Assert.AreEqual(expectedCode, actualCode);
        }
        public void AddAttributeAddsVbExtKeyAttributeForDifferentKey()
        {
            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""
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 = ""Key"", ""Value""
Attribute VB_Ext_Key = ""OtherKey"", ""Value""
Public Sub Foo(bar As String)
    bar = vbNullString
End Sub
";
            var attributeToAdd  = "VB_Ext_Key";
            var attributeValues = new List <string> {
                "\"OtherKey\"", "\"Value\""
            };

            string actualCode;

            var(component, rewriteSession, state) = TestSetup(inputCode);
            using (state)
            {
                var moduleDeclaration = state.DeclarationFinder
                                        .UserDeclarations(DeclarationType.ProceduralModule)
                                        .First();
                var attributesUpdater = new AttributesUpdater(state);

                attributesUpdater.AddAttribute(rewriteSession, moduleDeclaration, attributeToAdd, attributeValues);
                rewriteSession.TryRewrite();

                actualCode = component.CodeModule.Content();
            }
            Assert.AreEqual(expectedCode, actualCode);
        }
        //Should never happen in a real module.
        public void AddAttributeAddsModuleAttributeAtTopOfModuleIfThereAreNoModuleAttributesYet()
        {
            const string inputCode =
                @"Public Sub Foo(bar As String)
    bar = vbNullString
End Sub
";

            const string expectedCode =
                @"Attribute VB_Exposed = False
Public Sub Foo(bar As String)
    bar = vbNullString
End Sub
";
            var attributeToAdd  = "VB_Exposed";
            var attributeValues = new List <string> {
                "False"
            };

            string actualCode;

            var(component, rewriteSession, state) = TestSetup(inputCode);
            using (state)
            {
                var moduleDeclaration = state.DeclarationFinder
                                        .UserDeclarations(DeclarationType.ProceduralModule)
                                        .First();
                var attributesUpdater = new AttributesUpdater(state);

                attributesUpdater.AddAttribute(rewriteSession, moduleDeclaration, attributeToAdd, attributeValues);
                rewriteSession.TryRewrite();

                actualCode = component.CodeModule.Content();
            }
            Assert.AreEqual(expectedCode, actualCode);
        }