Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using Xunit.Abstractions;
  7.  
  8. namespace MagicalUnicorns {
  9. public class XunitConsoleForwarder : TextWriter {
  10. private readonly ITestOutputHelper output;
  11.  
  12. private IList<char> line = new List<char>();
  13.  
  14. public XunitConsoleForwarder(ITestOutputHelper output) {
  15. this.output = output;
  16. }
  17.  
  18. public override Encoding Encoding => Console.Out.Encoding;
  19.  
  20. public override void Write(char value) {
  21. if (value == '\n') {
  22. FlushLine();
  23. line = new List<char>();
  24. return;
  25. }
  26.  
  27. line.Add(value);
  28. }
  29.  
  30. protected override void Dispose(bool disposing) {
  31. if (line.Count > 0) {
  32. FlushLine();
  33. }
  34.  
  35. base.Dispose(disposing);
  36. }
  37.  
  38. private void FlushLine() {
  39. if (line.Count > 0 && line.Last() == '\r') {
  40. line.RemoveAt(line.Count - 1);
  41. }
  42.  
  43. output.WriteLine(new string(line.ToArray()));
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement