Added a test to verify incremental TagHelper discovery
This commit is contained in:
parent
60e5818884
commit
64c86634a8
|
|
@ -100,6 +100,42 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
throw new BuildOutputMissingException(result, match);
|
||||
}
|
||||
|
||||
public static void FileContains(MSBuildResult result, string filePath, string match)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
filePath = Path.Combine(result.Project.DirectoryPath, filePath);
|
||||
FileExists(result, filePath);
|
||||
|
||||
var text = File.ReadAllText(filePath);
|
||||
if (text.Contains(match))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FileContentMissingException(result, filePath, File.ReadAllText(filePath), match);
|
||||
}
|
||||
|
||||
public static void FileDoesNotContain(MSBuildResult result, string filePath, string match)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
filePath = Path.Combine(result.Project.DirectoryPath, filePath);
|
||||
FileExists(result, filePath);
|
||||
|
||||
var text = File.ReadAllText(filePath);
|
||||
if (text.Contains(match))
|
||||
{
|
||||
throw new FileContentFoundException(result, filePath, File.ReadAllText(filePath), match);
|
||||
}
|
||||
}
|
||||
|
||||
public static void FileContainsLine(MSBuildResult result, string filePath, string match)
|
||||
{
|
||||
if (result == null)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,14 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.dll");
|
||||
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.Views.dll");
|
||||
|
||||
// RazorGenerate should generate correct TagHelper caches
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.TagHelpers.input.cache");
|
||||
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.TagHelpers.output.cache");
|
||||
Assert.FileContains(
|
||||
result,
|
||||
Path.Combine(IntermediateOutputPath, "SimpleMvc.TagHelpers.output.cache"),
|
||||
@"""Name"":""SimpleMvc.SimpleTagHelper""");
|
||||
|
||||
Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "_ViewImports.cs");
|
||||
Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "_ViewStart.cs");
|
||||
Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Home", "About.cs");
|
||||
|
|
@ -44,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
// Introducing a syntax error, an unclosed brace
|
||||
ReplaceContent("@{", "Views", "Home", "Index.cshtml");
|
||||
|
||||
var result = await DotnetMSBuild("RazorGenerate");
|
||||
var result = await DotnetMSBuild(RazorGenerateTarget);
|
||||
|
||||
Assert.BuildFailed(result);
|
||||
|
||||
|
|
@ -181,6 +189,37 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.FileDoesNotExist(result, generatedFile);
|
||||
}
|
||||
|
||||
[Fact(Skip = "https://github.com/aspnet/Razor/issues/2104")]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task RazorGenerate_Rebuilds_IfTagHelpersChanged()
|
||||
{
|
||||
// Act - 1
|
||||
var expectedTagHelperCacheContent = @"""Name"":""SimpleMvc.SimpleTagHelper""";
|
||||
var result = await DotnetMSBuild(RazorGenerateTarget);
|
||||
var file = Path.Combine(Project.DirectoryPath, "SimpleTagHelper.cs");
|
||||
var tagHelperOutputCache = Path.Combine(IntermediateOutputPath, "SimpleMvc.TagHelpers.output.cache");
|
||||
var generatedFile = Path.Combine(RazorIntermediateOutputPath, "Views", "Home", "Index.cs");
|
||||
|
||||
// Assert - 1
|
||||
Assert.BuildPassed(result);
|
||||
Assert.FileContains(result, tagHelperOutputCache, expectedTagHelperCacheContent);
|
||||
var fileThumbPrint = GetThumbPrint(generatedFile);
|
||||
|
||||
// Act - 2
|
||||
// Update the source content and build. We should expect the outputs to be regenerated.
|
||||
// Timestamps on xplat are precise only to a second. Add a delay so we can ensure that MSBuild recognizes the
|
||||
// file change. See https://github.com/dotnet/corefx/issues/26024
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
ReplaceContent(string.Empty, file);
|
||||
result = await DotnetMSBuild(RazorGenerateTarget);
|
||||
|
||||
// Assert - 2
|
||||
Assert.BuildPassed(result);
|
||||
Assert.FileDoesNotContain(result, tagHelperOutputCache, expectedTagHelperCacheContent);
|
||||
var newThumbPrint = GetThumbPrint(generatedFile);
|
||||
Assert.NotEqual(fileThumbPrint, newThumbPrint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitializeTestProject("SimpleMvc")]
|
||||
public async Task RazorGenerate_Noops_WithNoFiles()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
|
||||
namespace SimpleMvc
|
||||
{
|
||||
public class SimpleTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue