PageRenderTime 40ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/UnitTests/GitUI.Tests/NBugReports/BugReportInvokerTests.cs

https://github.com/gitextensions/gitextensions
C# | 63 lines | 60 code | 3 blank | 0 comment | 0 complexity | 08cbf8b23fe038f232cf7838129350f2 MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using System.Collections;
  3. using System.Text;
  4. using FluentAssertions;
  5. using GitExtUtils;
  6. using GitUI.NBugReports;
  7. using NUnit.Framework;
  8. namespace GitUITests.NBugReports
  9. {
  10. [TestFixture]
  11. public sealed class BugReportInvokerTests
  12. {
  13. [Test, TestCaseSource(typeof(TestExceptions), "TestCases")]
  14. public void Append(Exception exception, string expectedRootError, string expectedText)
  15. {
  16. StringBuilder text = BugReportInvoker.GetExceptionInfo(exception);
  17. string rootError = BugReportInvoker.GetRootError(exception);
  18. rootError.Should().Be(expectedRootError);
  19. text.ToString().Should().Be(expectedText);
  20. }
  21. }
  22. public class TestExceptions
  23. {
  24. private const string _messageOuter = "outer";
  25. private const string _messageMiddle = "middle";
  26. private const string _messageInner = "inner";
  27. private const string _context = "context";
  28. private const string _command = "command";
  29. private const string _arguments = "arguments";
  30. private const string _directory = "directory";
  31. private const int _exitCode = 128;
  32. public static IEnumerable TestCases
  33. {
  34. get
  35. {
  36. yield return new TestCaseData(new Exception(_messageOuter),
  37. _messageOuter,
  38. "");
  39. yield return new TestCaseData(new Exception(_messageOuter, new Exception(_messageMiddle)),
  40. _messageMiddle,
  41. "");
  42. yield return new TestCaseData(new Exception(_messageOuter, new Exception(_messageMiddle, new Exception(_messageInner))),
  43. _messageInner,
  44. "");
  45. yield return new TestCaseData(new UserExternalOperationException(_context,
  46. new ExternalOperationException(_command, _arguments, _directory, _exitCode, new Exception(_messageOuter, new Exception(_messageInner)))),
  47. _messageInner,
  48. $"{_context}{Environment.NewLine}"
  49. + $"Exit code: {_exitCode}{Environment.NewLine}"
  50. + $"Command: {_command}{Environment.NewLine}"
  51. + $"Arguments: {_arguments}{Environment.NewLine}"
  52. + $"Working directory: {_directory}{Environment.NewLine}");
  53. yield return new TestCaseData(new UserExternalOperationException(context: null,
  54. new ExternalOperationException(null, null, null, null, new Exception(_messageInner))),
  55. _messageInner,
  56. "");
  57. }
  58. }
  59. }
  60. }