Update tests to follow developer guidelines.

- Moved tests to match their corresponding test src files.
- Updated test namespaces to match their corresponding test src files.

#782
This commit is contained in:
N. Taylor Mullen 2016-06-10 12:00:28 -07:00
parent eb2b58188a
commit 9c4eee14b8
84 changed files with 352 additions and 416 deletions

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.CodeGenerators;
using Microsoft.AspNetCore.Razor.Parser;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test
namespace Microsoft.AspNetCore.Razor
{
public class CSharpRazorCodeLanguageTest
{

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Chunks.Generators
namespace Microsoft.AspNetCore.Razor.Chunks
{
public class ChunkTreeBuilderTest
{
@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Razor.Chunks.Generators
var literalChunk = Assert.IsType<ParentLiteralChunk>(chunk);
Assert.Equal(2, literalChunk.Children.Count);
var span = Assert.IsType<Span>(literalChunk.Children[0].Association);
Assert.Same(span, previousSpan);

View File

@ -7,7 +7,7 @@ using Moq;
using Moq.Protected;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Chunks.Generators
namespace Microsoft.AspNetCore.Razor.Chunks
{
public class ChunkVisitorTests
{

View File

@ -5,8 +5,7 @@
using System;
#endif
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test;
using Microsoft.AspNetCore.Razor.Test.Generator;
using Microsoft.AspNetCore.Razor.Test.CodeGenerators;
using Microsoft.AspNetCore.Razor.Test.Utils;
using Moq;
using Xunit;

View File

@ -5,13 +5,12 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.CodeGenerators
{
public class CSharpPaddingBuilderTests
{

View File

@ -4,13 +4,13 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.CodeGenerators;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.CodeGenerators
{
public class RazorCodeGeneratorTest : RazorCodeGeneratorTest<CSharpRazorCodeLanguage>
public class CSharpRazorCodeGeneratorTest : RazorCodeGeneratorTest<CSharpRazorCodeLanguage>
{
protected override string FileExtension
{

View File

@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class CSharpTagHelperRenderingTest : TagHelperTestBase
{
@ -1832,31 +1832,31 @@ namespace Microsoft.AspNetCore.Razor.Test.Generator
documentAbsoluteIndex: 169,
documentLineIndex: 8,
documentCharacterOffsetIndex: 14,
generatedAbsoluteIndex: 1929,
generatedAbsoluteIndex: 1934,
generatedLineIndex: 50,
generatedCharacterOffsetIndex: 96,
generatedCharacterOffsetIndex: 101,
contentLength: 7),
BuildLineMapping(
documentAbsoluteIndex: 196,
documentLineIndex: 9,
documentCharacterOffsetIndex: 14,
generatedAbsoluteIndex: 2312,
generatedAbsoluteIndex: 2322,
generatedLineIndex: 57,
generatedCharacterOffsetIndex: 96,
generatedCharacterOffsetIndex: 101,
contentLength: 13),
BuildLineMapping(
documentAbsoluteIndex: 222,
documentLineIndex: 9,
documentCharacterOffsetIndex: 40,
generatedAbsoluteIndex: 2495,
generatedAbsoluteIndex: 2510,
generatedLineIndex: 62,
generatedCharacterOffsetIndex: 102,
generatedCharacterOffsetIndex: 107,
contentLength: 7),
BuildLineMapping(
documentAbsoluteIndex: 249,
documentLineIndex: 10,
documentCharacterOffsetIndex: 15,
generatedAbsoluteIndex: 2821,
generatedAbsoluteIndex: 2836,
generatedLineIndex: 69,
generatedCharacterOffsetIndex: 39,
contentLength: 9),
@ -1864,7 +1864,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Generator
documentAbsoluteIndex: 272,
documentLineIndex: 10,
documentCharacterOffsetIndex: 38,
generatedAbsoluteIndex: 2943,
generatedAbsoluteIndex: 2958,
generatedLineIndex: 74,
generatedCharacterOffsetIndex: 45,
contentLength: 9),

View File

@ -4,13 +4,13 @@ using Microsoft.AspNetCore.Razor.Chunks;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Microsoft.AspNetCore.Razor.CodeGenerators.Visitors;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Parser.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class CSharpTagHelperRenderingUnitTest
{

View File

@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Razor.CodeGenerators;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class CodeGenTestCodeGenerator : CSharpCodeGenerator
{

View File

@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Razor.CodeGenerators;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class CodeGenTestHost : RazorEngineHost
{

View File

@ -4,7 +4,7 @@
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class LineMappingTest
{

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Razor.Test.Utils;
using Microsoft.AspNetCore.Testing;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public abstract class RazorCodeGeneratorTest<TLanguage>
where TLanguage : RazorCodeLanguage, new()

View File

@ -2,7 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
[Flags]
public enum TabTest

View File

@ -5,13 +5,13 @@ using System;
#if NETCOREAPP1_0
using System.Reflection;
#endif
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Microsoft.AspNetCore.Razor.CodeGenerators.Visitors;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Xunit;
using Microsoft.AspNetCore.Razor.Test.CodeGenerators;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.CodeGenerators
{
public class TagHelperAttributeValueCodeRendererTest : TagHelperTestBase
{

View File

@ -6,12 +6,12 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Microsoft.AspNetCore.Razor.CodeGenerators.Visitors;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class TagHelperTestBase : RazorCodeGeneratorTest
public class TagHelperTestBase : CSharpRazorCodeGeneratorTest
{
protected void RunTagHelperTest(string testName,
string baseLineName = null,

View File

@ -4,7 +4,7 @@
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Test.Generator
namespace Microsoft.AspNetCore.Razor.Test.CodeGenerators
{
public class TestSpan
{

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Internal;
using Newtonsoft.Json;
@ -66,7 +65,7 @@ namespace Microsoft.AspNetCore.Razor.Compilation.TagHelpers
$"\"{ nameof(TagHelperDescriptor.AllowedChildren) }\":[\"allowed child one\"]," +
$"\"{ nameof(TagHelperDescriptor.RequiredParent) }\":\"parent name\"," +
$"\"{ nameof(TagHelperDescriptor.TagStructure) }\":0," +
$"\"{ nameof(TagHelperDescriptor.DesignTimeDescriptor) }\":{{"+
$"\"{ nameof(TagHelperDescriptor.DesignTimeDescriptor) }\":{{" +
$"\"{ nameof(TagHelperDesignTimeDescriptor.Summary) }\":\"usage summary\"," +
$"\"{ nameof(TagHelperDesignTimeDescriptor.Remarks) }\":\"usage remarks\"," +
$"\"{ nameof(TagHelperDesignTimeDescriptor.OutputElementHint) }\":\"some-tag\"}}}}";

View File

@ -2,11 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Parser.SyntaxTree
namespace Microsoft.AspNetCore.Razor.Editor
{
public class AutoCompleteEditHandlerTest
{

View File

@ -4,11 +4,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Parser.SyntaxTree
namespace Microsoft.AspNetCore.Razor.Editor
{
public class ImplicitExpressionEditHandlerTest
{

View File

@ -1,255 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using System.Web.WebPages.TestUtils;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.Generator;
using Microsoft.AspNetCore.Razor.Test.Utils;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Testing;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Editor
{
public class RazorEditorParserTest
{
private static readonly TestFile SimpleCSHTMLDocument = TestFile.Create("TestFiles/DesignTime/Simple.cshtml");
private static readonly TestFile SimpleCSHTMLDocumentGenerated = TestFile.Create("TestFiles/DesignTime/Simple.txt");
private const string TestLinePragmaFileName = "C:\\This\\Path\\Is\\Just\\For\\Line\\Pragmas.cshtml";
[Fact]
public void ConstructorRequiresNonNullPhysicalPath()
{
Assert.Throws<ArgumentException>("sourceFileName", () => new RazorEditorParser(CreateHost(), null));
}
[Fact]
public void ConstructorRequiresNonEmptyPhysicalPath()
{
Assert.Throws<ArgumentException>("sourceFileName", () => new RazorEditorParser(CreateHost(), string.Empty));
}
[Theory]
[InlineData(" ")]
[InlineData("\r\n")]
[InlineData("abcdefg")]
[InlineData("\f\r\n abcd \t")]
public void TreesAreDifferentReturnsFalseForAddedContent(string content)
{
// Arrange
var factory = SpanFactory.CreateCsHtml();
var blockFactory = new BlockFactory(factory);
var original = new MarkupBlock(
blockFactory.MarkupTagBlock("<p>"),
blockFactory.TagHelperBlock(
tagName: "div",
tagMode: TagMode.StartTagAndEndTag,
start: new SourceLocation(3, 0, 3),
startTag: blockFactory.MarkupTagBlock("<div>"),
children: new SyntaxTreeNode[]
{
factory.Markup($"{Environment.NewLine}{Environment.NewLine}")
},
endTag: blockFactory.MarkupTagBlock("</div>")),
blockFactory.MarkupTagBlock("</p>"));
factory.Reset();
var modified = new MarkupBlock(
blockFactory.MarkupTagBlock("<p>"),
blockFactory.TagHelperBlock(
tagName: "div",
tagMode: TagMode.StartTagAndEndTag,
start: new SourceLocation(3, 0, 3),
startTag: blockFactory.MarkupTagBlock("<div>"),
children: new SyntaxTreeNode[]
{
factory.Markup($"{Environment.NewLine}{content}{Environment.NewLine}")
},
endTag: blockFactory.MarkupTagBlock("</div>")),
blockFactory.MarkupTagBlock("</p>"));
original.LinkNodes();
modified.LinkNodes();
var oldBuffer = new StringTextBuffer($"<p><div>{Environment.NewLine}{Environment.NewLine}</div></p>");
var newBuffer = new StringTextBuffer(
$"<p><div>{Environment.NewLine}{content}{Environment.NewLine}</div></p>");
// Act
var treesAreDifferent = BackgroundParser.TreesAreDifferent(
original,
modified,
new[]
{
new TextChange(
position: 8 + Environment.NewLine.Length,
oldLength: 0,
oldBuffer: oldBuffer,
newLength: content.Length,
newBuffer: newBuffer)
});
// Assert
Assert.False(treesAreDifferent);
}
[Fact]
public void TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent()
{
var factory = SpanFactory.CreateCsHtml();
var original = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition()),
factory.Markup("</p>"));
var modified = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition("@"),
factory.Code("f")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
factory.Markup("</p>"));
var oldBuffer = new StringTextBuffer("<p>@</p>");
var newBuffer = new StringTextBuffer("<p>@f</p>");
Assert.True(BackgroundParser.TreesAreDifferent(
original,
modified,
new[]
{
new TextChange(position: 4, oldLength: 0, oldBuffer: oldBuffer, newLength: 1, newBuffer: newBuffer)
}));
}
[Fact]
public void TreesAreDifferentReturnsFalseIfTreeStructureIsSame()
{
var factory = SpanFactory.CreateCsHtml();
var original = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition(),
factory.Code("f")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
factory.Markup("</p>"));
factory.Reset();
var modified = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition(),
factory.Code("foo")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
factory.Markup("</p>"));
original.LinkNodes();
modified.LinkNodes();
var oldBuffer = new StringTextBuffer("<p>@f</p>");
var newBuffer = new StringTextBuffer("<p>@foo</p>");
Assert.False(BackgroundParser.TreesAreDifferent(
original,
modified,
new[]
{
new TextChange(position: 5, oldLength: 0, oldBuffer: oldBuffer, newLength: 2, newBuffer: newBuffer)
}));
}
[Fact]
public void CheckForStructureChangesRequiresNonNullBufferInChange()
{
var change = new TextChange();
var parameterName = "change";
var exception = Assert.Throws<ArgumentException>(
parameterName,
() =>
{
using (var parser = new RazorEditorParser(CreateHost(), "C:\\Foo.cshtml"))
{
parser.CheckForStructureChanges(change);
}
});
ExceptionHelpers.ValidateArgumentException(parameterName, RazorResources.FormatStructure_Member_CannotBeNull(nameof(change.NewBuffer), nameof(TextChange)), exception);
}
private static RazorEngineHost CreateHost()
{
return new CodeGenTestHost(new CSharpRazorCodeLanguage()) { DesignTimeMode = true };
}
[Fact]
[ReplaceCulture]
public void CheckForStructureChangesStartsReparseAndFiresDocumentParseCompletedEventIfNoAdditionalChangesQueued()
{
// Arrange
using (var parser = CreateClientParser())
{
var input = new StringTextBuffer(SimpleCSHTMLDocument.ReadAllText());
DocumentParseCompleteEventArgs capturedArgs = null;
var parseComplete = new ManualResetEventSlim(false);
parser.DocumentParseComplete += (sender, args) =>
{
capturedArgs = args;
parseComplete.Set();
};
// Act
parser.CheckForStructureChanges(new TextChange(0, 0, new StringTextBuffer(string.Empty), input.Length, input));
// Assert
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
Assert.Equal(
SimpleCSHTMLDocumentGenerated.ReadAllText(),
capturedArgs.GeneratorResults.GeneratedCode);
}
}
[Fact]
public void CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans()
{
// Arrange
using (var parser = new RazorEditorParser(CreateHost(), TestLinePragmaFileName))
{
var original = new StringTextBuffer("Foo @bar Baz");
var changed = new StringTextBuffer("Foo @bap Daz");
var change = new TextChange(7, 3, original, 3, changed);
var parseComplete = new ManualResetEventSlim();
var parseCount = 0;
parser.DocumentParseComplete += (sender, args) =>
{
Interlocked.Increment(ref parseCount);
parseComplete.Set();
};
Assert.Equal(PartialParseResult.Rejected, parser.CheckForStructureChanges(new TextChange(0, 0, new StringTextBuffer(string.Empty), 12, original)));
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait); // Wait for the parse to finish
parseComplete.Reset();
// Act
var result = parser.CheckForStructureChanges(change);
// Assert
Assert.Equal(PartialParseResult.Rejected, result);
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
Assert.Equal(2, parseCount);
}
}
private TextChange CreateDummyChange()
{
return new TextChange(0, 0, new StringTextBuffer(string.Empty), 3, new StringTextBuffer("foo"));
}
private static RazorEditorParser CreateClientParser()
{
return new RazorEditorParser(CreateHost(), TestLinePragmaFileName);
}
}
}

View File

@ -3,11 +3,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Parser.SyntaxTree
namespace Microsoft.AspNetCore.Razor.Editor
{
public class SpanEditHandlerTest
{

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
namespace Microsoft.AspNetCore.Razor.Test.Framework
{
internal class RawTextSymbol : ISymbol
public class RawTextSymbol : ISymbol
{
public SourceLocation Start { get; private set; }
public string Content { get; }

View File

@ -4,13 +4,12 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpAutoCompleteTest : CsHtmlCodeParserTestBase
{

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
@ -11,7 +10,7 @@ using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpBlockTest : CsHtmlCodeParserTestBase
{

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpDirectivesTest : CsHtmlCodeParserTestBase
{

View File

@ -3,12 +3,11 @@
using System;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpErrorTest : CsHtmlCodeParserTestBase
{

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpExplicitExpressionTest : CsHtmlCodeParserTestBase
{

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpImplicitExpressionTest : CsHtmlCodeParserTestBase
{

View File

@ -1,12 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpNestedStatementsTest : CsHtmlCodeParserTestBase
{

View File

@ -3,14 +3,13 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpRazorCommentsTest : CsHtmlMarkupParserTestBase
{

View File

@ -1,12 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class CSharpReservedWordsTest : CsHtmlCodeParserTestBase
{

View File

@ -3,14 +3,13 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class CSharpSectionTest : CsHtmlMarkupParserTestBase
{

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class CSharpSpecialBlockTest : CsHtmlCodeParserTestBase
{

View File

@ -3,12 +3,11 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
// Basic Tests for C# Statements:
// * Basic case for each statement

View File

@ -4,15 +4,13 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class CSharpTemplateTest : CsHtmlCodeParserTestBase
{

View File

@ -2,16 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpToMarkupSwitchTest : CsHtmlCodeParserTestBase
{
@ -460,7 +457,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
Factory.Markup(Environment.NewLine).Accepts(AcceptedCharacters.None)
),
Factory.Code(
$" return;{Environment.NewLine} case 2:{Environment.NewLine}"+
$" return;{Environment.NewLine} case 2:{Environment.NewLine}" +
" {" + Environment.NewLine).AsStatement(),
new MarkupBlock(
Factory.Markup(" "),

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpVerbatimBlockTest : CsHtmlCodeParserTestBase
{

View File

@ -3,14 +3,12 @@
using System;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
namespace Microsoft.AspNetCore.Razor.Parser
{
public class CSharpWhitespaceHandlingTest : CsHtmlMarkupParserTestBase
{

View File

@ -2,10 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Parser;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Utils
namespace Microsoft.AspNetCore.Razor.Parser
{
public class DisposableActionTest
{

View File

@ -4,15 +4,14 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.Parser.Internal;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Parser
{
public class HtmlToCodeSwitchTest : CsHtmlMarkupParserTestBase
{

View File

@ -3,15 +3,14 @@
using System;
using System.Threading;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class CallbackParserListenerTest
public class CallbackVisitorTest
{
[Fact]
public void ListenerConstructedWithSpanCallbackCallsCallbackOnEndSpan()

View File

@ -4,14 +4,12 @@
using System;
using System.Linq;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class HtmlAttributeTest : CsHtmlMarkupParserTestBase
{

View File

@ -4,8 +4,6 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
@ -13,7 +11,7 @@ using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class HtmlBlockTest : CsHtmlMarkupParserTestBase
{

View File

@ -4,16 +4,15 @@
using System;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.Utils;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class HtmlDocumentTest : CsHtmlMarkupParserTestBase
{

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class HtmlErrorTest : CsHtmlMarkupParserTestBase
{

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Test.Parser.Internal
{
internal class HtmlParserTestUtils
{

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.Html
namespace Microsoft.AspNetCore.Razor.Parser.Internal
{
public class HtmlTagsTest : CsHtmlMarkupParserTestBase
{

View File

@ -3,16 +3,16 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.Utils;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser
namespace Microsoft.AspNetCore.Razor.Parser
{
public class ParserContextTest
{

View File

@ -3,13 +3,12 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser
namespace Microsoft.AspNetCore.Razor.Parser
{
public class ParserVisitorExtensionsTest
{

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
@ -14,7 +13,7 @@ using Moq;
using Moq.Protected;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser
namespace Microsoft.AspNetCore.Razor.Parser
{
public class RazorParserTest
{

View File

@ -4,12 +4,11 @@
using System.Linq;
using System.Web.WebPages.TestUtils;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser
namespace Microsoft.AspNetCore.Razor.Parser.SyntaxTree
{
public class BlockTest
{

View File

@ -6,16 +6,15 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Parser.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Parser.TagHelpers.Internal;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Compilation.TagHelpers
namespace Microsoft.AspNetCore.Razor.Parser.TagHelpers.Internal
{
public class TagHelperBlockRewriterTest : TagHelperRewritingTestBase
{

View File

@ -6,18 +6,16 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Razor.Chunks.Generators;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.Parser.TagHelpers.Internal;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
using Microsoft.AspNetCore.Razor.Parser.TagHelpers.Internal;
using Microsoft.AspNetCore.Razor.Parser.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser.Internal;
namespace Microsoft.AspNetCore.Razor.Test.TagHelpers
namespace Microsoft.AspNetCore.Razor.Parser.TagHelpers.Internal
{
public class TagHelperParseTreeRewriterTest : TagHelperRewritingTestBase
{

View File

@ -3,15 +3,14 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.TagHelpers.Internal;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
namespace Microsoft.AspNetCore.Razor.Test.TagHelpers
namespace Microsoft.AspNetCore.Razor.Test.Parser.TagHelpers.Internal
{
public class TagHelperRewritingTestBase : CsHtmlMarkupParserTestBase
{

View File

@ -4,16 +4,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.Parser.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.Extensions.Internal;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Compilation.TagHelpers
namespace Microsoft.AspNetCore.Razor.Parser.TagHelpers.Internal
{
public class TagHelperDirectiveSpanVisitorTest
{

View File

@ -3,11 +3,9 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Text
namespace Microsoft.AspNetCore.Razor.Parser
{
public class TextReaderExtensionsTest
{

View File

@ -1,12 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser
namespace Microsoft.AspNetCore.Razor.Parser
{
public class WhitespaceRewriterTest
{

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Razor.Test.Utils;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.PartialParsing
namespace Microsoft.AspNetCore.Razor
{
public abstract class PartialParsingTestBase<TLanguage>
where TLanguage : RazorCodeLanguage, new()

View File

@ -3,7 +3,7 @@
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test
namespace Microsoft.AspNetCore.Razor
{
public class RazorCodeLanguageTest
{

View File

@ -2,17 +2,241 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using System.Web.WebPages.TestUtils;
using Microsoft.AspNetCore.Razor.Editor;
using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.SyntaxTree;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Razor.Test.CodeGenerators;
using Microsoft.AspNetCore.Razor.Test.Framework;
using Microsoft.AspNetCore.Razor.Test.Utils;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Testing;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Parser.PartialParsing
namespace Microsoft.AspNetCore.Razor
{
public class CSharpPartialParsingTest : PartialParsingTestBase<CSharpRazorCodeLanguage>
public class RazorEditorParserTest : PartialParsingTestBase<CSharpRazorCodeLanguage>
{
private static readonly TestFile SimpleCSHTMLDocument = TestFile.Create("TestFiles/DesignTime/Simple.cshtml");
private static readonly TestFile SimpleCSHTMLDocumentGenerated = TestFile.Create("TestFiles/DesignTime/Simple.txt");
private const string TestLinePragmaFileName = "C:\\This\\Path\\Is\\Just\\For\\Line\\Pragmas.cshtml";
[Fact]
public void ConstructorRequiresNonNullPhysicalPath()
{
Assert.Throws<ArgumentException>("sourceFileName", () => new RazorEditorParser(CreateCodeGenTestHost(), null));
}
[Fact]
public void ConstructorRequiresNonEmptyPhysicalPath()
{
Assert.Throws<ArgumentException>("sourceFileName", () => new RazorEditorParser(CreateCodeGenTestHost(), string.Empty));
}
[Theory]
[InlineData(" ")]
[InlineData("\r\n")]
[InlineData("abcdefg")]
[InlineData("\f\r\n abcd \t")]
public void TreesAreDifferentReturnsFalseForAddedContent(string content)
{
// Arrange
var factory = SpanFactory.CreateCsHtml();
var blockFactory = new BlockFactory(factory);
var original = new MarkupBlock(
blockFactory.MarkupTagBlock("<p>"),
blockFactory.TagHelperBlock(
tagName: "div",
tagMode: TagMode.StartTagAndEndTag,
start: new SourceLocation(3, 0, 3),
startTag: blockFactory.MarkupTagBlock("<div>"),
children: new SyntaxTreeNode[]
{
factory.Markup($"{Environment.NewLine}{Environment.NewLine}")
},
endTag: blockFactory.MarkupTagBlock("</div>")),
blockFactory.MarkupTagBlock("</p>"));
factory.Reset();
var modified = new MarkupBlock(
blockFactory.MarkupTagBlock("<p>"),
blockFactory.TagHelperBlock(
tagName: "div",
tagMode: TagMode.StartTagAndEndTag,
start: new SourceLocation(3, 0, 3),
startTag: blockFactory.MarkupTagBlock("<div>"),
children: new SyntaxTreeNode[]
{
factory.Markup($"{Environment.NewLine}{content}{Environment.NewLine}")
},
endTag: blockFactory.MarkupTagBlock("</div>")),
blockFactory.MarkupTagBlock("</p>"));
original.LinkNodes();
modified.LinkNodes();
var oldBuffer = new StringTextBuffer($"<p><div>{Environment.NewLine}{Environment.NewLine}</div></p>");
var newBuffer = new StringTextBuffer(
$"<p><div>{Environment.NewLine}{content}{Environment.NewLine}</div></p>");
// Act
var treesAreDifferent = BackgroundParser.TreesAreDifferent(
original,
modified,
new[]
{
new TextChange(
position: 8 + Environment.NewLine.Length,
oldLength: 0,
oldBuffer: oldBuffer,
newLength: content.Length,
newBuffer: newBuffer)
});
// Assert
Assert.False(treesAreDifferent);
}
[Fact]
public void TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent()
{
var factory = SpanFactory.CreateCsHtml();
var original = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition()),
factory.Markup("</p>"));
var modified = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition("@"),
factory.Code("f")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
factory.Markup("</p>"));
var oldBuffer = new StringTextBuffer("<p>@</p>");
var newBuffer = new StringTextBuffer("<p>@f</p>");
Assert.True(BackgroundParser.TreesAreDifferent(
original,
modified,
new[]
{
new TextChange(position: 4, oldLength: 0, oldBuffer: oldBuffer, newLength: 1, newBuffer: newBuffer)
}));
}
[Fact]
public void TreesAreDifferentReturnsFalseIfTreeStructureIsSame()
{
var factory = SpanFactory.CreateCsHtml();
var original = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition(),
factory.Code("f")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
factory.Markup("</p>"));
factory.Reset();
var modified = new MarkupBlock(
factory.Markup("<p>"),
new ExpressionBlock(
factory.CodeTransition(),
factory.Code("foo")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
factory.Markup("</p>"));
original.LinkNodes();
modified.LinkNodes();
var oldBuffer = new StringTextBuffer("<p>@f</p>");
var newBuffer = new StringTextBuffer("<p>@foo</p>");
Assert.False(BackgroundParser.TreesAreDifferent(
original,
modified,
new[]
{
new TextChange(position: 5, oldLength: 0, oldBuffer: oldBuffer, newLength: 2, newBuffer: newBuffer)
}));
}
[Fact]
public void CheckForStructureChangesRequiresNonNullBufferInChange()
{
var change = new TextChange();
var parameterName = "change";
var exception = Assert.Throws<ArgumentException>(
parameterName,
() =>
{
using (var parser = new RazorEditorParser(CreateCodeGenTestHost(), "C:\\Foo.cshtml"))
{
parser.CheckForStructureChanges(change);
}
});
ExceptionHelpers.ValidateArgumentException(parameterName, RazorResources.FormatStructure_Member_CannotBeNull(nameof(change.NewBuffer), nameof(TextChange)), exception);
}
[Fact]
[ReplaceCulture]
public void CheckForStructureChangesStartsReparseAndFiresDocumentParseCompletedEventIfNoAdditionalChangesQueued()
{
// Arrange
using (var parser = new RazorEditorParser(CreateCodeGenTestHost(), TestLinePragmaFileName))
{
var input = new StringTextBuffer(SimpleCSHTMLDocument.ReadAllText());
DocumentParseCompleteEventArgs capturedArgs = null;
var parseComplete = new ManualResetEventSlim(false);
parser.DocumentParseComplete += (sender, args) =>
{
capturedArgs = args;
parseComplete.Set();
};
// Act
parser.CheckForStructureChanges(new TextChange(0, 0, new StringTextBuffer(string.Empty), input.Length, input));
// Assert
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
Assert.Equal(
SimpleCSHTMLDocumentGenerated.ReadAllText(),
capturedArgs.GeneratorResults.GeneratedCode);
}
}
[Fact]
public void CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans()
{
// Arrange
using (var parser = new RazorEditorParser(CreateHost(), TestLinePragmaFileName))
{
var original = new StringTextBuffer("Foo @bar Baz");
var changed = new StringTextBuffer("Foo @bap Daz");
var change = new TextChange(7, 3, original, 3, changed);
var parseComplete = new ManualResetEventSlim();
var parseCount = 0;
parser.DocumentParseComplete += (sender, args) =>
{
Interlocked.Increment(ref parseCount);
parseComplete.Set();
};
Assert.Equal(PartialParseResult.Rejected, parser.CheckForStructureChanges(new TextChange(0, 0, new StringTextBuffer(string.Empty), 12, original)));
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait); // Wait for the parse to finish
parseComplete.Reset();
// Act
var result = parser.CheckForStructureChanges(change);
// Assert
Assert.Equal(PartialParseResult.Rejected, result);
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
Assert.Equal(2, parseCount);
}
}
[Fact]
public void AwaitPeriodInsertionAcceptedProvisionally()
{
@ -669,5 +893,10 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser.PartialParsing
{
RunTypeKeywordTest("class");
}
private static RazorEngineHost CreateCodeGenTestHost()
{
return new CodeGenTestHost(new CSharpRazorCodeLanguage()) { DesignTimeMode = true };
}
}
}

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Razor.Parser;
using Microsoft.AspNetCore.Razor.Parser.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test
namespace Microsoft.AspNetCore.Razor
{
public class RazorEngineHostTest
{

View File

@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Razor.Text;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test
namespace Microsoft.AspNetCore.Razor
{
public class RazorTemplateEngineTest
{

View File

@ -48,19 +48,19 @@ __TestNamespace_InputTagHelper.Value = MyEnum.MyValue;
__TestNamespace_InputTagHelper = CreateTagHelper<global::TestNamespace.InputTagHelper>();
__TestNamespace_CatchAllTagHelper = CreateTagHelper<global::TestNamespace.CatchAllTagHelper>();
#line 9 "EnumTagHelpers.cshtml"
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.Generator.MyEnum.MyValue;
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.CodeGenerators.MyEnum.MyValue;
#line default
#line hidden
__TestNamespace_InputTagHelper = CreateTagHelper<global::TestNamespace.InputTagHelper>();
__TestNamespace_CatchAllTagHelper = CreateTagHelper<global::TestNamespace.CatchAllTagHelper>();
#line 10 "EnumTagHelpers.cshtml"
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.Generator.MyEnum.MySecondValue;
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.CodeGenerators.MyEnum.MySecondValue;
#line default
#line hidden
#line 10 "EnumTagHelpers.cshtml"
__TestNamespace_CatchAllTagHelper.CatchAll = global::Microsoft.AspNetCore.Razor.Test.Generator.MyEnum.MyValue;
__TestNamespace_CatchAllTagHelper.CatchAll = global::Microsoft.AspNetCore.Razor.Test.CodeGenerators.MyEnum.MyValue;
#line default
#line hidden

View File

@ -89,7 +89,7 @@ AddHtmlAttributeValue("", 128, MyEnum.MySecondValue, 128, 21, false);
__TestNamespace_CatchAllTagHelper = CreateTagHelper<global::TestNamespace.CatchAllTagHelper>();
__tagHelperExecutionContext.Add(__TestNamespace_CatchAllTagHelper);
#line 9 "EnumTagHelpers.cshtml"
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.Generator.MyEnum.MyValue;
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.CodeGenerators.MyEnum.MyValue;
#line default
#line hidden
@ -110,13 +110,13 @@ __TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.G
__TestNamespace_CatchAllTagHelper = CreateTagHelper<global::TestNamespace.CatchAllTagHelper>();
__tagHelperExecutionContext.Add(__TestNamespace_CatchAllTagHelper);
#line 10 "EnumTagHelpers.cshtml"
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.Generator.MyEnum.MySecondValue;
__TestNamespace_InputTagHelper.Value = global::Microsoft.AspNetCore.Razor.Test.CodeGenerators.MyEnum.MySecondValue;
#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("value", __TestNamespace_InputTagHelper.Value, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
#line 10 "EnumTagHelpers.cshtml"
__TestNamespace_CatchAllTagHelper.CatchAll = global::Microsoft.AspNetCore.Razor.Test.Generator.MyEnum.MyValue;
__TestNamespace_CatchAllTagHelper.CatchAll = global::Microsoft.AspNetCore.Razor.Test.CodeGenerators.MyEnum.MyValue;
#line default
#line hidden

View File

@ -1,10 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Text
namespace Microsoft.AspNetCore.Razor.Text
{
public class LineTrackingStringBufferTest
{

View File

@ -3,10 +3,9 @@
using System;
using System.Text;
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Text
namespace Microsoft.AspNetCore.Razor.Text
{
public abstract class LookaheadTextReaderTestBase
{

View File

@ -1,10 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Text;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Text
namespace Microsoft.AspNetCore.Razor.Text
{
public class SourceLocationTrackerTest
{

View File

@ -3,11 +3,11 @@
using System;
using System.Web.WebPages.TestUtils;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Test.Utils;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Text
namespace Microsoft.AspNetCore.Razor.Text
{
public class TextChangeTest
{

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class CSharpTokenizerCommentTest : CSharpTokenizerTestBase
{

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class CSharpTokenizerIdentifierTest : CSharpTokenizerTestBase
{

View File

@ -2,10 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class CSharpTokenizerLiteralTest : CSharpTokenizerTestBase
{

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class CSharpTokenizerOperatorsTest : CSharpTokenizerTestBase
{

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class CSharpTokenizerTest : CSharpTokenizerTestBase
{

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Tokenizer;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal
{
public abstract class CSharpTokenizerTestBase : TokenizerTestBase<CSharpSymbol, CSharpSymbolType>
{

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class HtmlTokenizerTest : HtmlTokenizerTestBase
{

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Tokenizer;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal
{
public abstract class HtmlTokenizerTestBase : TokenizerTestBase<HtmlSymbol, HtmlSymbolType>
{

View File

@ -5,14 +5,13 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Razor.Test.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Text;
using Microsoft.AspNetCore.Razor.Tokenizer;
using Microsoft.AspNetCore.Razor.Tokenizer.Internal;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols;
using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test.Tokenizer
namespace Microsoft.AspNetCore.Razor.Tokenizer.Internal
{
public class TokenizerLookaheadTest : HtmlTokenizerTestBase
{

View File

@ -4,7 +4,7 @@
using System;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test
namespace Microsoft.AspNetCore.Razor.Test.Utils
{
public static class ExceptionHelpers
{

View File

@ -6,7 +6,7 @@ using System.IO;
using System.Reflection;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Test
namespace Microsoft.AspNetCore.Razor.Test.Utils
{
public class TestFile
{