BuildIntrospectionTest.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.NET.Sdk.Razor.Tests
  4. {
  5. public class BuildIntrospectionTest : AspNetSdkTest
  6. {
  7. public BuildIntrospectionTest(ITestOutputHelper log) : base(log) { }
  8. [Fact]
  9. public void RazorSdk_AddsCshtmlFilesToUpToDateCheckInput()
  10. {
  11. var testAsset = "RazorSimpleMvc";
  12. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  13. var build = new BuildCommand(projectDirectory);
  14. build.Execute("/t:_IntrospectUpToDateCheck")
  15. .Should()
  16. .Pass()
  17. .And.HaveStdOutContaining($"UpToDateCheckInput: {Path.Combine("Views", "Home", "Index.cshtml")}")
  18. .And.HaveStdOutContaining($"UpToDateCheckInput: {Path.Combine("Views", "_ViewStart.cshtml")}");
  19. }
  20. [Fact]
  21. public void UpToDateReloadFileTypes_Default()
  22. {
  23. var testAsset = "RazorSimpleMvc";
  24. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  25. var build = new BuildCommand(projectDirectory);
  26. build.Execute("/t:_IntrospectUpToDateReloadFileTypes")
  27. .Should()
  28. .Pass()
  29. .And.HaveStdOutContaining("UpToDateReloadFileTypes: ;.cs;.razor;.resx;.cshtml");
  30. }
  31. [Fact]
  32. public void UpToDateReloadFileTypes_WithRuntimeCompilation()
  33. {
  34. var testAsset = "RazorSimpleMvc";
  35. var projectDirectory = CreateAspNetSdkTestAsset(testAsset)
  36. .WithProjectChanges(p =>
  37. {
  38. var ns = p.Root.Name.Namespace;
  39. var propertyGroup = new XElement(ns + "PropertyGroup");
  40. p.Root.Add(propertyGroup);
  41. propertyGroup.Add(new XElement(ns + "RazorUpToDateReloadFileTypes", @"$(RazorUpToDateReloadFileTypes.Replace('.cshtml', ''))"));
  42. });
  43. var build = new BuildCommand(projectDirectory);
  44. build.Execute("/t:_IntrospectUpToDateReloadFileTypes")
  45. .Should()
  46. .Pass()
  47. .And.HaveStdOutContaining("UpToDateReloadFileTypes: ;.cs;.razor;.resx;");
  48. }
  49. [Fact]
  50. public void UpToDateReloadFileTypes_WithwWorkAroundRemoved()
  51. {
  52. var testAsset = "RazorSimpleMvc";
  53. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  54. var build = new BuildCommand(projectDirectory);
  55. build.Execute("/t:_IntrospectUpToDateReloadFileTypes")
  56. .Should()
  57. .Pass()
  58. .And.HaveStdOutContaining("UpToDateReloadFileTypes: ;.cs;.razor;.resx;.cshtml");
  59. }
  60. [Fact]
  61. public void UpToDateReloadFileTypes_WithRuntimeCompilationAndWorkaroundRemoved()
  62. {
  63. var testAsset = "RazorSimpleMvc";
  64. var projectDirectory = CreateAspNetSdkTestAsset(testAsset)
  65. .WithProjectChanges(p =>
  66. {
  67. var ns = p.Root.Name.Namespace;
  68. var propertyGroup = new XElement(ns + "PropertyGroup");
  69. p.Root.Add(propertyGroup);
  70. propertyGroup.Add(new XElement(ns + "RazorUpToDateReloadFileTypes", @"$(RazorUpToDateReloadFileTypes.Replace('.cshtml', ''))"));
  71. });
  72. var build = new BuildCommand(projectDirectory);
  73. build.Execute("/t:_IntrospectUpToDateReloadFileTypes", "/p:_RazorUpToDateReloadFileTypesAllowWorkaround=false")
  74. .Should()
  75. .Pass()
  76. .And.HaveStdOutContaining("UpToDateReloadFileTypes: ;.cs;.razor;.resx;");
  77. }
  78. [Fact]
  79. public void IntrospectRazorSdkWatchItems()
  80. {
  81. var testAsset = "RazorComponentApp";
  82. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  83. var build = new MSBuildCommand(Log, "_IntrospectWatchItems", projectDirectory.Path);
  84. build.Execute()
  85. .Should()
  86. .Pass()
  87. .And.HaveStdOutContaining("Watch: Index.razor")
  88. .And.HaveStdOutContaining("Watch: Index.razor.css");
  89. }
  90. [Fact]
  91. public void IntrospectRazorDesignTimeTargets()
  92. {
  93. var expected1 = Path.Combine("Components", "App.razor");
  94. var expected2 = Path.Combine("Components", "Shared", "MainLayout.razor");
  95. var testAsset = "RazorComponentApp";
  96. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  97. var build = new MSBuildCommand(Log, "_IntrospectRazorGenerateComponentDesignTime", projectDirectory.Path);
  98. build.Execute()
  99. .Should()
  100. .Pass()
  101. .And.HaveStdOutContaining($"RazorComponentWithTargetPath: App {expected1}")
  102. .And.HaveStdOutContaining($"RazorComponentWithTargetPath: MainLayout {expected2}");
  103. }
  104. }
  105. }