GivenThatWeWantToCleanAProject.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. using NuGet.Common;
  4. using NuGet.ProjectModel;
  5. namespace Microsoft.NET.Clean.Tests
  6. {
  7. public class GivenThatWeWantToCleanAHelloWorldProject : SdkTest
  8. {
  9. public GivenThatWeWantToCleanAHelloWorldProject(ITestOutputHelper log) : base(log)
  10. {
  11. }
  12. [RequiresMSBuildVersionFact("17.8.0")]
  13. public void It_cleans_without_logging_assets_message()
  14. {
  15. var testAsset = _testAssetsManager
  16. .CopyTestAsset("HelloWorld", "CleanHelloWorld")
  17. .WithSource()
  18. .Restore(Log);
  19. var lockFilePath = Path.Combine(testAsset.TestRoot, "obj", "project.assets.json");
  20. LockFile lockFile = LockFileUtilities.GetLockFile(lockFilePath, NullLogger.Instance);
  21. lockFile.LogMessages.Add(
  22. new AssetsLogMessage(
  23. LogLevel.Warning,
  24. NuGetLogCode.NU1500,
  25. "a test warning",
  26. null));
  27. new LockFileFormat().Write(lockFilePath, lockFile);
  28. var cleanCommand = new CleanCommand(Log, testAsset.TestRoot);
  29. cleanCommand
  30. .Execute("/p:CheckEolTargetFramework=false")
  31. .Should()
  32. .Pass()
  33. .And
  34. .NotHaveStdOutContaining("warning");
  35. }
  36. [Fact]
  37. public void It_cleans_without_assets_file_present()
  38. {
  39. var testAsset = _testAssetsManager
  40. .CopyTestAsset("HelloWorld")
  41. .WithSource();
  42. var assetsFilePath = Path.Combine(testAsset.TestRoot, "obj", "project.assets.json");
  43. File.Exists(assetsFilePath).Should().BeFalse();
  44. var cleanCommand = new CleanCommand(Log, testAsset.TestRoot);
  45. cleanCommand
  46. .Execute()
  47. .Should()
  48. .Pass();
  49. }
  50. // Related to https://github.com/dotnet/sdk/issues/2233
  51. // This test will fail if the naive fix for not reading assets file during clean is attempted
  52. [Fact]
  53. public void It_can_clean_and_build_without_using_rebuild()
  54. {
  55. var testAsset = _testAssetsManager
  56. .CopyTestAsset("HelloWorld")
  57. .WithSource();
  58. var cleanAndBuildCommand = new MSBuildCommand(Log, "Clean;Build", testAsset.TestRoot);
  59. cleanAndBuildCommand
  60. .Execute()
  61. .Should()
  62. .Pass();
  63. }
  64. }
  65. }