GivenDotnetInvokesMSBuild.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.MSBuild.IntegrationTests
  4. {
  5. public class GivenDotnetInvokesMSBuild : SdkTest
  6. {
  7. public GivenDotnetInvokesMSBuild(ITestOutputHelper log) : base(log)
  8. {
  9. }
  10. [Theory]
  11. [InlineData("build")]
  12. [InlineData("clean")]
  13. [InlineData("msbuild")]
  14. [InlineData("pack")]
  15. [InlineData("publish")]
  16. [InlineData("test")]
  17. public void When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(string command)
  18. {
  19. var testInstance = _testAssetsManager.CopyTestAsset("MSBuildIntegration", identifier: command)
  20. .WithSource();
  21. new DotnetCommand(Log)
  22. .WithWorkingDirectory(testInstance.Path)
  23. .Execute(command)
  24. .Should().Pass();
  25. }
  26. [Theory]
  27. [InlineData("build")]
  28. [InlineData("msbuild")]
  29. [InlineData("pack")]
  30. [InlineData("publish")]
  31. public void When_dotnet_command_invokes_msbuild_with_no_args_verbosity_is_set_to_minimum(string command)
  32. {
  33. var testInstance = _testAssetsManager.CopyTestAsset("MSBuildIntegration", identifier: command)
  34. .WithSource();
  35. var cmd = new DotnetCommand(Log)
  36. .WithWorkingDirectory(testInstance.Path)
  37. .Execute(command);
  38. cmd.Should().Pass();
  39. cmd.StdOut
  40. .Should().NotContain("Message with normal importance", "Because verbosity is set to minimum")
  41. .And.Contain("Message with high importance", "Because high importance messages are shown on minimum verbosity");
  42. }
  43. [Theory]
  44. [InlineData("build")]
  45. [InlineData("clean")]
  46. [InlineData("pack")]
  47. [InlineData("publish")]
  48. public void When_dotnet_command_invokes_msbuild_with_diag_verbosity_Then_arg_is_passed(string command)
  49. {
  50. var testInstance = _testAssetsManager.CopyTestAsset("MSBuildIntegration", identifier: command)
  51. .WithSource();
  52. var cmd = new DotnetCommand(Log)
  53. .WithWorkingDirectory(testInstance.Path)
  54. .Execute(command, "-v", "diag");
  55. cmd.Should().Pass();
  56. cmd.StdOut.Should().Contain("Message with low importance");
  57. }
  58. [Fact]
  59. public void When_dotnet_test_invokes_msbuild_with_no_args_verbosity_is_set_to_minimum()
  60. {
  61. var testInstance = _testAssetsManager.CopyTestAsset("MSBuildIntegration")
  62. .WithSource();
  63. var cmd = new DotnetCommand(Log)
  64. .WithWorkingDirectory(testInstance.Path)
  65. .Execute("test");
  66. cmd.Should().Pass();
  67. cmd.StdOut.Should().Contain("Message with high importance");
  68. }
  69. [Fact]
  70. public void When_dotnet_msbuild_command_is_invoked_with_non_msbuild_switch_Then_it_fails()
  71. {
  72. var testInstance = _testAssetsManager.CopyTestAsset("MSBuildIntegration")
  73. .WithSource();
  74. var cmd = new DotnetCommand(Log)
  75. .WithWorkingDirectory(testInstance.Path)
  76. .Execute("msbuild", "-v", "diag");
  77. cmd.ExitCode.Should().NotBe(0);
  78. }
  79. [Fact]
  80. public void When_MSBuildSDKsPath_is_set_by_env_var_then_it_is_not_overridden()
  81. {
  82. var testInstance = _testAssetsManager.CopyTestAsset("MSBuildIntegration")
  83. .WithSource();
  84. var cmd = new DotnetCommand(Log)
  85. .WithWorkingDirectory(testInstance.Path)
  86. .WithEnvironmentVariable("MSBuildSDKsPath", "AnyString")
  87. .Execute($"msbuild");
  88. cmd.ExitCode.Should().NotBe(0);
  89. cmd.StdOut.Should().Contain("Expected 'AnyString")
  90. .And.Contain("to exist, but it does not.");
  91. }
  92. }
  93. }