Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Change GetImports to allow querying of information on non-existent …
Browse files Browse the repository at this point in the history
…files.

- Added tests to validate imports can still be found on non-existent files.

#1267
  • Loading branch information
NTaylorMullen committed Apr 28, 2017
1 parent c176bdb commit 89ac2dc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ public virtual IEnumerable<RazorSourceDocument> GetImports(RazorProjectItem proj
{
throw new ArgumentNullException(nameof(projectItem));
}

if (!projectItem.Exists)
{
throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.Path));
}

var result = new List<RazorSourceDocument>();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,53 @@ namespace Microsoft.AspNetCore.Razor.Language
{
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]
public void GenerateCode_ThrowsIfItemCannotBeFound()
{
Expand Down

0 comments on commit 89ac2dc

Please sign in to comment.