public async Task LoadTextAsyncTest() { var target = new TxtFile(ValidTxtFilePath); var expected = await new StreamReader(target.FullPath).ReadToEndAsync(); var actual = await target.LoadTextAsync(); Check.That(actual).IsEqualTo(expected); }
/// <summary> /// Asynchronously loads the text of the given file into a new preview tab, displaying it with some rudimentary formatting. /// </summary> /// <param name="textfile">The Text File from which to load text.</param> /// <returns>A System.Threading.Tasks.Task representing the ongoing asynchronous operation.</returns> private async Task LoadTextandTabAsync(TxtFile textfile) { var text = await textfile.LoadTextAsync(); var processedText = string.Join("\t", from displayChunk in text.SplitRemoveEmpty("\r\n\r\n", "\r\n", "\n\",", "<paragraph>", "</paragraph>") select displayChunk.Trim()); var block = new System.Windows.Documents.Section( new System.Windows.Documents.Paragraph( new System.Windows.Documents.Run { Text = processedText }) { TextAlignment = TextAlignment.Left }) { TextAlignment = TextAlignment.Left, BreakColumnBefore = false }; var item = new TabItem { Header = textfile.NameSansExt, AllowDrop = true, Content = new FlowDocumentPageViewer { VerticalContentAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Left, HorizontalContentAlignment = HorizontalAlignment.Left, Document = new System.Windows.Documents.FlowDocument( new System.Windows.Documents.Paragraph( new System.Windows.Documents.Run( processedText ) ) ) } }; VisualTextRenderingMode = System.Windows.Media.TextRenderingMode.ClearType; item.Drop += Grid_Drop; DocumentPreview.Items.Add(item); DocumentPreview.SelectedItem = item; }