protected override TestWorkspace CreateWorkspaceFromFile(string initialMarkup, TestParameters parameters)
 {
     return(TestWorkspace.IsWorkspaceElement(initialMarkup)
         ? TestWorkspace.Create(initialMarkup)
         : TestWorkspace.CreateCSharp(initialMarkup, parameters.parseOptions, parameters.compilationOptions));
 }
    public async Task TestLspUpdatesCorrectWorkspaceWithMultipleWorkspacesAsync()
    {
        var firstWorkspaceXml =
            @$ "<Workspace>
    <Project Language=" "C#" " CommonReferences=" "true" " AssemblyName=" "FirstWorkspaceProject" ">
        <Document FilePath=" "C:\FirstWorkspace.cs" ">FirstWorkspace</Document>
    </Project>
</Workspace>";

        var secondWorkspaceXml =
            @$ "<Workspace>
    <Project Language=" "C#" " CommonReferences=" "true" " AssemblyName=" "SecondWorkspaceProject" ">
        <Document FilePath=" "C:\SecondWorkspace.cs" ">SecondWorkspace</Document>
    </Project>
</Workspace>";

        using var testLspServer = await CreateXmlTestLspServerAsync(firstWorkspaceXml);

        var exportProvider = testLspServer.TestWorkspace.ExportProvider;

        using var testWorkspaceTwo = TestWorkspace.Create(
                  XElement.Parse(secondWorkspaceXml),
                  workspaceKind: WorkspaceKind.MSBuild,
                  exportProvider: exportProvider);

        // Wait for workspace creation operations to complete for the second workspace.
        await WaitForWorkspaceOperationsAsync(testWorkspaceTwo);

        // Verify both workspaces registered.
        Assert.True(IsWorkspaceRegistered(testLspServer.TestWorkspace, testLspServer));
        Assert.True(IsWorkspaceRegistered(testWorkspaceTwo, testLspServer));

        var firstWorkspaceDocumentUri  = ProtocolConversions.GetUriFromFilePath(@"C:\FirstWorkspace.cs");
        var secondWorkspaceDocumentUri = ProtocolConversions.GetUriFromFilePath(@"C:\SecondWorkspace.cs");
        await testLspServer.OpenDocumentAsync(firstWorkspaceDocumentUri);

        // Verify we can get both documents from their respective workspaces.
        var firstDocument = await GetLspDocumentAsync(firstWorkspaceDocumentUri, testLspServer).ConfigureAwait(false);

        AssertEx.NotNull(firstDocument);
        Assert.Equal(firstWorkspaceDocumentUri, firstDocument.GetURI());
        Assert.Equal(testLspServer.TestWorkspace, firstDocument.Project.Solution.Workspace);

        var secondDocument = await GetLspDocumentAsync(secondWorkspaceDocumentUri, testLspServer).ConfigureAwait(false);

        AssertEx.NotNull(secondDocument);
        Assert.Equal(secondWorkspaceDocumentUri, secondDocument.GetURI());
        Assert.Equal(testWorkspaceTwo, secondDocument.Project.Solution.Workspace);

        // Verify making an LSP change only changes the respective workspace and document.
        await testLspServer.InsertTextAsync(firstWorkspaceDocumentUri, (0, 0, "Change in first workspace"));

        // The first document should now different text.
        var changedFirstDocument = await GetLspDocumentAsync(firstWorkspaceDocumentUri, testLspServer).ConfigureAwait(false);

        AssertEx.NotNull(changedFirstDocument);
        var changedFirstDocumentText = await changedFirstDocument.GetTextAsync(CancellationToken.None);

        var firstDocumentText = await firstDocument.GetTextAsync(CancellationToken.None);

        Assert.NotEqual(firstDocumentText, changedFirstDocumentText);

        // The second document should return the same document instance since it was not changed.
        var unchangedSecondDocument = await GetLspDocumentAsync(secondWorkspaceDocumentUri, testLspServer).ConfigureAwait(false);

        Assert.Equal(secondDocument, unchangedSecondDocument);
    }
 public DefaultVisualStudioRazorParserIntegrationTest()
 {
     Workspace       = TestWorkspace.Create();
     ProjectSnapshot = new EphemeralProjectSnapshot(Workspace.Services, TestProjectPath);
 }
Exemple #4
0
        public static ChangeSignatureTestState Create(XElement workspaceXml)
        {
            var workspace = TestWorkspace.Create(workspaceXml);

            return(new ChangeSignatureTestState(workspace));
        }
        public async Task CustomizableTagsForUnnecessaryCode()
        {
            var workspaceXml =
                @"<Workspace>
    <Project Language=""C#"" CommonReferences=""true"">
        <Document FilePath = ""Test.cs"" >
// System is used - rest are unused.
using System.Collections;
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Program
{
    void Test()
    {
        Int32 x = 2; // Int32 can be simplified.
        x += 1;
    }
}
        </Document>
    </Project>
</Workspace>";

            using var workspace = TestWorkspace.Create(workspaceXml);
            var options  = new Dictionary <OptionKey, object>();
            var language = workspace.Projects.Single().Language;
            var preferIntrinsicPredefinedTypeOption      = new OptionKey(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, language);
            var preferIntrinsicPredefinedTypeOptionValue = new CodeStyleOption <bool>(value: true, notification: NotificationOption.Error);

            options.Add(preferIntrinsicPredefinedTypeOption, preferIntrinsicPredefinedTypeOptionValue);

            workspace.ApplyOptions(options);

            var analyzerMap = new Dictionary <string, DiagnosticAnalyzer[]>
            {
                {
                    LanguageNames.CSharp,
                    new DiagnosticAnalyzer[]
                    {
                        new CSharpSimplifyTypeNamesDiagnosticAnalyzer(),
                        new CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer()
                    }
                }
            };

            var spans =
                (await _producer.GetDiagnosticsAndErrorSpans(workspace, analyzerMap)).Item2
                .OrderBy(s => s.Span.Span.Start).ToImmutableArray();

            Assert.Equal(3, spans.Length);
            var first  = spans[0];
            var second = spans[1];
            var third  = spans[2];

            Assert.Equal(PredefinedErrorTypeNames.Suggestion, first.Tag.ErrorType);
            Assert.Equal(CSharpFeaturesResources.Using_directive_is_unnecessary, first.Tag.ToolTipContent);
            Assert.Equal(40, first.Span.Start);
            Assert.Equal(25, first.Span.Length);

            Assert.Equal(PredefinedErrorTypeNames.Suggestion, second.Tag.ErrorType);
            Assert.Equal(CSharpFeaturesResources.Using_directive_is_unnecessary, second.Tag.ToolTipContent);
            Assert.Equal(82, second.Span.Start);
            Assert.Equal(60, second.Span.Length);

            Assert.Equal(PredefinedErrorTypeNames.SyntaxError, third.Tag.ErrorType);
            Assert.Equal(WorkspacesResources.Name_can_be_simplified, third.Tag.ToolTipContent);
            Assert.Equal(196, third.Span.Start);
            Assert.Equal(5, third.Span.Length);
        }
        public void TryGetWorkspaceFromLiveShare_NoLiveShareProvider_ReturnsFalse()
        {
            // Arrange
            var workspaceAccessor = new DefaultVisualStudioWorkspaceAccessor(Mock.Of <IBufferGraphFactoryService>(), Mock.Of <TextBufferProjectService>(), TestWorkspace.Create(), NoLiveShare);
            var textBuffer        = Mock.Of <ITextBuffer>();

            // Act
            var result = workspaceAccessor.TryGetWorkspaceFromLiveShare(textBuffer, out var workspace);

            // Assert
            Assert.False(result);
        }
        public DefaultProjectSnapshotManagerTest()
        {
            TagHelperResolver = new TestTagHelperResolver();

            HostServices = TestServices.Create(
                new IWorkspaceService[]
            {
                new TestProjectSnapshotProjectEngineFactory(),
            },
                new ILanguageService[]
            {
                TagHelperResolver,
            });

            Documents = new HostDocument[]
            {
                new HostDocument("c:\\MyProject\\File.cshtml", "File.cshtml"),
                new HostDocument("c:\\MyProject\\Index.cshtml", "Index.cshtml"),

                // linked file
                new HostDocument("c:\\SomeOtherProject\\Index.cshtml", "Pages\\Index.cshtml"),
            };

            HostProject = new HostProject("c:\\MyProject\\Test.csproj", FallbackRazorConfiguration.MVC_2_0);
            HostProjectWithConfigurationChange = new HostProject("c:\\MyProject\\Test.csproj", FallbackRazorConfiguration.MVC_1_0);

            Workspace      = TestWorkspace.Create(HostServices);
            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Enumerable.Empty <ProjectSnapshotChangeTrigger>(), Workspace);

            var projectId = ProjectId.CreateNewId("Test");
            var solution  = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                     projectId,
                                                                     VersionStamp.Default,
                                                                     "Test",
                                                                     "Test",
                                                                     LanguageNames.CSharp,
                                                                     "c:\\MyProject\\Test.csproj"));

            WorkspaceProject = solution.GetProject(projectId);

            var vbProjectId = ProjectId.CreateNewId("VB");

            solution = solution.AddProject(ProjectInfo.Create(
                                               vbProjectId,
                                               VersionStamp.Default,
                                               "VB",
                                               "VB",
                                               LanguageNames.VisualBasic,
                                               "VB.vbproj"));
            VBWorkspaceProject = solution.GetProject(vbProjectId);

            var projectWithoutFilePathId = ProjectId.CreateNewId("NoFile");

            solution = solution.AddProject(ProjectInfo.Create(
                                               projectWithoutFilePathId,
                                               VersionStamp.Default,
                                               "NoFile",
                                               "NoFile",
                                               LanguageNames.CSharp));
            WorkspaceProjectWithoutFilePath = solution.GetProject(projectWithoutFilePathId);

            // Approximates a project with multi-targeting
            var projectIdWithDifferentTfm = ProjectId.CreateNewId("TestWithDifferentTfm");

            solution = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                projectIdWithDifferentTfm,
                                                                VersionStamp.Default,
                                                                "Test (Different TFM)",
                                                                "Test",
                                                                LanguageNames.CSharp,
                                                                "c:\\MyProject\\Test.csproj"));
            WorkspaceProjectWithDifferentTfm = solution.GetProject(projectIdWithDifferentTfm);

            SomeTagHelpers = TagHelperResolver.TagHelpers;
            SomeTagHelpers.Add(TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build());
        }
 private static TestWorkspace CreateTestWorkspace(string xml)
 {
     return(TestWorkspace.Create(xml, composition: EditorTestCompositions.EditorFeaturesWpf));
 }
 protected Task <TestLspServer> CreateMultiProjectLspServerAsync(string xmlMarkup)
 => CreateTestLspServerAsync(TestWorkspace.Create(xmlMarkup, composition: Composition));
Exemple #10
0
            private static TestWorkspace CreateWorkspace(
                string projectLanguage,
                IEnumerable <string>?metadataSources,
                bool includeXmlDocComments,
                string?sourceWithSymbolReference,
                string?languageVersion,
                string?metadataLanguageVersion
                )
            {
                var languageVersionAttribute = languageVersion is null
                    ? ""
                    : $@" LanguageVersion=""{languageVersion}""";

                var xmlString = string.Concat(
                    @"
<Workspace>
    <Project Language=""",
                    projectLanguage,
                    @""" CommonReferences=""true""",
                    languageVersionAttribute
                    );

                xmlString += ">";

                metadataSources ??= new[] { AbstractMetadataAsSourceTests.DefaultMetadataSource };

                foreach (var source in metadataSources)
                {
                    var metadataLanguage = DeduceLanguageString(source);
                    var metadataLanguageVersionAttribute = metadataLanguageVersion is null
                        ? ""
                        : $@" LanguageVersion=""{metadataLanguageVersion}""";
                    xmlString = string.Concat(
                        xmlString,
                        $@"
        <MetadataReferenceFromSource Language=""{metadataLanguage}"" CommonReferences=""true"" {metadataLanguageVersionAttribute} IncludeXmlDocComments=""{includeXmlDocComments}"">
            <Document FilePath=""MetadataDocument"">
{SecurityElement.Escape(source)}
            </Document>
        </MetadataReferenceFromSource>"
                        );
                }

                if (sourceWithSymbolReference != null)
                {
                    xmlString = string.Concat(
                        xmlString,
                        string.Format(
                            @"
        <Document FilePath=""SourceDocument"">
{0}
        </Document>",
                            sourceWithSymbolReference
                            )
                        );
                }

                xmlString = string.Concat(
                    xmlString,
                    @"
    </Project>
</Workspace>"
                    );

                return(TestWorkspace.Create(xmlString));
            }
 protected Task <TestLspServer> CreateMultiProjectLspServerAsync(string xmlMarkup, LSP.ClientCapabilities?clientCapabilities = null)
 => CreateTestLspServerAsync(TestWorkspace.Create(xmlMarkup, composition: Composition), clientCapabilities, WellKnownLspServerKinds.AlwaysActiveVSLspServer);
        public void TryGetWorkspaceFromHostProject_NoHostProject_ReturnsFalse()
        {
            // Arrange
            var workspaceAccessor = new DefaultVisualStudioWorkspaceAccessor(Mock.Of <IBufferGraphFactoryService>(MockBehavior.Strict), Mock.Of <TextBufferProjectService>(s => s.GetHostProject(It.IsAny <ITextBuffer>()) == null, MockBehavior.Strict), TestWorkspace.Create());
            var textBuffer        = Mock.Of <ITextBuffer>(MockBehavior.Strict);

            // Act
            var result = workspaceAccessor.TryGetWorkspaceFromHostProject(textBuffer, out var workspace);

            // Assert
            Assert.False(result);
        }
        public void TryGetWorkspaceFromProjectionBuffer_NoProjectionBuffer_ReturnsFalse()
        {
            // Arrange
            var bufferGraph = new Mock <IBufferGraph>(MockBehavior.Strict);

            bufferGraph.Setup(graph => graph.GetTextBuffers(It.IsAny <Predicate <ITextBuffer> >()))
            .Returns <Predicate <ITextBuffer> >(predicate => new Collection <ITextBuffer>());
            var bufferGraphService = new Mock <IBufferGraphFactoryService>(MockBehavior.Strict);

            bufferGraphService.Setup(service => service.CreateBufferGraph(It.IsAny <ITextBuffer>()))
            .Returns(bufferGraph.Object);
            var workspaceAccessor = new DefaultVisualStudioWorkspaceAccessor(bufferGraphService.Object, Mock.Of <TextBufferProjectService>(MockBehavior.Strict), TestWorkspace.Create());
            var textBuffer        = Mock.Of <ITextBuffer>(MockBehavior.Strict);

            // Act
            var result = workspaceAccessor.TryGetWorkspaceFromProjectionBuffer(textBuffer, out var workspace);

            // Assert
            Assert.False(result);
        }
        public void TryGetWorkspaceFromLiveShare_CanNotFindWorkspace_ReturnsFalse()
        {
            // Arrange
            Workspace nullWorkspace = null;
            var       liveShareWorkspaceProvider = new Mock <LiveShareWorkspaceProvider>();

            liveShareWorkspaceProvider.Setup(provider => provider.TryGetWorkspace(It.IsAny <ITextBuffer>(), out nullWorkspace))
            .Returns(false);
            var workspaceAccessor = new DefaultVisualStudioWorkspaceAccessor(Mock.Of <IBufferGraphFactoryService>(), Mock.Of <TextBufferProjectService>(), TestWorkspace.Create(), liveShareWorkspaceProvider.Object);
            var textBuffer        = Mock.Of <ITextBuffer>();

            // Act
            var result = workspaceAccessor.TryGetWorkspaceFromLiveShare(textBuffer, out var workspace);

            // Assert
            Assert.False(result);
        }
Exemple #15
0
        internal async Task TestWithMockedGenerateTypeDialog(
            string initial,
            string languageName,
            string typeName,
            string expected             = null,
            bool isMissing              = false,
            Accessibility accessibility = Accessibility.NotApplicable,
            TypeKind typeKind           = TypeKind.Class,
            string projectName          = null,
            bool isNewFile              = false,
            string existingFilename     = null,
            ImmutableArray <string> newFileFolderContainers = default,
            string fullFilePath             = null,
            string newFileName              = null,
            string assertClassName          = null,
            bool checkIfUsingsIncluded      = false,
            bool checkIfUsingsNotIncluded   = false,
            string expectedTextWithUsings   = null,
            string defaultNamespace         = "",
            bool areFoldersValidIdentifiers = true,
            GenerateTypeDialogOptions assertGenerateTypeDialogOptions = null,
            IList <TypeKindOptions> assertTypeKindPresent             = null,
            IList <TypeKindOptions> assertTypeKindAbsent = null,
            bool isCancelled = false)
        {
            var workspace = TestWorkspace.IsWorkspaceElement(initial)
                ? TestWorkspace.Create(initial, composition: s_composition)
                : languageName == LanguageNames.CSharp
                  ? TestWorkspace.CreateCSharp(initial, composition: s_composition)
                  : TestWorkspace.CreateVisualBasic(initial, composition: s_composition);

            var testOptions = new TestParameters();

            var(diagnostics, actions, _) = await GetDiagnosticAndFixesAsync(workspace, testOptions);

            using var testState = new GenerateTypeTestState(workspace, projectToBeModified: projectName, typeName, existingFilename);

            // Initialize the viewModel values
            testState.TestGenerateTypeOptionsService.SetGenerateTypeOptions(
                accessibility: accessibility,
                typeKind: typeKind,
                typeName: testState.TypeName,
                project: testState.ProjectToBeModified,
                isNewFile: isNewFile,
                newFileName: newFileName,
                folders: newFileFolderContainers,
                fullFilePath: fullFilePath,
                existingDocument: testState.ExistingDocument,
                areFoldersValidIdentifiers: areFoldersValidIdentifiers,
                isCancelled: isCancelled);

            testState.TestProjectManagementService.SetDefaultNamespace(
                defaultNamespace: defaultNamespace);

            var generateTypeDiagFixes = diagnostics.SingleOrDefault(df => GenerateTypeTestState.FixIds.Contains(df.Id));

            if (isMissing)
            {
                Assert.Empty(actions);
                return;
            }

            var fixActions = MassageActions(actions);

            Assert.False(fixActions.IsDefault);

            // Since the dialog option is always fed as the last CodeAction
            var index  = fixActions.Count() - 1;
            var action = fixActions.ElementAt(index);

            Assert.Equal(action.Title, FeaturesResources.Generate_new_type);
            var operations = await action.GetOperationsAsync(CancellationToken.None);

            Tuple <Solution, Solution> oldSolutionAndNewSolution = null;

            if (!isNewFile)
            {
                oldSolutionAndNewSolution = await TestOperationsAsync(
                    testState.Workspace, expected, operations,
                    conflictSpans : ImmutableArray <TextSpan> .Empty,
                    renameSpans : ImmutableArray <TextSpan> .Empty,
                    warningSpans : ImmutableArray <TextSpan> .Empty,
                    navigationSpans : ImmutableArray <TextSpan> .Empty,
                    expectedChangedDocumentId : testState.ExistingDocument.Id);
            }
            else
            {
                oldSolutionAndNewSolution = await TestAddDocument(
                    testState.Workspace,
                    expected,
                    operations,
                    projectName != null,
                    testState.ProjectToBeModified.Id,
                    newFileFolderContainers,
                    newFileName);
            }

            if (checkIfUsingsIncluded)
            {
                Assert.NotNull(expectedTextWithUsings);
                await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operations,
                                          conflictSpans : ImmutableArray <TextSpan> .Empty,
                                          renameSpans : ImmutableArray <TextSpan> .Empty,
                                          warningSpans : ImmutableArray <TextSpan> .Empty,
                                          navigationSpans : ImmutableArray <TextSpan> .Empty,
                                          expectedChangedDocumentId : testState.InvocationDocument.Id);
            }

            if (checkIfUsingsNotIncluded)
            {
                var oldSolution        = oldSolutionAndNewSolution.Item1;
                var newSolution        = oldSolutionAndNewSolution.Item2;
                var changedDocumentIds = SolutionUtilities.GetChangedDocuments(oldSolution, newSolution);

                Assert.False(changedDocumentIds.Contains(testState.InvocationDocument.Id));
            }

            // Added into a different project than the triggering project
            if (projectName != null)
            {
                var appliedChanges   = ApplyOperationsAndGetSolution(testState.Workspace, operations);
                var newSolution      = appliedChanges.Item2;
                var triggeredProject = newSolution.GetProject(testState.TriggeredProject.Id);

                // Make sure the Project reference is present
                Assert.True(triggeredProject.ProjectReferences.Any(pr => pr.ProjectId == testState.ProjectToBeModified.Id));
            }

            // Assert Option Calculation
            if (assertClassName != null)
            {
                Assert.True(assertClassName == testState.TestGenerateTypeOptionsService.ClassName);
            }

            if (assertGenerateTypeDialogOptions != null || assertTypeKindPresent != null || assertTypeKindAbsent != null)
            {
                var generateTypeDialogOptions = testState.TestGenerateTypeOptionsService.GenerateTypeDialogOptions;

                if (assertGenerateTypeDialogOptions != null)
                {
                    Assert.True(assertGenerateTypeDialogOptions.IsPublicOnlyAccessibility == generateTypeDialogOptions.IsPublicOnlyAccessibility);
                    Assert.True(assertGenerateTypeDialogOptions.TypeKindOptions == generateTypeDialogOptions.TypeKindOptions);
                    Assert.True(assertGenerateTypeDialogOptions.IsAttribute == generateTypeDialogOptions.IsAttribute);
                }

                if (assertTypeKindPresent != null)
                {
                    foreach (var typeKindPresentEach in assertTypeKindPresent)
                    {
                        Assert.True((typeKindPresentEach & generateTypeDialogOptions.TypeKindOptions) != 0);
                    }
                }

                if (assertTypeKindAbsent != null)
                {
                    foreach (var typeKindPresentEach in assertTypeKindAbsent)
                    {
                        Assert.True((typeKindPresentEach & generateTypeDialogOptions.TypeKindOptions) == 0);
                    }
                }
            }
        }
Exemple #16
0
        public async Task CustomizableTagsForUnnecessaryCode()
        {
            var workspaceXml =
                @"<Workspace>
    <Project Language=""C#"" CommonReferences=""true"">
        <Document FilePath = ""Test.cs"" >
// System is used - rest are unused.
using System.Collections;
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Program
{
    void Test()
    {
        Int32 x = 2; // Int32 can be simplified.
        x += 1;
    }
}
        </Document>
    </Project>
</Workspace>";

            using var workspace = TestWorkspace.Create(workspaceXml, composition: SquiggleUtilities.CompositionWithSolutionCrawler);
            var options  = new Dictionary <OptionKey2, object>();
            var language = workspace.Projects.Single().Language;
            var preferIntrinsicPredefinedTypeOption      = new OptionKey2(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration, language);
            var preferIntrinsicPredefinedTypeOptionValue = new CodeStyleOption2 <bool>(value: true, notification: NotificationOption2.Error);

            options.Add(preferIntrinsicPredefinedTypeOption, preferIntrinsicPredefinedTypeOptionValue);

            workspace.ApplyOptions(options);

            var analyzerMap = new Dictionary <string, ImmutableArray <DiagnosticAnalyzer> >
            {
                {
                    LanguageNames.CSharp,
                    ImmutableArray.Create <DiagnosticAnalyzer>(
                        new CSharpSimplifyTypeNamesDiagnosticAnalyzer(),
                        new CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer(),
                        new ReportOnClassWithLink())
                }
            };

            var diagnosticsAndSpans = await TestDiagnosticTagProducer <DiagnosticsSquiggleTaggerProvider> .GetDiagnosticsAndErrorSpans(workspace, analyzerMap);

            var spans =
                diagnosticsAndSpans.Item1
                .Zip(diagnosticsAndSpans.Item2, (diagnostic, span) => (diagnostic, span))
                .OrderBy(s => s.span.Span.Span.Start).ToImmutableArray();

            Assert.Equal(4, spans.Length);
            var first  = spans[0].span;
            var second = spans[1].span;
            var third  = spans[2].span;
            var fourth = spans[3].span;

            var expectedToolTip = new ContainerElement(
                ContainerElementStyle.Wrapped,
                new ClassifiedTextElement(
                    new ClassifiedTextRun(ClassificationTypeNames.Text, "IDE0005"),
                    new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"),
                    new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
                    new ClassifiedTextRun(ClassificationTypeNames.Text, CSharpAnalyzersResources.Using_directive_is_unnecessary)));

            Assert.Equal(PredefinedErrorTypeNames.Suggestion, first.Tag.ErrorType);
            ToolTipAssert.EqualContent(expectedToolTip, first.Tag.ToolTipContent);
            Assert.Equal(40, first.Span.Start);
            Assert.Equal(25, first.Span.Length);

            expectedToolTip = new ContainerElement(
                ContainerElementStyle.Wrapped,
                new ClassifiedTextElement(
                    new ClassifiedTextRun(ClassificationTypeNames.Text, "IDE0005"),
                    new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"),
                    new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
                    new ClassifiedTextRun(ClassificationTypeNames.Text, CSharpAnalyzersResources.Using_directive_is_unnecessary)));

            Assert.Equal(PredefinedErrorTypeNames.Suggestion, second.Tag.ErrorType);
            ToolTipAssert.EqualContent(expectedToolTip, second.Tag.ToolTipContent);
            Assert.Equal(82, second.Span.Start);
            Assert.Equal(60, second.Span.Length);

            expectedToolTip = new ContainerElement(
                ContainerElementStyle.Wrapped,
                new ClassifiedTextElement(
                    new ClassifiedTextRun(ClassificationTypeNames.Text, "id", QuickInfoHyperLink.TestAccessor.CreateNavigationAction(new Uri("https://github.com/dotnet/roslyn", UriKind.Absolute)), "https://github.com/dotnet/roslyn"),
                    new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"),
                    new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
                    new ClassifiedTextRun(ClassificationTypeNames.Text, "messageFormat")));

            Assert.Equal(PredefinedErrorTypeNames.Warning, third.Tag.ErrorType);
            ToolTipAssert.EqualContent(expectedToolTip, third.Tag.ToolTipContent);
            Assert.Equal(152, third.Span.Start);
            Assert.Equal(7, third.Span.Length);

            expectedToolTip = new ContainerElement(
                ContainerElementStyle.Wrapped,
                new ClassifiedTextElement(
                    new ClassifiedTextRun(ClassificationTypeNames.Text, "IDE0049"),
                    new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"),
                    new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
                    new ClassifiedTextRun(ClassificationTypeNames.Text, WorkspacesResources.Name_can_be_simplified)));

            Assert.Equal(PredefinedErrorTypeNames.SyntaxError, fourth.Tag.ErrorType);
            ToolTipAssert.EqualContent(expectedToolTip, fourth.Tag.ToolTipContent);
            Assert.Equal(196, fourth.Span.Start);
            Assert.Equal(5, fourth.Span.Length);
        }
 protected override TestWorkspace CreateWorkspace(string markup, ParseOptions options)
 => TestWorkspace.Create(
     NoCompilationConstants.LanguageName, compilationOptions: null, parseOptions: options, content: markup);
Exemple #18
0
 protected Task <TestLspServer> CreateMultiProjectLspServerAsync(string xmlMarkup)
 => CreateTestLspServerAsync(TestWorkspace.Create(xmlMarkup, composition: Composition), WellKnownLspServerKinds.AlwaysActiveVSLspServer);