GivenAppThrowingException.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. namespace Microsoft.DotNet.Cli.Utils.Tests
  4. {
  5. public class GivenAppThrowingException : SdkTest
  6. {
  7. public GivenAppThrowingException(ITestOutputHelper log) : base(log)
  8. {
  9. }
  10. [RequiresSpecificFrameworkFact("netcoreapp1.1")]
  11. public void ItShowsStackTraceWhenRun()
  12. {
  13. var root = _testAssetsManager.CopyTestAsset("AppThrowingException", testAssetSubdirectory: TestAssetSubdirectories.NonRestoredTestProjects)
  14. .WithSource()
  15. .Path;
  16. var appRoot = Path.Combine(root, "App");
  17. string msg1 = "Unhandled Exception: AppThrowing.MyException: "
  18. + "Exception of type 'AppThrowing.MyException' was thrown.";
  19. string msg2 = "at AppThrowing.MyException.Main(String[] args)";
  20. new DotnetCommand(Log)
  21. .WithWorkingDirectory(appRoot)
  22. .Execute("run")
  23. .Should().Fail()
  24. .And.HaveStdErrContaining(msg1)
  25. .And.HaveStdErrContaining(msg2);
  26. }
  27. [RequiresSpecificFrameworkFact("netcoreapp1.1")]
  28. public void ItShowsStackTraceWhenRunAsTool()
  29. {
  30. var root = _testAssetsManager.CopyTestAsset("AppThrowingException", testAssetSubdirectory: TestAssetSubdirectories.NonRestoredTestProjects)
  31. .WithSource()
  32. .Path;
  33. var appRoot = Path.Combine(root, "App");
  34. new DotnetPackCommand(Log)
  35. .WithWorkingDirectory(appRoot)
  36. .Execute("-o", "../pkgs")
  37. .Should()
  38. .Pass();
  39. var appWithToolDepRoot = Path.Combine(root, "AppDependingOnOtherAsTool");
  40. new RestoreCommand(Log, appWithToolDepRoot)
  41. .Execute()
  42. .Should().Pass();
  43. string msg1 = "Unhandled Exception: AppThrowing.MyException: "
  44. + "Exception of type 'AppThrowing.MyException' was thrown.";
  45. string msg2 = "at AppThrowing.MyException.Main(String[] args)";
  46. new DotnetCommand(Log)
  47. .WithWorkingDirectory(appWithToolDepRoot)
  48. .Execute("throwingtool")
  49. .Should().Fail()
  50. .And.HaveStdErrContaining(msg1)
  51. .And.HaveStdErrContaining(msg2);
  52. }
  53. }
  54. }