Use FilePath if RelativePhysicalPath on RazorProjectItem is null
This commit is contained in:
parent
8c7c486641
commit
ecb323b5dc
|
|
@ -196,7 +196,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
using (var stream = projectItem.Read())
|
||||
{
|
||||
// Autodetect the encoding.
|
||||
return new StreamSourceDocument(stream, null, new RazorSourceDocumentProperties(filePath, projectItem.RelativePhysicalPath));
|
||||
var relativePath = projectItem.RelativePhysicalPath ?? projectItem.FilePath;
|
||||
return new StreamSourceDocument(stream, null, new RazorSourceDocumentProperties(filePath, relativePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
Assert.Equal("c:\\myapp\\filePath.cshtml", document.FilePath);
|
||||
Assert.Null(document.RelativePath);
|
||||
Assert.Equal("filePath.cshtml", document.RelativePath);
|
||||
Assert.Equal(projectItem.Content, ReadContent(document));
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
Assert.Equal("filePath.cshtml", document.FilePath);
|
||||
Assert.Null(document.RelativePath);
|
||||
Assert.Equal("filePath.cshtml", document.RelativePath);
|
||||
Assert.Equal(projectItem.Content, ReadContent(document));
|
||||
}
|
||||
|
||||
|
|
@ -177,6 +177,37 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
Assert.Same(Encoding.UTF32, Assert.IsType<StringSourceDocument>(document).Encoding);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadFrom_WithProjectItem_FallbackToFilePath_WhenRelativePhysicalPathIsNull()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = "filePath.cshtml";
|
||||
var projectItem = new TestRazorProjectItem(filePath, relativePhysicalPath: null);
|
||||
|
||||
// Act
|
||||
var document = RazorSourceDocument.ReadFrom(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(filePath, document.FilePath);
|
||||
Assert.Equal(filePath, document.RelativePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadFrom_WithProjectItem_UsesRelativePhysicalPath()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = "filePath.cshtml";
|
||||
var relativePhysicalPath = "relative-path.cshtml";
|
||||
var projectItem = new TestRazorProjectItem(filePath, relativePhysicalPath: relativePhysicalPath);
|
||||
|
||||
// Act
|
||||
var document = RazorSourceDocument.ReadFrom(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(relativePhysicalPath, document.FilePath);
|
||||
Assert.Equal(relativePhysicalPath, document.RelativePath);
|
||||
}
|
||||
|
||||
private static string ReadContent(RazorSourceDocument razorSourceDocument)
|
||||
{
|
||||
var buffer = new char[razorSourceDocument.Length];
|
||||
|
|
|
|||
Loading…
Reference in New Issue