public void GetResourceReferenceTest() { ResourceFile resFile = resources["Resource1.resx"]; VBHardCodedString hcs = new VBHardCodedString(this.codeFile, 157, 172); IExtractResourceAction action = new GenericVBExtractResourceAction(); Assert.AreEqual("My.Resources.Resource1.Test", action.GetResourceReference(resFile, "Test", null), "GetResourceReference does not work correctly in VB"); }
public void IndexGetterTests() { VBHardCodedString hcs = new VBHardCodedString(this.codeFile, 157, 172); TextDocument doc = ((EnvDTE.TextDocument)this.codeFile.Document.Object(null)); EditPoint ep = doc.StartPoint.CreateEditPoint(); string text = ep.GetLines(9,10); Assert.AreEqual(text.IndexOf("\"Test Instance\""), hcs.StartIndex); Assert.AreEqual(text.IndexOf("\"Test Instance\"") + "\"Test Instance\"".Length, hcs.EndIndex); Assert.AreEqual(8, hcs.StartingLine); }
/// <summary> /// Returns an instance of BaseHardCodedString, based the type of the current document. /// </summary> /// <param name="currentDocument">The document that contains an hard-coded string.</param> /// <returns>A hard coded string that is file type aware.</returns> public static BaseHardCodedString GetHardCodedString(Document currentDocument) { BaseHardCodedString stringInstance = null; // Create the hard coded string instance switch (currentDocument.Language) { case "CSharp": stringInstance = new CSharpHardCodedString(); break; case "Basic": stringInstance = new VBHardCodedString(); break; case "XAML": stringInstance = new XamlHardCodedString(); break; case "HTMLX": if (currentDocument.Name.EndsWith(".cshtml", StringComparison.CurrentCultureIgnoreCase)) { stringInstance = new CSharpRazorHardCodedString(); } else if (currentDocument.Name.EndsWith(".vbhtml", StringComparison.CurrentCultureIgnoreCase)) { stringInstance = new VBRazorHardCodedString(); } break; case "HTML": if (currentDocument.Name.EndsWith(".aspx", StringComparison.CurrentCultureIgnoreCase) || currentDocument.Name.EndsWith(".ascx", StringComparison.CurrentCultureIgnoreCase) || currentDocument.Name.EndsWith(".master", StringComparison.CurrentCultureIgnoreCase)) { stringInstance = new AspxHardCodedString(); } break; } return(stringInstance); }
public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled) { if (CmdName == null) { throw new ArgumentNullException("CmdName"); } if (this.availableRefactorOptions.ContainsKey(CmdName)) { TextSelection selection = (TextSelection)(applicationObject.ActiveDocument.Selection); if (applicationObject.ActiveDocument.ProjectItem.Object != null) { Common.BaseHardCodedString stringInstance = null; /// Create the hard coded string instance switch (applicationObject.ActiveDocument.Language) { case "CSharp": stringInstance = new Common.CSharpHardCodedString(); break; case "Basic": stringInstance = new Common.VBHardCodedString(); break; case "XAML": stringInstance = new Common.XamlHardCodedString(); break; case "HTML": if (applicationObject.ActiveDocument.Name.Contains(".cshtml")) { stringInstance = new Common.CSharpRazorHardCodedString(); } break; default: MessageBox.Show( Strings.UnsupportedFile + " (" + applicationObject.ActiveDocument.Language + ")", Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Common.MatchResult scanResult = stringInstance.CheckForHardCodedString( selection.Parent, selection.AnchorPoint.AbsoluteCharOffset - 1, selection.BottomPoint.AbsoluteCharOffset - 1); if (!scanResult.Result && selection.AnchorPoint.AbsoluteCharOffset < selection.BottomPoint.AbsoluteCharOffset) { scanResult.StartIndex = selection.AnchorPoint.AbsoluteCharOffset - 1; scanResult.EndIndex = selection.BottomPoint.AbsoluteCharOffset - 1; scanResult.Result = true; } if (scanResult.Result) { stringInstance = stringInstance.CreateInstance(applicationObject.ActiveDocument.ProjectItem, scanResult.StartIndex, scanResult.EndIndex); if (stringInstance != null && stringInstance.Parent != null) { Common.IStringRefactorOption option = this.availableRefactorOptions[CmdName]; if (option.QuerySupportForString(stringInstance)) { option.PerformAction(stringInstance); } else { MessageBox.Show( Strings.UnsupportedFile, Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show( Strings.NotStringLiteral, Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void GenericVBReplaceMethodTest() { // Get Project object Project testProject = (Project)(extensibility.Solution.Projects.Item(2)); ProjectItem codeFile = testProject.ProjectItems.Item("Form1.vb"); VBHardCodedString hcs = new VBHardCodedString(codeFile, 157, 172); TestReplaceMethod(codeFile, "Resource1.resx", hcs, TestStrings.VBReplaceTestExpectedLine, "Test"); }
public void ValueGetterTest() { VBHardCodedString hcs = new VBHardCodedString(this.codeFile, 157, 172); Assert.AreEqual("Test Instance", hcs.Value, "Simple string Value get failed"); Assert.AreEqual("\"Test Instance\"", hcs.RawValue, "Raw Value get failed"); hcs = new VBHardCodedString(this.codeFile, 188,204); Assert.AreEqual(@"Test""Instance", hcs.Value, "Value property for verbatim string with escaped quotes failed"); Assert.AreEqual("\"Test\"\"Instance\"", hcs.RawValue, "Raw Value get failed"); }