PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/UnitTests/BugReporter.Tests/ErrorReportUrlBuilderTests.cs

https://github.com/gitextensions/gitextensions
C# | 60 lines | 52 code | 8 blank | 0 comment | 0 complexity | 5d4e79943a2a72d3e4ddbdb48c43285d MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using BugReporter;
  3. using BugReporter.Serialization;
  4. using FluentAssertions;
  5. using NUnit.Framework;
  6. namespace BugReporterTests
  7. {
  8. [TestFixture]
  9. [SetCulture("en-US")]
  10. [SetUICulture("en-US")]
  11. public sealed class ErrorReportUrlBuilderTests
  12. {
  13. private ErrorReportUrlBuilder _builder;
  14. [SetUp]
  15. public void Setup()
  16. {
  17. _builder = new ErrorReportUrlBuilder();
  18. }
  19. [Test]
  20. public void Build_should_throw_ANE_if_exception_null()
  21. {
  22. ((Action)(() => _builder.Build(exception: null, exceptionInfo: null, environmentInfo: null, additionalInfo: null)))
  23. .Should().Throw<ArgumentNullException>();
  24. }
  25. private (SerializableException exception, string? exceptionInfo, string environmentInfo, string additionalInfo) BuildData()
  26. {
  27. SerializableException exception = new(new Exception("OPPS!", new ApplicationException("BAM!", new DivideByZeroException("BOOM!"))));
  28. string environmentInfo = @"Git Extensions 3.4.3.9999
  29. Build d4b0f48
  30. Git 2.27.0.windows.1
  31. Microsoft Windows NT 10.0.19041.0
  32. .NET Framework 4.8.4360.0
  33. DPI 288dpi (300% scaling)".Replace("\r\n", "\n");
  34. string additionalInfo = "I was just trying out a bunch of stuff, not sure what is the cause. Could just as well be an issue with Git. I cannot provide the specific Repo I used. Hope I'm not wasting your time.";
  35. return (exception, exceptionInfo: null, environmentInfo, additionalInfo);
  36. }
  37. [Test]
  38. public void Build_should_serialize_exception_into_url()
  39. {
  40. (SerializableException exception, string? exceptionInfo, string environmentInfo, string additionalInfo) bd = BuildData();
  41. string url = _builder.Build(bd.exception, bd.exceptionInfo, bd.environmentInfo, bd.additionalInfo);
  42. Assert.AreEqual("template=bug_report.yml&labels=type%3A%20NBug&about=Git%20Extensions%203.4.3.9999%0ABuild%20d4b0f48%0AGit%202.27.0.windows.1%0AMicrosoft%20Windows%20NT%2010.0.19041.0%0A.NET%20Framework%204.8.4360.0%0ADPI%20288dpi%20%28300%25%20scaling%29&description=%60%60%60%0ASystem.Exception%3A%20OPPS%21%0D%0A%20---%3E%20System.ApplicationException%3A%20BAM%21%0D%0A%20---%3E%20System.DivideByZeroException%3A%20BOOM%21%0D%0A%20%20%20---%20End%20of%20inner%20exception%20stack%20trace%20---%0D%0A%20%20%20---%20End%20of%20inner%20exception%20stack%20trace%20---%0A%60%60%60%0A%0AI%20was%20just%20trying%20out%20a%20bunch%20of%20stuff%2C%20not%20sure%20what%20is%20the%20cause.%20Could%20just%20as%20well%20be%20an%20issue%20with%20Git.%20I%20cannot%20provide%20the%20specific%20Repo%20I%20used.%20Hope%20I%27m%20not%20wasting%20your%20time.%0A", url);
  43. }
  44. [Test]
  45. public void CopyText_should_format_text()
  46. {
  47. (SerializableException exception, string? exceptionInfo, string environmentInfo, string additionalInfo) bd = BuildData();
  48. string url = _builder.CopyText(bd.exception, bd.exceptionInfo, bd.environmentInfo, bd.additionalInfo);
  49. Assert.AreEqual("Git Extensions 3.4.3.9999\nBuild d4b0f48\nGit 2.27.0.windows.1\nMicrosoft Windows NT 10.0.19041.0\n.NET Framework 4.8.4360.0\nDPI 288dpi (300% scaling)```\nSystem.Exception: OPPS!\r\n ---> System.ApplicationException: BAM!\r\n ---> System.DivideByZeroException: BOOM!\r\n --- End of inner exception stack trace ---\r\n --- End of inner exception stack trace ---\n```\n\nI was just trying out a bunch of stuff, not sure what is the cause. Could just as well be an issue with Git. I cannot provide the specific Repo I used. Hope I'm not wasting your time.\n", url);
  50. }
  51. }
  52. }