Make usage of FileName and FilePath consistent
FileName => "Foo.cshtml" FilePath => "/Bar/Baz/Foo.cshtml"
This commit is contained in:
parent
6ce71c24e5
commit
6860806213
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
ClassDeclarationIRNode @class,
|
||||
MethodDeclarationIRNode method)
|
||||
{
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FileName;
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath;
|
||||
|
||||
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
||||
@class.Name = CSharpIdentifier.GetClassNameFromPath(filePath);
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
return;
|
||||
}
|
||||
|
||||
if (TryComputeNamespace(codeDocument.Source.FileName, directive, out var computedNamespace))
|
||||
if (TryComputeNamespace(codeDocument.Source.FilePath, directive, out var computedNamespace))
|
||||
{
|
||||
// Beautify the class name since we're using a hierarchy for namespaces.
|
||||
var @class = visitor.FirstClass;
|
||||
var prefix = CSharpIdentifier.SanitizeClassName(Path.GetFileNameWithoutExtension(codeDocument.Source.FileName));
|
||||
var prefix = CSharpIdentifier.SanitizeClassName(Path.GetFileNameWithoutExtension(codeDocument.Source.FilePath));
|
||||
if (@class != null && irDocument.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind)
|
||||
{
|
||||
@class.Name = prefix + "_Page";
|
||||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
// This code does a best-effort attempt to compute a namespace 'suffix' - the path difference between
|
||||
// where the @namespace directive appears and where the current document is on disk.
|
||||
//
|
||||
// In the event that these two source either don't have filenames set or don't follow a coherent hierarchy,
|
||||
// In the event that these two source either don't have FileNames set or don't follow a coherent hierarchy,
|
||||
// we will just use the namespace verbatim.
|
||||
internal static bool TryComputeNamespace(string source, DirectiveIRNode directive, out string @namespace)
|
||||
{
|
||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
|
||||
var segments = source.Substring(directiveSource.Length).Split(Separators);
|
||||
|
||||
// Skip the last segment because it's the filename.
|
||||
// Skip the last segment because it's the FileName.
|
||||
for (var i = 0; i < segments.Length - 1; i++)
|
||||
{
|
||||
builder.Append('.');
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
ClassDeclarationIRNode @class,
|
||||
MethodDeclarationIRNode method)
|
||||
{
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FileName;
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath;
|
||||
|
||||
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
||||
@class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page";
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
return;
|
||||
}
|
||||
|
||||
if (SourceDocument.FileName != null &&
|
||||
!string.Equals(SourceDocument.FileName, node.Source.Value.FilePath, StringComparison.OrdinalIgnoreCase))
|
||||
if (SourceDocument.FilePath != null &&
|
||||
!string.Equals(SourceDocument.FilePath, node.Source.Value.FilePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// We don't want to generate line mappings for imports.
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
var tokenKind = node.Descriptor.Kind;
|
||||
if (!node.Source.HasValue ||
|
||||
!string.Equals(
|
||||
context.SourceDocument?.FileName,
|
||||
context.SourceDocument?.FilePath,
|
||||
node.Source.Value.FilePath,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
{
|
||||
context.Writer
|
||||
.Write("#pragma checksum \"")
|
||||
.Write(node.FileName)
|
||||
.Write(node.FilePath)
|
||||
.Write("\" \"")
|
||||
.Write(node.Guid)
|
||||
.Write("\" \"")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
var import = imports[j];
|
||||
|
||||
importsVisitor.FileName = import.Source.FileName;
|
||||
importsVisitor.FilePath = import.Source.FilePath;
|
||||
importsVisitor.VisitBlock(import.Root);
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var tagHelperPrefix = tagHelperContext?.Prefix;
|
||||
var visitor = new MainSourceVisitor(document, builder, namespaces, tagHelperPrefix)
|
||||
{
|
||||
FileName = syntaxTree.Source.FileName,
|
||||
FilePath = syntaxTree.Source.FilePath,
|
||||
};
|
||||
|
||||
visitor.VisitBlock(syntaxTree.Root);
|
||||
|
|
@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
_namespaces = namespaces;
|
||||
}
|
||||
|
||||
public string FileName { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public override void VisitImportSpan(AddImportChunkGenerator chunkGenerator, Span span)
|
||||
{
|
||||
|
|
@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
}
|
||||
|
||||
var span = new SourceSpan(
|
||||
node.Start.FilePath ?? FileName,
|
||||
node.Start.FilePath ?? FilePath,
|
||||
node.Start.AbsoluteIndex,
|
||||
node.Start.LineIndex,
|
||||
node.Start.CharacterIndex,
|
||||
|
|
@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
if (location != SourceLocation.Undefined)
|
||||
{
|
||||
valueSpan = new SourceSpan(
|
||||
location.FilePath ?? FileName,
|
||||
location.FilePath ?? FilePath,
|
||||
location.AbsoluteIndex,
|
||||
location.LineIndex,
|
||||
location.CharacterIndex,
|
||||
|
|
@ -369,7 +369,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var contentLength = templateNode.Children.Sum(child => child.Source?.Length ?? 0);
|
||||
|
||||
templateNode.Source = new SourceSpan(
|
||||
sourceRangeStart.Value.FilePath ?? FileName,
|
||||
sourceRangeStart.Value.FilePath ?? FilePath,
|
||||
sourceRangeStart.Value.AbsoluteIndex,
|
||||
sourceRangeStart.Value.LineIndex,
|
||||
sourceRangeStart.Value.CharacterIndex,
|
||||
|
|
@ -412,7 +412,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var contentLength = expressionNode.Children.Sum(child => child.Source?.Length ?? 0);
|
||||
|
||||
expressionNode.Source = new SourceSpan(
|
||||
sourceRangeStart.Value.FilePath ?? FileName,
|
||||
sourceRangeStart.Value.FilePath ?? FilePath,
|
||||
sourceRangeStart.Value.AbsoluteIndex,
|
||||
sourceRangeStart.Value.LineIndex,
|
||||
sourceRangeStart.Value.CharacterIndex,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// 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.FilePath, position, index, characterIndex: 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -59,12 +59,12 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
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.FilePath, position, 0, position);
|
||||
}
|
||||
else
|
||||
{
|
||||
var characterIndex = position - _lineStarts[index];
|
||||
return new SourceLocation(_document.FileName, position, index, characterIndex);
|
||||
return new SourceLocation(_document.FilePath, position, index, characterIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
|
|||
|
||||
public string Bytes { get; set; }
|
||||
|
||||
public string FileName { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public string Guid { get; set; }
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
|
|||
|
||||
var node = new ChecksumIRNode()
|
||||
{
|
||||
FileName = sourceDocument.FileName,
|
||||
FilePath = sourceDocument.FilePath,
|
||||
Guid = Sha1AlgorithmId
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
_chunkMaxLength = chunkMaxLength;
|
||||
Encoding = encoding;
|
||||
FileName = fileName;
|
||||
FilePath = fileName;
|
||||
|
||||
ReadChunks(reader, _chunkMaxLength, out _length, out _chunks);
|
||||
_lines = new DefaultRazorSourceLineCollection(this);
|
||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override Encoding Encoding { get; }
|
||||
|
||||
public override string FileName { get; }
|
||||
public override string FilePath { get; }
|
||||
|
||||
public override int Length => _length;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
var chars = new char[source.Length];
|
||||
source.CopyTo(0, chars, 0, source.Length);
|
||||
|
||||
Source = new SeekableTextReader(chars, source.FileName);
|
||||
Source = new SeekableTextReader(chars, source.FilePath);
|
||||
DesignTimeMode = options.DesignTime;
|
||||
ParseOnlyLeadingDirectives = options.ParseOnlyLeadingDirectives;
|
||||
Builder = new SyntaxTreeBuilder();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
/// <summary>
|
||||
/// Path of the file the content was read from.
|
||||
/// </summary>
|
||||
public abstract string FileName { get; }
|
||||
public abstract string FilePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a character at given position.
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override Encoding Encoding => _innerSourceDocument.Encoding;
|
||||
|
||||
public override string FileName => _innerSourceDocument.FileName;
|
||||
public override string FilePath => _innerSourceDocument.FilePath;
|
||||
|
||||
public override int Length => _innerSourceDocument.Length;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
private readonly RazorSourceLineCollection _lines;
|
||||
private byte[] _checksum;
|
||||
|
||||
public StringSourceDocument(string content, Encoding encoding, string fileName)
|
||||
public StringSourceDocument(string content, Encoding encoding, string filePath)
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
_content = content;
|
||||
Encoding = encoding;
|
||||
FileName = fileName;
|
||||
FilePath = filePath;
|
||||
|
||||
_lines = new DefaultRazorSourceLineCollection(this);
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override Encoding Encoding { get; }
|
||||
|
||||
public override string FileName { get; }
|
||||
public override string FilePath { get; }
|
||||
|
||||
public override int Length => _content.Length;
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
|
|||
return Task.FromResult(directives ?? Enumerable.Empty<DirectiveDescriptor>());
|
||||
}
|
||||
|
||||
public Task<GeneratedDocument> GenerateDocumentAsync(Guid projectIdBytes, string projectDebugName, string filename, string text, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<GeneratedDocument> GenerateDocumentAsync(Guid projectIdBytes, string projectDebugName, string filePath, string text, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var projectId = ProjectId.CreateFromSerialized(projectIdBytes, projectDebugName);
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
|
|||
stream.Write(bytes, 0, bytes.Length);
|
||||
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
source = RazorSourceDocument.ReadFrom(stream, filename, Encoding.UTF8);
|
||||
source = RazorSourceDocument.ReadFrom(stream, filePath, Encoding.UTF8);
|
||||
}
|
||||
|
||||
var code = RazorCodeDocument.Create(source);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
[Export(typeof(IRazorEngineDocumentGenerator))]
|
||||
internal class DefaultRazorEngineDocumentGenerator : IRazorEngineDocumentGenerator
|
||||
{
|
||||
public async Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filename, string text, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public async Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filePath, string text, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
|
||||
using (var session = await client.CreateSessionAsync(project.Solution))
|
||||
{
|
||||
var document = await session.InvokeAsync<RazorEngineDocument>("GenerateDocumentAsync", new object[] { project.Id.Id, "Foo", filename, text }).ConfigureAwait(false);
|
||||
var document = await session.InvokeAsync<RazorEngineDocument>("GenerateDocumentAsync", new object[] { project.Id.Id, "Foo", filePath, text }).ConfigureAwait(false);
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
var span = spans[i];
|
||||
result[i] = new ClassifiedSpan(
|
||||
new SourceSpan(
|
||||
span.Start.FilePath ?? syntaxTree.Source.FileName,
|
||||
span.Start.FilePath ?? syntaxTree.Source.FilePath,
|
||||
span.Start.AbsoluteIndex,
|
||||
span.Start.LineIndex,
|
||||
span.Start.CharacterIndex,
|
||||
span.Length),
|
||||
new SourceSpan(
|
||||
span.Parent.Start.FilePath ?? syntaxTree.Source.FileName,
|
||||
span.Parent.Start.FilePath ?? syntaxTree.Source.FilePath,
|
||||
span.Parent.Start.AbsoluteIndex,
|
||||
span.Parent.Start.LineIndex,
|
||||
span.Parent.Start.CharacterIndex,
|
||||
|
|
@ -111,7 +111,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
{
|
||||
results.Add(new TagHelperSpan(
|
||||
new SourceSpan(
|
||||
tagHelperNode.Start.FilePath ?? syntaxTree.Source.FileName,
|
||||
tagHelperNode.Start.FilePath ?? syntaxTree.Source.FilePath,
|
||||
tagHelperNode.Start.AbsoluteIndex,
|
||||
tagHelperNode.Start.LineIndex,
|
||||
tagHelperNode.Start.CharacterIndex,
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
throw new ArgumentNullException(nameof(textBuffer));
|
||||
}
|
||||
|
||||
// If there's no document we can't find the filename, or look for a matching hierarchy.
|
||||
// If there's no document we can't find the FileName, or look for a matching hierarchy.
|
||||
if (!_documentFactory.TryGetTextDocument(textBuffer, out var textDocument))
|
||||
{
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
{
|
||||
internal interface IRazorEngineDocumentGenerator
|
||||
{
|
||||
Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filename, string text, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filePath, string text, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -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.FilePath);
|
||||
@class.AccessModifier = "internal";
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -614,7 +614,7 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
var text = new string(buffer);
|
||||
text = Regex.Replace(text, "(?<!\r)\n", "\r\n");
|
||||
|
||||
imports.Add(RazorSourceDocument.Create(text, DefaultImports.FileName, DefaultImports.Encoding));
|
||||
imports.Add(RazorSourceDocument.Create(text, DefaultImports.FilePath, DefaultImports.Encoding));
|
||||
}
|
||||
|
||||
private static MetadataReference BuildDynamicAssembly(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
var sourceFileName = sourceDocument.FileName;
|
||||
var sourceFilePath = sourceDocument.FilePath;
|
||||
var charBuffer = new char[sourceDocument.Length];
|
||||
sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length);
|
||||
var sourceContent = new string(charBuffer);
|
||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
for (var i = 0; i < csharpDocument.LineMappings.Count; i++)
|
||||
{
|
||||
var lineMapping = csharpDocument.LineMappings[i];
|
||||
if (!string.Equals(lineMapping.OriginalSpan.FilePath, sourceFileName, StringComparison.Ordinal))
|
||||
if (!string.Equals(lineMapping.OriginalSpan.FilePath, sourceFilePath, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
Assert.Equal("AddUser_Page", @class.Name);
|
||||
}
|
||||
|
||||
// Handles cases where invalid characters appears in filenames. Note that we don't sanitize the part of
|
||||
// Handles cases where invalid characters appears in FileNames. Note that we don't sanitize the part of
|
||||
// the namespace that you put in an import, just the file-based-suffix. Garbage in, garbage out.
|
||||
[Fact]
|
||||
public void Pass_SetsNamespaceAndClassName_SanitizesClassAndNamespace()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
var node = new ChecksumIRNode()
|
||||
{
|
||||
FileName = "test.cshtml",
|
||||
FilePath = "test.cshtml",
|
||||
Guid = "SomeGuid",
|
||||
Bytes = "SomeFileHash"
|
||||
};
|
||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
var node = new ChecksumIRNode()
|
||||
{
|
||||
FileName = "test.cshtml",
|
||||
FilePath = "test.cshtml",
|
||||
Guid = "SomeGuid",
|
||||
Bytes = string.Empty
|
||||
};
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var codeDocument = TestRazorCodeDocument.Create(@"@using System");
|
||||
var expectedSourceLocation = new SourceSpan(codeDocument.Source.FileName, 1, 0, 1, 12);
|
||||
var expectedSourceLocation = new SourceSpan(codeDocument.Source.FilePath, 1, 0, 1, 12);
|
||||
|
||||
// Act
|
||||
var irDocument = Lower(codeDocument);
|
||||
|
|
|
|||
|
|
@ -838,7 +838,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var errorSink = new ErrorSink();
|
||||
var phase = new DefaultRazorTagHelperBinderPhase();
|
||||
var document = RazorCodeDocument.Create(new StringSourceDocument("Test content", encoding: Encoding.UTF8, fileName: "TestFile"));
|
||||
var document = RazorCodeDocument.Create(new StringSourceDocument("Test content", encoding: Encoding.UTF8, filePath: "TestFile"));
|
||||
|
||||
// Act
|
||||
var prefix = phase.ProcessTagHelperPrefix(((IEnumerable<TagHelperDirectiveDescriptor>)directiveDescriptors).ToList(), document, errorSink);
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
public void GenerateCodeWithDefaults()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||
var content = File.ReadAllText(filePath);
|
||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
||||
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
|
|
@ -33,9 +33,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
public void GenerateCodeWithBaseType()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||
var content = File.ReadAllText(filePath);
|
||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
||||
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
|
|
@ -54,9 +54,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
public void GenerateCodeWithConfigureClass()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||
var content = File.ReadAllText(filePath);
|
||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
||||
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
|
|
@ -88,9 +88,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
public void GenerateCodeWithSetNamespace()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
||||
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||
var content = File.ReadAllText(filePath);
|
||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
||||
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -99,17 +99,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Test
|
|||
[Theory]
|
||||
[InlineData("test.cshtml")]
|
||||
[InlineData(null)]
|
||||
public void Filename(string fileName)
|
||||
public void FilePath(string filePath)
|
||||
{
|
||||
// Arrange
|
||||
var stream = TestRazorSourceDocument.CreateStreamContent("abc");
|
||||
var reader = new StreamReader(stream, true);
|
||||
|
||||
// Act
|
||||
var document = new LargeTextSourceDocument(reader, ChunkTestLength, Encoding.UTF8, fileName);
|
||||
var document = new LargeTextSourceDocument(reader, ChunkTestLength, Encoding.UTF8, filePath);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(fileName, document.FileName);
|
||||
Assert.Equal(filePath, document.FilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
Assert.IsType<StreamSourceDocument>(document);
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
Assert.Same(Encoding.UTF8, document.Encoding);
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
Assert.Same(Encoding.UTF32, Assert.IsType<StreamSourceDocument>(document).Encoding);
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
Assert.Same(Encoding.UTF32, Assert.IsType<StreamSourceDocument>(document).Encoding);
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = RazorSourceDocument.ReadFrom(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(projectItem.PhysicalPath, document.FileName);
|
||||
Assert.Equal(projectItem.PhysicalPath, document.FilePath);
|
||||
Assert.Equal(projectItem.Content, ReadContent(document));
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = RazorSourceDocument.ReadFrom(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(projectItem.Path, document.FileName);
|
||||
Assert.Equal(projectItem.Path, document.FilePath);
|
||||
Assert.Equal(projectItem.Content, ReadContent(document));
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = RazorSourceDocument.Create(content, fileName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(fileName, document.FileName);
|
||||
Assert.Equal(fileName, document.FilePath);
|
||||
Assert.Equal(content, ReadContent(document));
|
||||
Assert.Same(Encoding.UTF8, document.Encoding);
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = RazorSourceDocument.Create(content, fileName, encoding);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(fileName, document.FileName);
|
||||
Assert.Equal(fileName, document.FilePath);
|
||||
Assert.Equal(content, ReadContent(document));
|
||||
Assert.Same(encoding, document.Encoding);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
var import = Assert.Single(imports);
|
||||
Assert.Equal(projectItem.Path, import.FileName);
|
||||
Assert.Equal(projectItem.Path, import.FilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -207,8 +207,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// 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.FilePath),
|
||||
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FilePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -236,8 +236,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// 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.FilePath),
|
||||
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FilePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
Assert.IsType<StreamSourceDocument>(document);
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
Assert.Equal(Encoding.UTF32, document.Encoding);
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
Assert.IsType<StreamSourceDocument>(document);
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
Assert.Equal(Encoding.UTF32, document.Encoding);
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Assert
|
||||
var streamDocument = Assert.IsType<StreamSourceDocument>(document);
|
||||
Assert.IsType<LargeTextSourceDocument>(streamDocument._innerSourceDocument);
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
Assert.Same(Encoding.UTF8, document.Encoding);
|
||||
Assert.Equal(content, ReadContent(document));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var expectedContent = "Hello, World!";
|
||||
var indexerBuffer = new char[expectedContent.Length];
|
||||
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, fileName: "file.cshtml");
|
||||
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, filePath: "file.cshtml");
|
||||
|
||||
// Act
|
||||
for (var i = 0; i < document.Length; i++)
|
||||
|
|
@ -78,36 +78,36 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var expectedContent = "Hello, World!";
|
||||
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, fileName: "file.cshtml");
|
||||
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, filePath: "file.cshtml");
|
||||
|
||||
// Act & Assert
|
||||
Assert.Equal(expectedContent.Length, document.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Filename()
|
||||
public void FilePath()
|
||||
{
|
||||
// Arrange
|
||||
var content = "Hello, World!";
|
||||
|
||||
// Act
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: "file.cshtml");
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: "file.cshtml");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("file.cshtml", document.FileName);
|
||||
Assert.Equal("file.cshtml", document.FilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Filename_Null()
|
||||
public void FilePath_Null()
|
||||
{
|
||||
// Arrange
|
||||
var content = "Hello, World!";
|
||||
|
||||
// Act
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Assert
|
||||
Assert.Null(document.FileName);
|
||||
Assert.Null(document.FilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "Hello, World!";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
var expectedContent = "Hello";
|
||||
var charBuffer = new char[expectedContent.Length];
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "Hello, World!";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
var expectedContent = "$Hello";
|
||||
var charBuffer = new char[expectedContent.Length];
|
||||
charBuffer[0] = '$';
|
||||
|
|
@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "Hello, World!";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
var expectedContent = "World";
|
||||
var charBuffer = new char[expectedContent.Length];
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "Hi";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
var charBuffer = new char[2];
|
||||
|
||||
// Act
|
||||
|
|
@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "Hi";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act & Assert
|
||||
//
|
||||
|
|
@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = string.Empty;
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.Count;
|
||||
|
|
@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = string.Empty;
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLineLength(0);
|
||||
|
|
@ -230,7 +230,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "hello\n";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLineLength(0);
|
||||
|
|
@ -244,7 +244,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
// Arrange
|
||||
var content = "hello\r\n";
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLineLength(0);
|
||||
|
|
@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
.Append("jumps over the lazy dog.")
|
||||
.ToString();
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -293,7 +293,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\rWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -309,7 +309,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\rBig\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -324,7 +324,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\u0085World!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -354,7 +354,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\u2028World!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -369,7 +369,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\u2029World!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
|
|
@ -384,7 +384,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello, World!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: "Hi.cshtml");
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: "Hi.cshtml");
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLocation(1);
|
||||
|
|
@ -402,7 +402,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\nBig\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLocation(0);
|
||||
|
|
@ -418,7 +418,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\nBig\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLocation(5);
|
||||
|
|
@ -434,7 +434,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\nBig\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLocation(7);
|
||||
|
|
@ -450,7 +450,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\nBig\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLocation(11);
|
||||
|
|
@ -466,7 +466,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Arrange
|
||||
var content = "Hello\nBig\r\nWorld!";
|
||||
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
||||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = document.Lines.GetLocation(16);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
public abstract class IntegrationTestBase
|
||||
{
|
||||
#if !NET46
|
||||
private static readonly AsyncLocal<string> _filename = new AsyncLocal<string>();
|
||||
private static readonly AsyncLocal<string> _fileName = new AsyncLocal<string>();
|
||||
#endif
|
||||
|
||||
protected IntegrationTestBase()
|
||||
|
|
@ -40,53 +40,53 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
protected string TestProjectRoot { get; }
|
||||
|
||||
// Used by the test framework to set the 'base' name for test files.
|
||||
public static string Filename
|
||||
public static string FileName
|
||||
{
|
||||
#if NET46
|
||||
get
|
||||
{
|
||||
var handle = (ObjectHandle)CallContext.LogicalGetData("IntegrationTestBase_Filename");
|
||||
var handle = (ObjectHandle)CallContext.LogicalGetData("IntegrationTestBase_FileName");
|
||||
return (string)handle.Unwrap();
|
||||
}
|
||||
set
|
||||
{
|
||||
CallContext.LogicalSetData("IntegrationTestBase_Filename", new ObjectHandle(value));
|
||||
CallContext.LogicalSetData("IntegrationTestBase_FileName", new ObjectHandle(value));
|
||||
}
|
||||
#elif NETCOREAPP2_0
|
||||
get { return _filename.Value; }
|
||||
set { _filename.Value = value; }
|
||||
get { return _fileName.Value; }
|
||||
set { _fileName.Value = value; }
|
||||
#endif
|
||||
}
|
||||
|
||||
protected virtual RazorCodeDocument CreateCodeDocument()
|
||||
{
|
||||
if (Filename == null)
|
||||
if (FileName == null)
|
||||
{
|
||||
var message = $"{nameof(CreateCodeDocument)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||
var message = $"{nameof(CreateCodeDocument)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
var suffixIndex = Filename.LastIndexOf("_");
|
||||
var normalizedFileName = suffixIndex == -1 ? Filename : Filename.Substring(0, suffixIndex);
|
||||
var sourceFilename = Path.ChangeExtension(normalizedFileName, ".cshtml");
|
||||
var testFile = TestFile.Create(sourceFilename, GetType().GetTypeInfo().Assembly);
|
||||
var suffixIndex = FileName.LastIndexOf("_");
|
||||
var normalizedFileName = suffixIndex == -1 ? FileName : FileName.Substring(0, suffixIndex);
|
||||
var sourceFileName = Path.ChangeExtension(normalizedFileName, ".cshtml");
|
||||
var testFile = TestFile.Create(sourceFileName, GetType().GetTypeInfo().Assembly);
|
||||
if (!testFile.Exists())
|
||||
{
|
||||
throw new XunitException($"The resource {sourceFilename} was not found.");
|
||||
throw new XunitException($"The resource {sourceFileName} was not found.");
|
||||
}
|
||||
|
||||
var source = TestRazorSourceDocument.CreateResource(sourceFilename, GetType(), normalizeNewLines: true);
|
||||
var source = TestRazorSourceDocument.CreateResource(sourceFileName, GetType(), normalizeNewLines: true);
|
||||
|
||||
var imports = new List<RazorSourceDocument>();
|
||||
while (true)
|
||||
{
|
||||
var importsFilename = Path.ChangeExtension(normalizedFileName + "_Imports" + imports.Count.ToString(), ".cshtml");
|
||||
if (!TestFile.Create(importsFilename, GetType().GetTypeInfo().Assembly).Exists())
|
||||
var importsFileName = Path.ChangeExtension(normalizedFileName + "_Imports" + imports.Count.ToString(), ".cshtml");
|
||||
if (!TestFile.Create(importsFileName, GetType().GetTypeInfo().Assembly).Exists())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
imports.Add(TestRazorSourceDocument.CreateResource(importsFilename, GetType(), normalizeNewLines: true));
|
||||
imports.Add(TestRazorSourceDocument.CreateResource(importsFileName, GetType(), normalizeNewLines: true));
|
||||
}
|
||||
|
||||
OnCreatingCodeDocument(ref source, imports);
|
||||
|
|
@ -114,25 +114,25 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
|
||||
protected void AssertIRMatchesBaseline(DocumentIRNode document)
|
||||
{
|
||||
if (Filename == null)
|
||||
if (FileName == null)
|
||||
{
|
||||
var message = $"{nameof(AssertIRMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||
var message = $"{nameof(AssertIRMatchesBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
var baselineFilename = Path.ChangeExtension(Filename, ".ir.txt");
|
||||
var baselineFileName = Path.ChangeExtension(FileName, ".ir.txt");
|
||||
|
||||
if (GenerateBaselines)
|
||||
{
|
||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename);
|
||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
|
||||
File.WriteAllText(baselineFullPath, RazorIRNodeSerializer.Serialize(document));
|
||||
return;
|
||||
}
|
||||
|
||||
var irFile = TestFile.Create(baselineFilename, GetType().GetTypeInfo().Assembly);
|
||||
var irFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);
|
||||
if (!irFile.Exists())
|
||||
{
|
||||
throw new XunitException($"The resource {baselineFilename} was not found.");
|
||||
throw new XunitException($"The resource {baselineFileName} was not found.");
|
||||
}
|
||||
|
||||
var baseline = irFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
|
@ -141,21 +141,21 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
|
||||
protected void AssertCSharpDocumentMatchesBaseline(RazorCSharpDocument document)
|
||||
{
|
||||
if (Filename == null)
|
||||
if (FileName == null)
|
||||
{
|
||||
var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||
var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
var baselineFilename = Path.ChangeExtension(Filename, ".codegen.cs");
|
||||
var baselineDiagnosticsFilename = Path.ChangeExtension(Filename, ".diagnostics.txt");
|
||||
var baselineFileName = Path.ChangeExtension(FileName, ".codegen.cs");
|
||||
var baselineDiagnosticsFileName = Path.ChangeExtension(FileName, ".diagnostics.txt");
|
||||
|
||||
if (GenerateBaselines)
|
||||
{
|
||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename);
|
||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
|
||||
File.WriteAllText(baselineFullPath, document.GeneratedCode);
|
||||
|
||||
var baselineDiagnosticsFullPath = Path.Combine(TestProjectRoot, baselineDiagnosticsFilename);
|
||||
var baselineDiagnosticsFullPath = Path.Combine(TestProjectRoot, baselineDiagnosticsFileName);
|
||||
var lines = document.Diagnostics.Select(RazorDiagnosticSerializer.Serialize).ToArray();
|
||||
if (lines.Any())
|
||||
{
|
||||
|
|
@ -169,10 +169,10 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
return;
|
||||
}
|
||||
|
||||
var codegenFile = TestFile.Create(baselineFilename, GetType().GetTypeInfo().Assembly);
|
||||
var codegenFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);
|
||||
if (!codegenFile.Exists())
|
||||
{
|
||||
throw new XunitException($"The resource {baselineFilename} was not found.");
|
||||
throw new XunitException($"The resource {baselineFileName} was not found.");
|
||||
}
|
||||
|
||||
var baseline = codegenFile.ReadAllText();
|
||||
|
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
Assert.Equal(baseline, actual);
|
||||
|
||||
var baselineDiagnostics = string.Empty;
|
||||
var diagnosticsFile = TestFile.Create(baselineDiagnosticsFilename, GetType().GetTypeInfo().Assembly);
|
||||
var diagnosticsFile = TestFile.Create(baselineDiagnosticsFileName, GetType().GetTypeInfo().Assembly);
|
||||
if (diagnosticsFile.Exists())
|
||||
{
|
||||
baselineDiagnostics = diagnosticsFile.ReadAllText();
|
||||
|
|
@ -194,29 +194,29 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
|
||||
protected void AssertLineMappingsMatchBaseline(RazorCodeDocument document)
|
||||
{
|
||||
if (Filename == null)
|
||||
if (FileName == null)
|
||||
{
|
||||
var message = $"{nameof(AssertLineMappingsMatchBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||
var message = $"{nameof(AssertLineMappingsMatchBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
var csharpDocument = document.GetCSharpDocument();
|
||||
Assert.NotNull(csharpDocument);
|
||||
|
||||
var baselineFilename = Path.ChangeExtension(Filename, ".mappings.txt");
|
||||
var baselineFileName = Path.ChangeExtension(FileName, ".mappings.txt");
|
||||
var serializedMappings = LineMappingsSerializer.Serialize(csharpDocument, document.Source);
|
||||
|
||||
if (GenerateBaselines)
|
||||
{
|
||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename);
|
||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
|
||||
File.WriteAllText(baselineFullPath, serializedMappings);
|
||||
return;
|
||||
}
|
||||
|
||||
var testFile = TestFile.Create(baselineFilename, GetType().GetTypeInfo().Assembly);
|
||||
var testFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);
|
||||
if (!testFile.Exists())
|
||||
{
|
||||
throw new XunitException($"The resource {baselineFilename} was not found.");
|
||||
throw new XunitException($"The resource {baselineFileName} was not found.");
|
||||
}
|
||||
|
||||
var baseline = testFile.ReadAllText();
|
||||
|
|
@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
{
|
||||
public override void VisitClassDeclaration(ClassDeclarationIRNode node)
|
||||
{
|
||||
node.Name = Filename.Replace('/', '_');
|
||||
node.Name = FileName.Replace('/', '_');
|
||||
node.AccessModifier = "public";
|
||||
|
||||
VisitDefault(node);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
if (typeof(IntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
|
||||
{
|
||||
var typeName = methodUnderTest.DeclaringType.Name;
|
||||
IntegrationTestBase.Filename = $"TestFiles/IntegrationTests/{typeName}/{methodUnderTest.Name}";
|
||||
IntegrationTestBase.FileName = $"TestFiles/IntegrationTests/{typeName}/{methodUnderTest.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
{
|
||||
if (typeof(IntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
|
||||
{
|
||||
IntegrationTestBase.Filename = null;
|
||||
IntegrationTestBase.FileName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue