• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Workspaces.TestHostProject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestHostProject的典型用法代码示例。如果您正苦于以下问题:C# TestHostProject类的具体用法?C# TestHostProject怎么用?C# TestHostProject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TestHostProject类属于Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces命名空间,在下文中一共展示了TestHostProject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestEmptySolutionUpdateDoesNotFireEvents

        public async Task TestEmptySolutionUpdateDoesNotFireEvents()
        {
            using (var workspace = CreateWorkspace())
            {
                var project = new TestHostProject(workspace);
                workspace.AddTestProject(project);

                // wait for all previous operations to complete
                await WaitForWorkspaceOperationsToComplete(workspace);

                var solution = workspace.CurrentSolution;
                bool workspaceChanged = false;

                workspace.WorkspaceChanged += (s, e) => workspaceChanged = true;

                // make an 'empty' update by claiming something changed, but its the same as before
                workspace.OnParseOptionsChanged(project.Id, project.ParseOptions);

                // wait for any new outstanding operations to complete (there shouldn't be any)
                await WaitForWorkspaceOperationsToComplete(workspace);

                // same solution instance == nothing changed
                Assert.Equal(solution, workspace.CurrentSolution);

                // no event was fired because nothing was changed
                Assert.False(workspaceChanged);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:WorkspaceTests.cs


示例2: TestRemoveExistingProject1

        public void TestRemoveExistingProject1()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var project = new TestHostProject(workspace);

                workspace.AddTestProject(project);
                workspace.OnProjectRemoved(project.Id);
                solution = workspace.CurrentSolution;

                Assert.Equal(0, solution.Projects.Count());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:15,代码来源:WorkspaceTests.cs


示例3: TestAddProject

        public void TestAddProject()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                Assert.Equal(0, solution.Projects.Count());

                var project = new TestHostProject(workspace);

                workspace.AddTestProject(project);
                solution = workspace.CurrentSolution;

                Assert.Equal(1, solution.Projects.Count());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:16,代码来源:WorkspaceTests.cs


示例4: TestEmptySolutionUpdate

        public void TestEmptySolutionUpdate()
        {
            using (var workspace = CreateWorkspace())
            {
                var project = new TestHostProject(workspace);
                workspace.AddTestProject(project);
                var solution = workspace.CurrentSolution;
                bool workspaceChanged = false;
                workspace.WorkspaceChanged += (s, e) => workspaceChanged = true;

                workspace.OnParseOptionsChanged(project.Id, project.ParseOptions);
                WaitForWorkspaceOperationsToComplete(workspace);

                Assert.Equal(solution, workspace.CurrentSolution);
                Assert.False(workspaceChanged);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:17,代码来源:WorkspaceTests.cs


示例5: TestChangeOptions1

        public async Task TestChangeOptions1()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var document = new TestHostDocument(
@"#if FOO
class C { }
#else
class D { }
#endif");

                var project1 = new TestHostProject(workspace, document, name: "project1");

                workspace.AddTestProject(project1);

                await VerifyRootTypeNameAsync(workspace, "D");

                workspace.OnParseOptionsChanged(document.Id.ProjectId,
                    new CSharpParseOptions(preprocessorSymbols: new[] { "FOO" }));

                await VerifyRootTypeNameAsync(workspace, "C");
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:WorkspaceTests.cs


示例6: TestGetCompilationOnCrossLanguageDependentProjectChanged

        public void TestGetCompilationOnCrossLanguageDependentProjectChanged()
        {
            using (var workspace = CreateWorkspace())
            {
                var solutionX = workspace.CurrentSolution;

                var document1 = new TestHostDocument(@"public class C { }");
                var project1 = new TestHostProject(workspace, document1, name: "project1");

                var document2 = new TestHostDocument("Public Class D \r\n  Inherits C\r\nEnd Class");
                var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 });

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                var solutionY = workspace.CurrentSolution;
                var id1 = solutionY.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = solutionY.Projects.First(p => p.Name == project2.Name).Id;

                var compilation2 = solutionY.GetProject(id2).GetCompilationAsync().Result;
                var errors = compilation2.GetDiagnostics();
                var classD = compilation2.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                var classC = classD.BaseType;
                Assert.NotEqual(TypeKind.Error, classC.TypeKind);

                // change the class name in document1
                workspace.OnDocumentOpened(document1.Id, document1.GetOpenTextContainer());
                var buffer1 = document1.GetTextBuffer();

                // change C to X
                buffer1.Replace(new Span(13, 1), "X");

                // this solution should have the change
                var solutionZ = workspace.CurrentSolution;
                var docZ = solutionZ.GetDocument(document1.Id);
                var docZText = docZ.GetTextAsync().PumpingWaitResult();

                var compilation2Z = solutionZ.GetProject(id2).GetCompilationAsync().Result;
                var classDz = compilation2Z.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                var classCz = classDz.BaseType;

                Assert.Equal(TypeKind.Error, classCz.TypeKind);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:44,代码来源:WorkspaceTests.cs


示例7: TestGetCompilationOnCrossLanguageDependentProjectChangedInProgress

        public void TestGetCompilationOnCrossLanguageDependentProjectChangedInProgress()
        {
            using (var workspace = CreateWorkspace(disablePartialSolutions: false))
            {
                var solutionX = workspace.CurrentSolution;

                var document1 = new TestHostDocument(@"public class C { }");
                var project1 = new TestHostProject(workspace, document1, name: "project1");

                var document2 = new TestHostDocument("Public Class D \r\n  Inherits C\r\nEnd Class");
                var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 });

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                var solutionY = workspace.CurrentSolution;
                var id1 = solutionY.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = solutionY.Projects.First(p => p.Name == project2.Name).Id;

                var compilation2y = solutionY.GetProject(id2).GetCompilationAsync().Result;
                var errors = compilation2y.GetDiagnostics();
                var classDy = compilation2y.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                var classCy = classDy.BaseType;
                Assert.NotEqual(TypeKind.Error, classCy.TypeKind);

                // open both documents so background compiler works on their compilations
                workspace.OnDocumentOpened(document1.Id, document1.GetOpenTextContainer());
                workspace.OnDocumentOpened(document2.Id, document2.GetOpenTextContainer());

                // change C to X
                var buffer1 = document1.GetTextBuffer();
                buffer1.Replace(new Span(13, 1), "X");

                var foundTheError = false;
                for (int iter = 0; iter < 10; iter++)
                {
                    WaitHelper.WaitForDispatchedOperationsToComplete(System.Windows.Threading.DispatcherPriority.ApplicationIdle);
                    Thread.Sleep(1000);

                    // the current solution should eventually have the change
                    var cs = workspace.CurrentSolution;
                    var doc1Z = cs.GetDocument(document1.Id);
                    var hasX = doc1Z.GetTextAsync().Result.ToString().Contains("X");

                    if (hasX)
                    {
                        var doc2Z = cs.GetDocument(document2.Id);
                        var partialDoc2Z = doc2Z.WithFrozenPartialSemanticsAsync(CancellationToken.None).Result;
                        var compilation2Z = partialDoc2Z.Project.GetCompilationAsync().Result;
                        var classDz = compilation2Z.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                        var classCz = classDz.BaseType;

                        if (classCz.TypeKind == TypeKind.Error)
                        {
                            foundTheError = true;
                            break;
                        }
                    }
                }

                Assert.True(foundTheError, "Did not find error");
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:63,代码来源:WorkspaceTests.cs


示例8: TestGetCompilationOnDependentProject

        public async Task TestGetCompilationOnDependentProject()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var document1 = new TestHostDocument(@"public class C { }");
                var project1 = new TestHostProject(workspace, document1, name: "project1");

                var document2 = new TestHostDocument(@"class D : C { }");
                var project2 = new TestHostProject(workspace, document2, name: "project2", projectReferences: new[] { project1 });

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                var snapshot = workspace.CurrentSolution;
                var id1 = snapshot.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = snapshot.Projects.First(p => p.Name == project2.Name).Id;

                var compilation2 = await snapshot.GetProject(id2).GetCompilationAsync();
                var classD = compilation2.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                var classC = classD.BaseType;
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:24,代码来源:WorkspaceTests.cs


示例9: TestGetCompilationOnCrossLanguageDependentProject

        public void TestGetCompilationOnCrossLanguageDependentProject()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var document1 = new TestHostDocument(@"public class C { }");
                var project1 = new TestHostProject(workspace, document1, name: "project1");

                var document2 = new TestHostDocument("Public Class D \r\n  Inherits C\r\nEnd Class");
                var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 });

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                var snapshot = workspace.CurrentSolution;
                var id1 = snapshot.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = snapshot.Projects.First(p => p.Name == project2.Name).Id;

                var compilation2 = snapshot.GetProject(id2).GetCompilationAsync().Result;
                var classD = compilation2.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                var classC = classD.BaseType;
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:24,代码来源:WorkspaceTests.cs


示例10: TestApplyChangesWithDocumentAdded

        public void TestApplyChangesWithDocumentAdded()
        {
            using (var workspace = CreateWorkspace())
            {
                var doc1Text = "public class C { }";
                var doc2Text = "public class D { }";

                var document = new TestHostDocument(doc1Text);
                var project1 = new TestHostProject(workspace, document, name: "project1");

                workspace.AddTestProject(project1);

                // fork the solution to introduce a change.
                var oldSolution = workspace.CurrentSolution;
                var newSolution = oldSolution.AddDocument(DocumentId.CreateNewId(project1.Id), "Doc2", SourceText.From(doc2Text));

                workspace.TryApplyChanges(newSolution);

                // new document should have been added.
                Assert.Equal(2, workspace.CurrentSolution.GetProject(project1.Id).Documents.Count());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:22,代码来源:WorkspaceTests.cs


示例11: TestDocumentEvents

        public void TestDocumentEvents()
        {
            using (var workspace = CreateWorkspace())
            {
                var doc1Text = "public class C { }";
                var document = new TestHostDocument(doc1Text);
                var project1 = new TestHostProject(workspace, document, name: "project1");
                var longEventTimeout = TimeSpan.FromMinutes(5);
                var shortEventTimeout = TimeSpan.FromSeconds(5);

                workspace.AddTestProject(project1);

                // Creating two waiters that will allow us to know for certain if the events have fired.
                using (var closeWaiter = new EventWaiter())
                using (var openWaiter = new EventWaiter())
                {
                    // Wrapping event handlers so they can notify us on being called.
                    var documentOpenedEventHandler = openWaiter.Wrap<DocumentEventArgs>(
                        (sender, args) => Assert.True(args.Document.Id == document.Id,
                        "The document given to the 'DocumentOpened' event handler did not have the same id as the one created for the test."));

                    var documentClosedEventHandler = closeWaiter.Wrap<DocumentEventArgs>(
                        (sender, args) => Assert.True(args.Document.Id == document.Id,
                        "The document given to the 'DocumentClosed' event handler did not have the same id as the one created for the test."));

                    workspace.DocumentOpened += documentOpenedEventHandler;
                    workspace.DocumentClosed += documentClosedEventHandler;

                    workspace.OpenDocument(document.Id);
                    workspace.CloseDocument(document.Id);

                    // Wait for all workspace tasks to finish.  After this is finished executing, all handlers should have been notified.
                    WaitForWorkspaceOperationsToComplete(workspace);

                    // Wait to recieve signal that events have fired.
                    Assert.True(openWaiter.WaitForEventToFire(longEventTimeout),
                                            string.Format("event 'DocumentOpened' was not fired within {0} minutes.",
                                            longEventTimeout.Minutes));

                    Assert.True(closeWaiter.WaitForEventToFire(longEventTimeout),
                                            string.Format("event 'DocumentClosed' was not fired within {0} minutes.",
                                            longEventTimeout.Minutes));

                    workspace.DocumentOpened -= documentOpenedEventHandler;
                    workspace.DocumentClosed -= documentClosedEventHandler;

                    workspace.OpenDocument(document.Id);
                    workspace.CloseDocument(document.Id);

                    // Wait for all workspace tasks to finish.  After this is finished executing, all handlers should have been notified.
                    WaitForWorkspaceOperationsToComplete(workspace);

                    // Verifiying that an event has not been called is difficult to prove.  
                    // All events should have already been called so we wait 5 seconds and then assume the event handler was removed correctly. 
                    Assert.False(openWaiter.WaitForEventToFire(shortEventTimeout),
                                            string.Format("event handler 'DocumentOpened' was called within {0} seconds though it was removed from the list.",
                                            shortEventTimeout.Seconds));

                    Assert.False(closeWaiter.WaitForEventToFire(shortEventTimeout),
                                            string.Format("event handler 'DocumentClosed' was called within {0} seconds though it was removed from the list.",
                                            shortEventTimeout.Seconds));
                }
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:64,代码来源:WorkspaceTests.cs


示例12: TestRemoveP2PReference1

        public void TestRemoveP2PReference1()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var project1 = new TestHostProject(workspace, name: "project1");
                var project2 = new TestHostProject(workspace, name: "project2");

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                workspace.OnProjectReferenceAdded(project1.Id, new ProjectReference(project2.Id));
                workspace.OnProjectReferenceRemoved(project1.Id, new ProjectReference(project2.Id));

                var snapshot = workspace.CurrentSolution;
                var id1 = snapshot.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = snapshot.Projects.First(p => p.Name == project2.Name).Id;

                Assert.Equal(0, snapshot.GetProject(id1).ProjectReferences.Count());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:22,代码来源:WorkspaceTests.cs


示例13: TestAddP2PReferenceCircularity

        public void TestAddP2PReferenceCircularity()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var project1 = new TestHostProject(workspace, name: "project1");
                var project2 = new TestHostProject(workspace, name: "project2");

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                workspace.OnProjectReferenceAdded(project1.Id, new ProjectReference(project2.Id));

                Assert.Throws<ArgumentException>(() => workspace.OnProjectReferenceAdded(project2.Id, new ProjectReference(project1.Id)));
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:17,代码来源:WorkspaceTests.cs


示例14: TestChangeOptions2

        public void TestChangeOptions2()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var document = new TestHostDocument(
@"#if FOO
class C { }
#else
class D { }
#endif");

                var project1 = new TestHostProject(workspace, document, name: "project1");

                workspace.AddTestProject(project1);
                workspace.OnDocumentOpened(document.Id, document.GetOpenTextContainer());

                VerifyRootTypeName(workspace, "D");

                workspace.OnParseOptionsChanged(document.Id.ProjectId,
                    new CSharpParseOptions(preprocessorSymbols: new[] { "FOO" }));

                VerifyRootTypeName(workspace, "C");

                workspace.OnDocumentClosed(document.Id);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:28,代码来源:WorkspaceTests.cs


示例15: TestAddP2PReference1

        public void TestAddP2PReference1()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var project1 = new TestHostProject(workspace, name: "project1");
                var project2 = new TestHostProject(workspace, name: "project2");

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                var reference = new ProjectReference(project2.Id);
                workspace.OnProjectReferenceAdded(project1.Id, reference);

                var snapshot = workspace.CurrentSolution;
                var id1 = snapshot.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = snapshot.Projects.First(p => p.Name == project2.Name).Id;

                Assert.True(snapshot.GetProject(id1).ProjectReferences.Contains(reference), "ProjectReferences did not contain project2");
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:22,代码来源:WorkspaceTests.cs


示例16: TestRemoveNonAddedProject2

        public void TestRemoveNonAddedProject2()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var project1 = new TestHostProject(workspace, name: "project1");
                var project2 = new TestHostProject(workspace, name: "project2");

                workspace.AddTestProject(project1);

                Assert.Throws<ArgumentException>(() => workspace.OnProjectRemoved(project2.Id));
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:14,代码来源:WorkspaceTests.cs


示例17: TestAddedSubmissionParseTreeHasEmptyFilePath

        public async void TestAddedSubmissionParseTreeHasEmptyFilePath()
        {
            using (var workspace = CreateWorkspace())
            {
                var document1 = new TestHostDocument("var x = 1;", displayName: "Sub1", sourceCodeKind: SourceCodeKind.Script);
                var project1 = new TestHostProject(workspace, document1, name: "Submission");

                var document2 = new TestHostDocument("var x = 2;", displayName: "Sub2", sourceCodeKind: SourceCodeKind.Script, filePath: "a.csx");
                var project2 = new TestHostProject(workspace, document2, name: "Script");

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                workspace.TryApplyChanges(workspace.CurrentSolution);

                // Check that a parse tree for a submission has an empty file path.
                SyntaxTree tree1 = await workspace.CurrentSolution
                    .GetProjectState(project1.Id)
                    .GetDocumentState(document1.Id)
                    .GetSyntaxTreeAsync(CancellationToken.None);
                Assert.Equal("", tree1.FilePath);

                // Check that a parse tree for a script does not have an empty file path.
                SyntaxTree tree2 = await workspace.CurrentSolution
                    .GetProjectState(project2.Id)
                    .GetDocumentState(document2.Id)
                    .GetSyntaxTreeAsync(CancellationToken.None);
                Assert.Equal("a.csx", tree2.FilePath);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:30,代码来源:WorkspaceTests.cs


示例18: TestDependentSemanticVersionChangesWhenNotOriginallyAccessed

        public async Task TestDependentSemanticVersionChangesWhenNotOriginallyAccessed()
        {
            using (var workspace = CreateWorkspace(disablePartialSolutions: false))
            {
                var solutionX = workspace.CurrentSolution;

                var document1 = new TestHostDocument(@"public class C { }");
                var project1 = new TestHostProject(workspace, document1, name: "project1");

                var document2 = new TestHostDocument("Public Class D \r\n  Inherits C\r\nEnd Class");
                var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 });

                workspace.AddTestProject(project1);
                workspace.AddTestProject(project2);

                var solutionY = workspace.CurrentSolution;
                var id1 = solutionY.Projects.First(p => p.Name == project1.Name).Id;
                var id2 = solutionY.Projects.First(p => p.Name == project2.Name).Id;

                var compilation2y = await solutionY.GetProject(id2).GetCompilationAsync();
                var errors = compilation2y.GetDiagnostics();
                var classDy = compilation2y.SourceModule.GlobalNamespace.GetTypeMembers("D").Single();
                var classCy = classDy.BaseType;
                Assert.NotEqual(TypeKind.Error, classCy.TypeKind);

                // open both documents so background compiler works on their compilations
                workspace.OnDocumentOpened(document1.Id, document1.GetOpenTextContainer());
                workspace.OnDocumentOpened(document2.Id, document2.GetOpenTextContainer());

                // change C to X
                var buffer1 = document1.GetTextBuffer();
                buffer1.Replace(new Span(13, 1), "X");

                for (int iter = 0; iter < 10; iter++)
                {
                    WaitHelper.WaitForDispatchedOperationsToComplete(System.Windows.Threading.DispatcherPriority.ApplicationIdle);
                    Thread.Sleep(1000);

                    // the current solution should eventually have the change
                    var cs = workspace.CurrentSolution;
                    var doc1Z = cs.GetDocument(document1.Id);
                    var hasX = (await doc1Z.GetTextAsync()).ToString().Contains("X");

                    if (hasX)
                    {
                        var newVersion = await cs.GetProject(project1.Id).GetDependentSemanticVersionAsync();
                        var newVersionX = await doc1Z.Project.GetDependentSemanticVersionAsync();
                        Assert.NotEqual(VersionStamp.Default, newVersion);
                        Assert.Equal(newVersion, newVersionX);
                        break;
                    }
                }
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:54,代码来源:WorkspaceTests.cs


示例19: TestOpenAndChangeDocument

        public void TestOpenAndChangeDocument()
        {
            using (var workspace = CreateWorkspace())
            {
                var solution = workspace.CurrentSolution;

                var document = new TestHostDocument(string.Empty);
                var project1 = new TestHostProject(workspace, document, name: "project1");

                workspace.AddTestProject(project1);
                var buffer = document.GetTextBuffer();
                workspace.OnDocumentOpened(document.Id, document.GetOpenTextContainer());

                buffer.Insert(0, "class C {}");

                solution = workspace.CurrentSolution;
                var doc = solution.Projects.Single().Documents.First();

                var syntaxTree = doc.GetSyntaxTreeAsync(CancellationToken.None).Result;
                Assert.True(syntaxTree.GetRoot().Width() > 0, "syntaxTree.GetRoot().Width should be > 0");

                workspace.OnDocumentClosed(document.Id);
                workspace.OnProjectRemoved(project1.Id);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:25,代码来源:WorkspaceTests.cs


示例20: TestAdditionalFile_Properties

        public void TestAdditionalFile_Properties()
        {
            using (var workspace = CreateWorkspace())
            {
                var document = new TestHostDocument("public class C { }");
                var additionalDoc = new TestHostDocument("some text");
                var project1 = new TestHostProject(workspace, name: "project1", documents: new[] { document }, additionalDocuments: new[] { additionalDoc });

                workspace.AddTestProject(project1);

                var project = workspace.CurrentSolution.Projects.Single();

                Assert.Equal(1, project.Documents.Count());
                Assert.Equal(1, project.AdditionalDocuments.Count());
                Assert.Equal(1, project.AdditionalDocumentIds.Count);

                var doc = project.GetDocument(additionalDoc.Id);
                Assert.Null(doc);

                var additionalDocument = project.GetAdditionalDocument(additionalDoc.Id);

                Assert.Equal("some text", additionalDocument.GetTextAsync().PumpingWaitResult().ToString());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:24,代码来源:WorkspaceTests.cs



注:本文中的Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestHostProject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Workspaces.TestWorkspace类代码示例发布时间:2022-05-26
下一篇:
C# Workspaces.TestHostDocument类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap