diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/CodeGeneration/RuntimeCSharpRenderer.cs b/src/Microsoft.AspNetCore.Razor.Evolution/CodeGeneration/RuntimeCSharpRenderer.cs
index b1077aee37..c904c64841 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/CodeGeneration/RuntimeCSharpRenderer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/CodeGeneration/RuntimeCSharpRenderer.cs
@@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
{
Context.Writer
.Write("#pragma checksum \"")
- .Write(node.Filename)
+ .Write(node.FileName)
.Write("\" \"")
.Write(node.Guid)
.Write("\" \"")
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs
index 656569a8db..a1feb35873 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs
@@ -51,14 +51,14 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
var import = imports[j];
- importsVisitor.Filename = import.Source.Filename;
+ importsVisitor.FileName = import.Source.FileName;
importsVisitor.VisitBlock(import.Root);
}
}
var visitor = new MainSourceVisitor(document, builder, namespaces)
{
- Filename = syntaxTree.Source.Filename,
+ FileName = syntaxTree.Source.FileName,
};
visitor.VisitBlock(syntaxTree.Root);
@@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
_namespaces = namespaces;
}
- public string Filename { get; set; }
+ public string FileName { get; set; }
public override void VisitImportSpan(AddImportChunkGenerator chunkGenerator, Span span)
{
@@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
}
var span = new SourceSpan(
- node.Start.FilePath ?? Filename,
+ node.Start.FilePath ?? FileName,
node.Start.AbsoluteIndex,
node.Start.LineIndex,
node.Start.CharacterIndex,
@@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var contentLength = templateNode.Children.Sum(child => child.Source?.Length ?? 0);
templateNode.Source = new SourceSpan(
- sourceRangeStart.Value.FilePath ?? Filename,
+ sourceRangeStart.Value.FilePath ?? FileName,
sourceRangeStart.Value.AbsoluteIndex,
sourceRangeStart.Value.LineIndex,
sourceRangeStart.Value.CharacterIndex,
@@ -353,7 +353,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var contentLength = expressionNode.Children.Sum(child => child.Source?.Length ?? 0);
expressionNode.Source = new SourceSpan(
- sourceRangeStart.Value.FilePath ?? Filename,
+ sourceRangeStart.Value.FilePath ?? FileName,
sourceRangeStart.Value.AbsoluteIndex,
sourceRangeStart.Value.LineIndex,
sourceRangeStart.Value.CharacterIndex,
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceDocument.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceDocument.cs
index 353ccb222b..1b4359c823 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceDocument.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceDocument.cs
@@ -2,10 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
using System.Text;
-using Microsoft.AspNetCore.Razor.Evolution.Legacy;
namespace Microsoft.AspNetCore.Razor.Evolution
{
@@ -14,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
private readonly string _content;
private readonly RazorSourceLineCollection _lines;
- public DefaultRazorSourceDocument(string content, Encoding encoding, string filename)
+ public DefaultRazorSourceDocument(string content, Encoding encoding, string fileName)
{
if (content == null)
{
@@ -28,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
_content = content;
Encoding = encoding;
- Filename = filename;
+ FileName = fileName;
_lines = new DefaultRazorSourceLineCollection(this);
}
@@ -37,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public override Encoding Encoding { get; }
- public override string Filename { get; }
+ public override string FileName { get; }
public override int Length => _content.Length;
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceLineCollection.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceLineCollection.cs
index 53e8c43f66..daaef11d56 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceLineCollection.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSourceLineCollection.cs
@@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// We have an exact match for the start of a line.
Debug.Assert(_lineStarts[index] == position);
- return new SourceLocation(_document.Filename, position, index, characterIndex: 0);
+ return new SourceLocation(_document.FileName, position, index, characterIndex: 0);
}
@@ -59,12 +59,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution
if (index == -1)
{
// There's no preceding line, so it's based on the start of the string
- return new SourceLocation(_document.Filename, position, 0, position);
+ return new SourceLocation(_document.FileName, position, 0, position);
}
else
{
var characterIndex = position - _lineStarts[index];
- return new SourceLocation(_document.Filename, position, index, characterIndex);
+ return new SourceLocation(_document.FileName, position, index, characterIndex);
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/FileSystemRazorProjectItem.cs b/src/Microsoft.AspNetCore.Razor.Evolution/FileSystemRazorProjectItem.cs
index 9ce8bef44b..f8a79016e1 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/FileSystemRazorProjectItem.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/FileSystemRazorProjectItem.cs
@@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public override bool Exists => File.Exists;
///
- public override string Filename => File.Name;
+ public override string FileName => File.Name;
///
public override string PhysicalPath => File.FullName;
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs
index 2d02b55b6c..b73c9704b6 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs
@@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public string Bytes { get; set; }
- public string Filename { get; set; }
+ public string FileName { get; set; }
public string Guid { get; set; }
@@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
var node = new ChecksumIRNode()
{
- Filename = sourceDocument.Filename,
+ FileName = sourceDocument.FileName,
Guid = Sha1AlgorithmId
};
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/LargeTextRazorSourceDocument.cs b/src/Microsoft.AspNetCore.Razor.Evolution/LargeTextRazorSourceDocument.cs
index 5d9b6eb9d2..a9d5b16a03 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/LargeTextRazorSourceDocument.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/LargeTextRazorSourceDocument.cs
@@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
private readonly int _length;
- public LargeTextRazorSourceDocument(StreamReader reader, int chunkMaxLength, Encoding encoding, string filename)
+ public LargeTextRazorSourceDocument(StreamReader reader, int chunkMaxLength, Encoding encoding, string fileName)
{
if (reader == null)
{
@@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
_chunkMaxLength = chunkMaxLength;
Encoding = encoding;
- Filename = filename;
+ FileName = fileName;
ReadChunks(reader, _chunkMaxLength, out _length, out _chunks);
_lines = new DefaultRazorSourceLineCollection(this);
@@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public override Encoding Encoding { get; }
- public override string Filename { get; }
+ public override string FileName { get; }
public override int Length => _length;
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorProjectItem.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorProjectItem.cs
index 24368a7d86..896e7e788d 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorProjectItem.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorProjectItem.cs
@@ -63,14 +63,14 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
get
{
- var index = Filename.LastIndexOf('.');
+ var index = FileName.LastIndexOf('.');
if (index == -1)
{
return null;
}
else
{
- return Filename.Substring(index);
+ return FileName.Substring(index);
}
}
}
@@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
///
/// The name of the file including the extension.
///
- public virtual string Filename
+ public virtual string FileName
{
get
{
diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorSourceDocument.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorSourceDocument.cs
index d1e1565937..b0d19ded95 100644
--- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorSourceDocument.cs
+++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorSourceDocument.cs
@@ -7,35 +7,74 @@ using System.Text;
namespace Microsoft.AspNetCore.Razor.Evolution
{
+ ///
+ /// The Razor template source.
+ ///
public abstract class RazorSourceDocument
{
- private const int LargeObjectHeapLimitInChars = 40 * 1024; // 40K Unicode chars is 80KB which is less than the large object heap limit.
+ internal const int LargeObjectHeapLimitInChars = 40 * 1024; // 40K Unicode chars is 80KB which is less than the large object heap limit.
internal static readonly RazorSourceDocument[] EmptyArray = new RazorSourceDocument[0];
+ ///
+ /// Encoding of the file that the text was read from.
+ ///
public abstract Encoding Encoding { get; }
- public abstract string Filename { get; }
+ ///
+ /// Path of the file the content was read from.
+ ///
+ public abstract string FileName { get; }
+ ///
+ /// Gets a character at given position.
+ ///
+ /// The position to get the character from.
public abstract char this[int position] { get; }
+ ///
+ /// Gets the length of the text in characters.
+ ///
public abstract int Length { get; }
+ ///
+ /// Gets the .
+ ///
public abstract RazorSourceLineCollection Lines { get; }
+ ///
+ /// Copies a range of characters from the to the specified .
+ ///
+ /// The index of the first character in this instance to copy.
+ /// The destination buffer.
+ /// The index in destination at which the copy operation begins.
+ /// The number of characters in this instance to copy to destination.
public abstract void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
- public static RazorSourceDocument ReadFrom(Stream stream, string filename)
+ ///
+ /// Reads the from the specified .
+ ///
+ /// The to read from.
+ /// The file name of the template.
+ /// The .
+ public static RazorSourceDocument ReadFrom(Stream stream, string fileName)
{
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
- return ReadFromInternal(stream, filename, encoding: null);
+ return ReadFromInternal(stream, fileName, encoding: null);
}
- public static RazorSourceDocument ReadFrom(Stream stream, string filename, Encoding encoding)
+ ///
+ /// Reads the from the specified .
+ ///
+ /// The to read from.
+ /// The file name of the template.
+ /// The to use to read the .
+ /// The .
+ public static RazorSourceDocument ReadFrom(Stream stream, string fileName, Encoding encoding)
{
if (stream == null)
{
@@ -47,9 +86,14 @@ namespace Microsoft.AspNetCore.Razor.Evolution
throw new ArgumentNullException(nameof(encoding));
}
- return ReadFromInternal(stream, filename, encoding);
+ return ReadFromInternal(stream, fileName, encoding);
}
+ ///
+ /// Reads the from the specified .
+ ///
+ /// The to read from.
+ /// The .
public static RazorSourceDocument ReadFrom(RazorProjectItem projectItem)
{
if (projectItem == null)
@@ -69,7 +113,39 @@ namespace Microsoft.AspNetCore.Razor.Evolution
}
}
- private static RazorSourceDocument ReadFromInternal(Stream stream, string filename, Encoding encoding)
+ ///
+ /// Creates a from the specified .
+ ///
+ /// The template content.
+ /// The file name of the .
+ /// The .
+ /// Uses
+ public static RazorSourceDocument Create(string content, string fileName)
+ => Create(content, fileName, Encoding.UTF8);
+
+ ///
+ /// Creates a from the specified .
+ ///
+ /// The template content.
+ /// The file name of the .
+ /// The of the file was read from.
+ /// The .
+ public static RazorSourceDocument Create(string content, string fileName, Encoding encoding)
+ {
+ if (content == null)
+ {
+ throw new ArgumentNullException(nameof(content));
+ }
+
+ if (encoding == null)
+ {
+ throw new ArgumentNullException(nameof(encoding));
+ }
+
+ return new DefaultRazorSourceDocument(content, encoding, fileName);
+ }
+
+ private static RazorSourceDocument ReadFromInternal(Stream stream, string fileName, Encoding encoding)
{
var streamLength = (int)stream.Length;
var content = string.Empty;
@@ -109,14 +185,14 @@ namespace Microsoft.AspNetCore.Razor.Evolution
reader,
LargeObjectHeapLimitInChars,
contentEncoding,
- filename);
+ fileName);
}
content = reader.ReadToEnd();
}
}
- return new DefaultRazorSourceDocument(content, contentEncoding, filename);
+ return new DefaultRazorSourceDocument(content, contentEncoding, fileName);
}
}
}
diff --git a/src/RazorPageGenerator/Program.cs b/src/RazorPageGenerator/Program.cs
index 2a2fdb17d1..75bb90ccfb 100644
--- a/src/RazorPageGenerator/Program.cs
+++ b/src/RazorPageGenerator/Program.cs
@@ -46,7 +46,7 @@ namespace RazorPageGenerator
.SetBaseType("Microsoft.Extensions.RazorViews.BaseView")
.ConfigureClass((document, @class) =>
{
- @class.Name = Path.GetFileNameWithoutExtension(document.Source.Filename);
+ @class.Name = Path.GetFileNameWithoutExtension(document.Source.FileName);
@class.AccessModifier = "internal";
});
@@ -76,7 +76,7 @@ namespace RazorPageGenerator
foreach (var item in cshtmlFiles)
{
- Console.WriteLine(" Generating code file for view {0}...", item.Filename);
+ Console.WriteLine(" Generating code file for view {0}...", item.FileName);
results.Add(GenerateCodeFile(templateEngine, item));
Console.WriteLine(" Done!");
fileCount++;
@@ -118,7 +118,7 @@ namespace RazorPageGenerator
public override string Path => _source.Path;
// Mask the full name since we don't want a developer's local file paths to be commited.
- public override string PhysicalPath => _source.Filename;
+ public override string PhysicalPath => _source.FileName;
public override bool Exists => _source.Exists;
diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorSourceDocumentTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorSourceDocumentTest.cs
index 74ff8bea26..8bd7be73d3 100644
--- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorSourceDocumentTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorSourceDocumentTest.cs
@@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var expectedContent = "Hello, World!";
var indexerBuffer = new char[expectedContent.Length];
- var document = new DefaultRazorSourceDocument(expectedContent, Encoding.UTF8, filename: "file.cshtml");
+ var document = new DefaultRazorSourceDocument(expectedContent, Encoding.UTF8, fileName: "file.cshtml");
// Act
for (var i = 0; i < document.Length; i++)
@@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var expectedContent = "Hello, World!";
- var document = new DefaultRazorSourceDocument(expectedContent, Encoding.UTF8, filename: "file.cshtml");
+ var document = new DefaultRazorSourceDocument(expectedContent, Encoding.UTF8, fileName: "file.cshtml");
// Act & Assert
Assert.Equal(expectedContent.Length, document.Length);
@@ -46,10 +46,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var content = "Hello, World!";
// Act
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: "file.cshtml");
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: "file.cshtml");
// Assert
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
}
[Fact]
@@ -59,10 +59,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var content = "Hello, World!";
// Act
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Assert
- Assert.Null(document.Filename);
+ Assert.Null(document.FileName);
}
[Fact]
@@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "Hello, World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
var expectedContent = "Hello";
var charBuffer = new char[expectedContent.Length];
@@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "Hello, World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
var expectedContent = "$Hello";
var charBuffer = new char[expectedContent.Length];
charBuffer[0] = '$';
@@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "Hello, World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
var expectedContent = "World";
var charBuffer = new char[expectedContent.Length];
@@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "Hi";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
var charBuffer = new char[2];
// Act
@@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "Hi";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act & Assert
//
@@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = string.Empty;
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.Count;
@@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = string.Empty;
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLineLength(0);
@@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "hello\n";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLineLength(0);
@@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
// Arrange
var content = "hello\r\n";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLineLength(0);
@@ -218,7 +218,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
.Append("jumps over the lazy dog.")
.ToString();
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\rWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\rBig\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\u0085World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -309,7 +309,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\u2028World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -324,7 +324,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\u2029World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = GetAllLineMappings(document);
@@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello, World!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: "Hi.cshtml");
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: "Hi.cshtml");
// Act
var actual = document.Lines.GetLocation(1);
@@ -357,7 +357,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\nBig\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLocation(0);
@@ -373,7 +373,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\nBig\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLocation(5);
@@ -389,7 +389,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\nBig\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLocation(7);
@@ -405,7 +405,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\nBig\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLocation(11);
@@ -421,7 +421,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Arrange
var content = "Hello\nBig\r\nWorld!";
- var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, filename: null);
+ var document = new DefaultRazorSourceDocument(content, Encoding.UTF8, fileName: null);
// Act
var actual = document.Lines.GetLocation(16);
diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/FileSystemRazorProjectItemTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/FileSystemRazorProjectItemTest.cs
index 7bb8006fa5..e792001709 100644
--- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/FileSystemRazorProjectItemTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/FileSystemRazorProjectItemTest.cs
@@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Assert.Equal("/Home.cshtml", projectItem.Path);
Assert.Equal("/Views", projectItem.BasePath);
Assert.True(projectItem.Exists);
- Assert.Equal("Home.cshtml", projectItem.Filename);
+ Assert.Equal("Home.cshtml", projectItem.FileName);
Assert.Equal(fileInfo.FullName, projectItem.PhysicalPath);
}
diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/LargeTextRazorSourceDocumentTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/LargeTextRazorSourceDocumentTest.cs
index 71778bf358..2c2a67d4dd 100644
--- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/LargeTextRazorSourceDocumentTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/LargeTextRazorSourceDocumentTest.cs
@@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Test
var document = new LargeTextRazorSourceDocument(reader, ChunkTestLength, Encoding.UTF8, fileName);
// Assert
- Assert.Equal(fileName, document.Filename);
+ Assert.Equal(fileName, document.FileName);
}
[Fact]
diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorProjectItemTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorProjectItemTest.cs
index bda7205f53..d08f947cde 100644
--- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorProjectItemTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorProjectItemTest.cs
@@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var projectItem = new TestRazorProjectItem(path, basePath: "/");
// Act
- var fileName = projectItem.Filename;
+ var fileName = projectItem.FileName;
// Assert
Assert.Equal(expected, fileName);
diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorSourceDocumentTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorSourceDocumentTest.cs
index fc80d816d0..3ec3dc3e19 100644
--- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorSourceDocumentTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorSourceDocumentTest.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Assert
Assert.IsType(document);
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
Assert.Same(Encoding.UTF8, document.Encoding);
}
@@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
// Assert
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
Assert.Same(Encoding.UTF32, Assert.IsType(document).Encoding);
}
@@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
// Assert
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
Assert.Same(Encoding.UTF32, Assert.IsType(document).Encoding);
}
@@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Assert
Assert.IsType(document);
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
Assert.Equal(Encoding.UTF32, document.Encoding);
}
@@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Assert
Assert.IsType(document);
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
Assert.Equal(Encoding.UTF32, document.Encoding);
}
@@ -95,19 +95,95 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Assert.Equal(expectedMessage, exception.Message);
}
- [Fact]
- public void ReadFrom_LargeContent()
+ [Theory]
+ [InlineData(100000)]
+ [InlineData(RazorSourceDocument.LargeObjectHeapLimitInChars)]
+ [InlineData(RazorSourceDocument.LargeObjectHeapLimitInChars + 2)]
+ [InlineData(RazorSourceDocument.LargeObjectHeapLimitInChars * 2 - 1)]
+ [InlineData(RazorSourceDocument.LargeObjectHeapLimitInChars * 2)]
+ public void ReadFrom_LargeContent(int contentLength)
{
// Arrange
- var content = TestRazorSourceDocument.CreateStreamContent(new string('a', 100000));
+ var content = new string('a', contentLength);
+ var stream = TestRazorSourceDocument.CreateStreamContent(content);
// Act
- var document = RazorSourceDocument.ReadFrom(content, "file.cshtml");
+ var document = RazorSourceDocument.ReadFrom(stream, "file.cshtml");
// Assert
Assert.IsType(document);
- Assert.Equal("file.cshtml", document.Filename);
+ Assert.Equal("file.cshtml", document.FileName);
Assert.Same(Encoding.UTF8, document.Encoding);
+ Assert.Equal(content, ReadContent(document));
+ }
+
+ [Fact]
+ public void ReadFrom_ProjectItem()
+ {
+ // Arrange
+ var projectItem = new TestRazorProjectItem("/test-path");
+
+ // Act
+ var document = RazorSourceDocument.ReadFrom(projectItem);
+
+ // Assert
+ Assert.Equal(projectItem.Path, document.FileName);
+ Assert.Equal(projectItem.Content, ReadContent(document));
+ }
+
+ [Fact]
+ public void ReadFrom_UsesProjectItemPhysicalPath()
+ {
+ // Arrange
+ var projectItem = new TestRazorProjectItem("/test-path", "some-physical-path");
+
+ // Act
+ var document = RazorSourceDocument.ReadFrom(projectItem);
+
+ // Assert
+ Assert.Equal(projectItem.PhysicalPath, document.FileName);
+ Assert.Equal(projectItem.Content, ReadContent(document));
+ }
+
+ [Fact]
+ public void Create_WithoutEncoding()
+ {
+ // Arrange
+ var content = "Hello world";
+ var fileName = "some-file-name";
+
+ // Act
+ var document = RazorSourceDocument.Create(content, fileName);
+
+ // Assert
+ Assert.Equal(fileName, document.FileName);
+ Assert.Equal(content, ReadContent(document));
+ Assert.Same(Encoding.UTF8, document.Encoding);
+ }
+
+ [Fact]
+ public void Create_WithEncoding()
+ {
+ // Arrange
+ var content = "Hello world";
+ var fileName = "some-file-name";
+ var encoding = Encoding.UTF32;
+
+ // Act
+ var document = RazorSourceDocument.Create(content, fileName, encoding);
+
+ // Assert
+ Assert.Equal(fileName, document.FileName);
+ Assert.Equal(content, ReadContent(document));
+ Assert.Same(encoding, document.Encoding);
+ }
+
+ private static string ReadContent(RazorSourceDocument razorSourceDocument)
+ {
+ var buffer = new char[razorSourceDocument.Length];
+ razorSourceDocument.CopyTo(0, buffer, 0, buffer.Length);
+
+ return new string(buffer);
}
}
}
diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorTemplateEngineTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorTemplateEngineTest.cs
index ef68383c22..76f05123a1 100644
--- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorTemplateEngineTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/RazorTemplateEngineTest.cs
@@ -159,8 +159,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Assert
Assert.Collection(codeDocument.Imports,
- import => Assert.Equal("/MyImport.cshtml", import.Filename),
- import => Assert.Equal("/Views/Home/MyImport.cshtml", import.Filename));
+ import => Assert.Equal("/MyImport.cshtml", import.FileName),
+ import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FileName));
}
[Fact]
@@ -188,8 +188,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Assert
Assert.Collection(codeDocument.Imports,
import => Assert.Same(defaultImport, import),
- import => Assert.Equal("/MyImport.cshtml", import.Filename),
- import => Assert.Equal("/Views/Home/MyImport.cshtml", import.Filename));
+ import => Assert.Equal("/MyImport.cshtml", import.FileName),
+ import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FileName));
}
}
}