DiffPlexReporter.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7. using DiffPlex;
  8. using DiffPlex.DiffBuilder;
  9. using DiffPlex.DiffBuilder.Model;
  10. namespace ReactiveTests.Tests
  11. {
  12. public static class DiffPlexReporter
  13. {
  14. public static async Task Report(string receivedFile, string verifiedFile)
  15. {
  16. #if(!DEBUG)
  17. var receivedText = File.ReadAllText(receivedFile);
  18. var verifiedText = File.ReadAllText(verifiedFile);
  19. var diffBuilder = new InlineDiffBuilder(new Differ());
  20. var diff = diffBuilder.BuildDiffModel(verifiedText, receivedText);
  21. foreach (var line in diff.Lines)
  22. {
  23. if (line.Type == ChangeType.Unchanged) continue;
  24. var prefix = " ";
  25. switch (line.Type)
  26. {
  27. case ChangeType.Inserted:
  28. prefix = "+ ";
  29. break;
  30. case ChangeType.Deleted:
  31. prefix = "- ";
  32. break;
  33. }
  34. Console.WriteLine("{0}{1}", prefix, line.Text);
  35. }
  36. #endif
  37. }
  38. }
  39. }