private async Task <(DocumentOutlineTestMocks mocks, DocumentSymbolDataModel model, ImmutableArray <DocumentSymbolUIItem> uiItems)> InitializeMocksAndDataModelAndUIItems(string testCode) { using var mocks = await CreateMocksAsync(testCode); var response = await DocumentOutlineHelper.DocumentSymbolsRequestAsync(mocks.TextBuffer, mocks.LanguageServiceBroker, mocks.FilePath, CancellationToken.None); AssertEx.NotNull(response.Value); var responseBody = response.Value.response?.ToObject <DocumentSymbol[]>(); AssertEx.NotNull(responseBody); var snapshot = response.Value.snapshot; AssertEx.NotNull(snapshot); var model = DocumentOutlineHelper.CreateDocumentSymbolDataModel(responseBody, snapshot); var uiItems = DocumentOutlineHelper.GetDocumentSymbolUIItems(model.DocumentSymbolData, mocks.ThreadingContext); return(mocks, model, uiItems); }
public async Task TestSetIsExpanded() { var(mocks, model, originalUIItems) = await InitializeMocksAndDataModelAndUIItems(TestCode); var updatedUIItems = DocumentOutlineHelper.GetDocumentSymbolUIItems(model.DocumentSymbolData, mocks.ThreadingContext); // Check that all updatedUIItems nodes are collapsed (originalUIItems parameter is unused) DocumentOutlineHelper.SetIsExpanded(updatedUIItems, originalUIItems, ExpansionOption.Collapse); CheckNodeExpansion(updatedUIItems, false); // Check that all updatedUIItems nodes are expanded (originalUIItems parameter is unused) DocumentOutlineHelper.SetIsExpanded(updatedUIItems, originalUIItems, ExpansionOption.Expand); CheckNodeExpansion(updatedUIItems, true); // Collapse 3 nodes in originalUIItems originalUIItems.Single(parent => parent.Name.Equals("App")).IsExpanded = false; originalUIItems.Single(parent => parent.Name.Equals("MyClass")).Children.Single(child => child.Name.Equals("Method2")).IsExpanded = false; originalUIItems.Single(parent => parent.Name.Equals("foo")).Children.Single(child => child.Name.Equals("r")).IsExpanded = false; // Apply same expansion as originalUIItems to updatedUIItems DocumentOutlineHelper.SetIsExpanded(updatedUIItems, originalUIItems, ExpansionOption.CurrentExpansion); // Confirm that matching expanded/collapsed node states have been applied CheckNodeExpansionMatches(updatedUIItems, originalUIItems);