本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.OnSolutionAdded方法的典型用法代码示例。如果您正苦于以下问题:C# TestWorkspace.OnSolutionAdded方法的具体用法?C# TestWorkspace.OnSolutionAdded怎么用?C# TestWorkspace.OnSolutionAdded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace
的用法示例。
在下文中一共展示了TestWorkspace.OnSolutionAdded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solution_Remove
public void Solution_Remove()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var worker = ExecuteOperation(workspace, w => w.OnSolutionRemoved());
Assert.Equal(10, worker.InvalidateDocumentIds.Count);
}
}
示例2: ProgressReporterTest
public void ProgressReporterTest()
{
var solution = GetInitialSolutionInfoWithP2P();
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
WaitWaiter(workspace.ExportProvider);
var service = workspace.Services.GetService<ISolutionCrawlerService>();
var reporter = service.GetProgressReporter(workspace);
Assert.False(reporter.InProgress);
// set up events
bool started = false;
reporter.Started += (o, a) => { started = true; };
bool stopped = false;
reporter.Stopped += (o, a) => { stopped = true; };
var registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
registrationService.Register(workspace);
// first mutation
workspace.OnSolutionAdded(solution);
Wait((SolutionCrawlerRegistrationService)registrationService, workspace);
Assert.True(started);
Assert.True(stopped);
// reset
started = false;
stopped = false;
// second mutation
workspace.OnDocumentAdded(DocumentInfo.Create(DocumentId.CreateNewId(solution.Projects[0].Id), "D6"));
Wait((SolutionCrawlerRegistrationService)registrationService, workspace);
Assert.True(started);
Assert.True(stopped);
registrationService.Unregister(workspace);
}
}
示例3: Document_InvocationReasons
public void Document_InvocationReasons()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var id = workspace.CurrentSolution.Projects.First().DocumentIds[0];
var analyzer = new Analyzer(blockedRun: true);
var lazyWorker = new Lazy<IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>(() => new AnalyzerProvider(analyzer), Metadata.Crawler);
var service = new SolutionCrawlerRegistrationService(new[] { lazyWorker }, GetListeners(workspace.ExportProvider));
service.Register(workspace);
// first invocation will block worker
workspace.ChangeDocument(id, SourceText.From("//"));
analyzer.RunningEvent.Wait();
var openReady = new ManualResetEventSlim(initialState: false);
var closeReady = new ManualResetEventSlim(initialState: false);
workspace.DocumentOpened += (o, e) => openReady.Set();
workspace.DocumentClosed += (o, e) => closeReady.Set();
// cause several different request to queue up
workspace.ChangeDocument(id, SourceText.From("// "));
workspace.OpenDocument(id);
workspace.CloseDocument(id);
openReady.Set();
closeReady.Set();
analyzer.BlockEvent.Set();
Wait(service, workspace);
service.Unregister(workspace);
Assert.Equal(1, analyzer.SyntaxDocumentIds.Count);
Assert.Equal(5, analyzer.DocumentIds.Count);
}
}
示例4: SemanticChange_Propagation
public void SemanticChange_Propagation()
{
var solution = GetInitialSolutionInfoWithP2P();
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var id = solution.Projects[0].Id;
var info = DocumentInfo.Create(DocumentId.CreateNewId(id), "D6");
var worker = ExecuteOperation(workspace, w => w.OnDocumentAdded(info));
Assert.Equal(1, worker.SyntaxDocumentIds.Count);
Assert.Equal(4, worker.DocumentIds.Count);
#if false
Assert.True(1 == worker.SyntaxDocumentIds.Count,
string.Format("Expected 1 SyntaxDocumentIds, Got {0}\n\n{1}", worker.SyntaxDocumentIds.Count, GetListenerTrace(workspace.ExportProvider)));
Assert.True(4 == worker.DocumentIds.Count,
string.Format("Expected 4 DocumentIds, Got {0}\n\n{1}", worker.DocumentIds.Count, GetListenerTrace(workspace.ExportProvider)));
#endif
}
}
示例5: Document_AdditionalFileChange
public void Document_AdditionalFileChange()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var project = solution.Projects[0];
var ncfile = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "D6");
var worker = ExecuteOperation(workspace, w => w.OnAdditionalDocumentAdded(ncfile));
Assert.Equal(5, worker.SyntaxDocumentIds.Count);
Assert.Equal(5, worker.DocumentIds.Count);
worker = ExecuteOperation(workspace, w => w.ChangeAdditionalDocument(ncfile.Id, SourceText.From("//")));
Assert.Equal(5, worker.SyntaxDocumentIds.Count);
Assert.Equal(5, worker.DocumentIds.Count);
worker = ExecuteOperation(workspace, w => w.OnAdditionalDocumentRemoved(ncfile.Id));
Assert.Equal(5, worker.SyntaxDocumentIds.Count);
Assert.Equal(5, worker.DocumentIds.Count);
}
}
示例6: Document_Cancellation_MultipleTimes
public void Document_Cancellation_MultipleTimes()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var id = workspace.CurrentSolution.Projects.First().DocumentIds[0];
var analyzer = new Analyzer(waitForCancellation: true);
var lazyWorker = new Lazy<IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>(() => new AnalyzerProvider(analyzer), Metadata.Crawler);
var service = new SolutionCrawlerRegistrationService(new[] { lazyWorker }, GetListeners(workspace.ExportProvider));
service.Register(workspace);
workspace.ChangeDocument(id, SourceText.From("//"));
analyzer.RunningEvent.Wait();
analyzer.RunningEvent.Reset();
workspace.ChangeDocument(id, SourceText.From("// "));
analyzer.RunningEvent.Wait();
workspace.ChangeDocument(id, SourceText.From("// "));
Wait(service, workspace);
service.Unregister(workspace);
Assert.Equal(1, analyzer.SyntaxDocumentIds.Count);
Assert.Equal(5, analyzer.DocumentIds.Count);
}
}
示例7: Document_Reanalyze
public void Document_Reanalyze()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var info = solution.Projects[0].Documents[0];
var worker = new Analyzer();
var lazyWorker = new Lazy<IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>(() => new AnalyzerProvider(worker), Metadata.Crawler);
var service = new SolutionCrawlerRegistrationService(new[] { lazyWorker }, GetListeners(workspace.ExportProvider));
service.Register(workspace);
// don't rely on background parser to have tree. explicitly do it here.
TouchEverything(workspace.CurrentSolution);
service.Reanalyze(workspace, worker, projectIds: null, documentIds: SpecializedCollections.SingletonEnumerable<DocumentId>(info.Id));
TouchEverything(workspace.CurrentSolution);
Wait(service, workspace);
service.Unregister(workspace);
Assert.Equal(1, worker.SyntaxDocumentIds.Count);
Assert.Equal(1, worker.DocumentIds.Count);
}
}
示例8: Document_Change
public void Document_Change()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var id = workspace.CurrentSolution.Projects.First().DocumentIds[0];
var worker = ExecuteOperation(workspace, w => w.ChangeDocument(id, SourceText.From("//")));
Assert.Equal(1, worker.SyntaxDocumentIds.Count);
}
}
示例9: Document_Add
public void Document_Add()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var project = solution.Projects[0];
var info = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "D6");
var worker = ExecuteOperation(workspace, w => w.OnDocumentAdded(info));
Assert.Equal(1, worker.SyntaxDocumentIds.Count);
Assert.Equal(6, worker.DocumentIds.Count);
}
}
示例10: Document_Reload
public void Document_Reload()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var id = solution.Projects[0].Documents[0];
var worker = ExecuteOperation(workspace, w => w.OnDocumentReloaded(id));
Assert.Equal(0, worker.SyntaxDocumentIds.Count);
}
}
示例11: Project_AnalyzerOptions_Change
public void Project_AnalyzerOptions_Change()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solutionInfo = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solutionInfo);
WaitWaiter(workspace.ExportProvider);
var project = workspace.CurrentSolution.Projects.First(p => p.Name == "P1").AddAdditionalDocument("a1", SourceText.From("")).Project;
var worker = ExecuteOperation(workspace, w => w.ChangeProject(project.Id, project.Solution));
Assert.Equal(5, worker.SyntaxDocumentIds.Count);
Assert.Equal(5, worker.DocumentIds.Count);
}
}
示例12: Project_Change
public void Project_Change()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solutionInfo = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solutionInfo);
WaitWaiter(workspace.ExportProvider);
var project = workspace.CurrentSolution.Projects.First();
var documentId = project.DocumentIds[0];
var solution = workspace.CurrentSolution.RemoveDocument(documentId);
var worker = ExecuteOperation(workspace, w => w.ChangeProject(project.Id, solution));
Assert.Equal(0, worker.SyntaxDocumentIds.Count);
Assert.Equal(1, worker.InvalidateDocumentIds.Count);
}
}
示例13: Project_Remove
public void Project_Remove()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var projectid = workspace.CurrentSolution.ProjectIds[0];
var worker = ExecuteOperation(workspace, w => w.OnProjectRemoved(projectid));
Assert.Equal(0, worker.SyntaxDocumentIds.Count);
Assert.Equal(5, worker.InvalidateDocumentIds.Count);
}
}
示例14: Project_Add
public void Project_Add()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solution);
WaitWaiter(workspace.ExportProvider);
var projectId = ProjectId.CreateNewId();
var projectInfo = ProjectInfo.Create(
projectId, VersionStamp.Create(), "P3", "P3", LanguageNames.CSharp,
documents: new List<DocumentInfo>
{
DocumentInfo.Create(DocumentId.CreateNewId(projectId), "D1"),
DocumentInfo.Create(DocumentId.CreateNewId(projectId), "D2")
});
var worker = ExecuteOperation(workspace, w => w.OnProjectAdded(projectInfo));
Assert.Equal(2, worker.SyntaxDocumentIds.Count);
}
}
示例15: Solution_Change
public void Solution_Change()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solutionInfo = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solutionInfo);
WaitWaiter(workspace.ExportProvider);
var solution = workspace.CurrentSolution;
var documentId = solution.Projects.First().DocumentIds[0];
solution = solution.RemoveDocument(documentId);
var changedSolution = solution.AddProject("P3", "P3", LanguageNames.CSharp).AddDocument("D1", "").Project.Solution;
var worker = ExecuteOperation(workspace, w => w.ChangeSolution(changedSolution));
Assert.Equal(1, worker.SyntaxDocumentIds.Count);
}
}