public async Task TestRetrieveAsync() { var textFactory = new TextFactoryServiceFactory.TextFactoryService(); var tempStorageService = new TemporaryStorageServiceFactory.TemporaryStorageService(textFactory); var syntaxTreeStorageService = new SyntaxTreeStorageService(); var tree = CSharp.SyntaxFactory.ParseSyntaxTree("namespace A { class C {"); var root = tree.GetRoot(); syntaxTreeStorageService.Store(tree, root, tempStorageService, CancellationToken.None); Assert.True(syntaxTreeStorageService.CanRetrieve(tree)); var syntaxFactoryService = new CSharp.CSharpSyntaxTreeFactoryServiceFactory().CreateLanguageService(provider: null) as ISyntaxTreeFactoryService; var newRoot = await syntaxTreeStorageService.RetrieveAsync(tree, syntaxFactoryService, CancellationToken.None); Assert.True(root.IsEquivalentTo(newRoot)); // we can't directly compare diagnostics since location in the diagnostic will point to two different trees AssertEx.SetEqual(root.GetDiagnostics().Select(d => d.ToString()), newRoot.GetDiagnostics().Select(d => d.ToString())); }
public async Task TestRetrieveAsync() { var textFactory = new TextFactoryServiceFactory.TextFactoryService(); var tempStorageService = new TemporaryStorageServiceFactory.TemporaryStorageService(textFactory); var syntaxTreeStorageService = new SyntaxTreeStorageService(); var tree = CSharp.SyntaxFactory.ParseSyntaxTree("namespace A { class C {"); var root = tree.GetRoot(); syntaxTreeStorageService.Store(tree, root, tempStorageService, CancellationToken.None); Assert.True(syntaxTreeStorageService.CanRetrieve(tree)); var syntaxFactoryService = new CSharp.CSharpSyntaxTreeFactoryServiceFactory().CreateLanguageService(provider: null) as ISyntaxTreeFactoryService; var newRoot = await syntaxTreeStorageService.RetrieveAsync(tree, syntaxFactoryService, CancellationToken.None).ConfigureAwait(false); Assert.True(root.IsEquivalentTo(newRoot)); // we can't directly compare diagnostics since location in the diagnostic will point to two different trees AssertEx.SetEqual(root.GetDiagnostics().Select(d => d.ToString()), newRoot.GetDiagnostics().Select(d => d.ToString())); }