Change `GetImports` to allow querying of information on non-existent files.
- Added tests to validate imports can still be found on non-existent files. #1267
This commit is contained in:
parent
c176bdbab0
commit
207e0f0b59
|
|
@ -182,12 +182,6 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(projectItem));
|
throw new ArgumentNullException(nameof(projectItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!projectItem.Exists)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.Path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new List<RazorSourceDocument>();
|
var result = new List<RazorSourceDocument>();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,53 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
public class RazorTemplateEngineTest
|
public class RazorTemplateEngineTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetImports_CanQueryInformationOnNonExistentFileWithoutImports()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var project = new TestRazorProject();
|
||||||
|
var razorEngine = RazorEngine.Create();
|
||||||
|
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||||
|
{
|
||||||
|
Options =
|
||||||
|
{
|
||||||
|
ImportsFileName = "MyImport.cshtml"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var projectItemToQuery = project.GetItem("/Views/Home/Index.cshtml");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var imports = templateEngine.GetImports(projectItemToQuery);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(imports);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetImports_CanQueryInformationOnNonExistentFileWithImports()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var path = "/Views/Home/MyImport.cshtml";
|
||||||
|
var projectItem = new TestRazorProjectItem(path);
|
||||||
|
var project = new TestRazorProject(new[] { projectItem });
|
||||||
|
var razorEngine = RazorEngine.Create();
|
||||||
|
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||||
|
{
|
||||||
|
Options =
|
||||||
|
{
|
||||||
|
ImportsFileName = "MyImport.cshtml"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var projectItemToQuery = project.GetItem("/Views/Home/Index.cshtml");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var imports = templateEngine.GetImports(projectItemToQuery);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var import = Assert.Single(imports);
|
||||||
|
Assert.Equal(projectItem.Path, import.FileName);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GenerateCode_ThrowsIfItemCannotBeFound()
|
public void GenerateCode_ThrowsIfItemCannotBeFound()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue