From f045c6792b7d62697cd748d45fe38205b1aab136 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 17 Sep 2015 22:37:31 -0700 Subject: [PATCH] Allow _ViewImports to remove default inherited tag helpers. Additionally simplifying the contract for ChunkInheritaceUtility\IChunkMerger so we don't have to understand the order in which CodeTrees appear. --- .../Directives/ChunkHelper.cs | 28 ------- .../Directives/ChunkInheritanceUtility.cs | 44 +++++----- .../Directives/IChunkMerger.cs | 5 +- .../Directives/InjectChunkMerger.cs | 27 +++--- .../Directives/SetBaseTypeChunkMerger.cs | 32 ++++--- .../Directives/UsingChunkMerger.cs | 25 +++--- .../MvcRazorParser.cs | 11 +-- .../Properties/Resources.Designer.cs | 16 ---- .../Resources.resx | 57 ++++++------- .../TagHelpersTest.cs | 13 +++ .../Directives/ChunkInheritanceUtilityTest.cs | 53 ++++++------ .../Directives/InjectChunkMergerTest.cs | 84 +++++++++++-------- .../Directives/SetBaseTypeChunkMergerTest.cs | 48 ++++------- .../Directives/UsingChunkMergerTest.cs | 58 ++++++------- .../MvcRazorParserTest.cs | 15 ++-- .../TestFiles/Output/DesignTime/Basic.cs | 8 +- .../TestFiles/Output/DesignTime/Inject.cs | 8 +- .../Output/DesignTime/InjectWithModel.cs | 4 +- .../Output/DesignTime/InjectWithSemicolon.cs | 4 +- .../TestFiles/Output/DesignTime/Model.cs | 8 +- .../DesignTime/ModelExpressionTagHelper.cs | 8 +- .../TestFiles/Output/Runtime/Basic.cs | 8 +- .../TestFiles/Output/Runtime/Inject.cs | 8 +- .../Output/Runtime/InjectWithModel.cs | 4 +- .../Output/Runtime/InjectWithSemicolon.cs | 4 +- .../TestFiles/Output/Runtime/Model.cs | 8 +- .../Runtime/ModelExpressionTagHelper.cs | 8 +- ...oveDefaultInheritedTagHelpersController.cs | 12 +++ .../Index.cshtml | 4 + .../_ViewImports.cshtml | 1 + 30 files changed, 300 insertions(+), 313 deletions(-) create mode 100644 test/WebSites/TagHelpersWebSite/Controllers/RemoveDefaultInheritedTagHelpersController.cs create mode 100644 test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/Index.cshtml create mode 100644 test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/_ViewImports.cshtml diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs index 5053193f02..2ef280e31b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using Microsoft.AspNet.Mvc.Razor.Host; using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -15,33 +14,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { private const string TModelToken = ""; - /// - /// Attempts to cast the passed in to type and throws if the - /// cast fails. - /// - /// The type to cast to. - /// The chunk to cast. - /// The cast to . - /// is not an instance of - /// . - public static TChunk EnsureChunk(Chunk chunk) - where TChunk : Chunk - { - if (chunk == null) - { - throw new ArgumentNullException(nameof(chunk)); - } - - var chunkOfT = chunk as TChunk; - if (chunkOfT == null) - { - var message = Resources.FormatArgumentMustBeOfType(typeof(TChunk).FullName); - throw new ArgumentException(message, nameof(chunk)); - } - - return chunkOfT; - } - /// /// Returns the used to determine the model name for the page generated /// using the specified diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs index 3ec945d00e..e4711d9e6e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs @@ -63,6 +63,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives /// The path of the page to locate inherited chunks for. /// A of parsed _ViewImports /// s and their file paths. + /// + /// The resulting is ordered so that the result + /// for a _ViewImport closest to the application root appears first and the _ViewImport + /// closest to the page appears last i.e. + /// [ /_ViewImport, /Views/_ViewImport, /Views/Home/_ViewImport ] + /// public virtual IReadOnlyList GetInheritedChunkTreeResults(string pagePath) { if (pagePath == null) @@ -88,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives if (chunkTree != null) { var result = new ChunkTreeResult(chunkTree, viewImportsPath); - inheritedChunkTreeResults.Add(result); + inheritedChunkTreeResults.Insert(0, result); } } @@ -102,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives /// The to merge in to. /// inherited from _ViewImports /// files. - /// The list of chunks to merge. + /// The default model name. public void MergeInheritedChunkTrees( ChunkTree chunkTree, IReadOnlyList inheritedChunkTrees, @@ -118,44 +124,34 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives throw new ArgumentNullException(nameof(inheritedChunkTrees)); } - var mergerMappings = GetMergerMappings(chunkTree, defaultModel); - IChunkMerger merger; - + var chunkMergers = GetChunkMergers(chunkTree, defaultModel); // We merge chunks into the ChunkTree in two passes. In the first pass, we traverse the ChunkTree visiting // a mapped IChunkMerger for types that are registered. foreach (var chunk in chunkTree.Chunks) { - if (mergerMappings.TryGetValue(chunk.GetType(), out merger)) + foreach (var merger in chunkMergers) { merger.VisitChunk(chunk); } } - // In the second phase we invoke IChunkMerger.Merge for each chunk that has a mapped merger. - // During this phase, the merger can either add to the ChunkTree or ignore the chunk based on the merging - // rules. - // Read the chunks outside in - that is chunks from the _ViewImports closest to the page get merged in first - // and the furthest one last. This allows the merger to ignore a directive like @model that was previously - // seen. - var chunksToMerge = inheritedChunkTrees.SelectMany(tree => tree.Chunks) - .Concat(_defaultInheritedChunks); - foreach (var chunk in chunksToMerge) + var inheritedChunks = _defaultInheritedChunks.Concat( + inheritedChunkTrees.SelectMany(tree => tree.Chunks)).ToArray(); + + foreach (var merger in chunkMergers) { - if (mergerMappings.TryGetValue(chunk.GetType(), out merger)) - { - merger.Merge(chunkTree, chunk); - } + merger.MergeInheritedChunks(chunkTree, inheritedChunks); } } - private static Dictionary GetMergerMappings(ChunkTree chunkTree, string defaultModel) + private static IChunkMerger[] GetChunkMergers(ChunkTree chunkTree, string defaultModel) { var modelType = ChunkHelper.GetModelTypeName(chunkTree, defaultModel); - return new Dictionary + return new IChunkMerger[] { - { typeof(UsingChunk), new UsingChunkMerger() }, - { typeof(InjectChunk), new InjectChunkMerger(modelType) }, - { typeof(SetBaseTypeChunk), new SetBaseTypeChunkMerger(modelType) } + new UsingChunkMerger(), + new InjectChunkMerger(modelType), + new SetBaseTypeChunkMerger(modelType) }; } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs index e12c23213f..fbef21fcf6 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs @@ -1,6 +1,7 @@ // 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.Collections.Generic; using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives /// Merges an inherited into the . /// /// The to merge into. - /// The to merge. - void Merge(ChunkTree chunkTree, Chunk chunk); + /// The s to merge. + void MergeInheritedChunks(ChunkTree chunkTree, IReadOnlyList inheritedChunks); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs index 60e305657e..99f8354532 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -37,29 +38,35 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives throw new ArgumentNullException(nameof(chunk)); } - var injectChunk = ChunkHelper.EnsureChunk(chunk); - injectChunk.TypeName = ChunkHelper.ReplaceTModel(injectChunk.TypeName, _modelType); - _addedMemberNames.Add(injectChunk.MemberName); + var injectChunk = chunk as InjectChunk; + if (injectChunk != null) + { + injectChunk.TypeName = ChunkHelper.ReplaceTModel(injectChunk.TypeName, _modelType); + _addedMemberNames.Add(injectChunk.MemberName); + } } /// - public void Merge(ChunkTree chunkTree, Chunk chunk) + public void MergeInheritedChunks(ChunkTree chunkTree, IReadOnlyList inheritedChunks) { if (chunkTree == null) { throw new ArgumentNullException(nameof(chunkTree)); } - if (chunk == null) + if (inheritedChunks == null) { - throw new ArgumentNullException(nameof(chunk)); + throw new ArgumentNullException(nameof(inheritedChunks)); } - var injectChunk = ChunkHelper.EnsureChunk(chunk); - if (!_addedMemberNames.Contains(injectChunk.MemberName)) + for (var i = inheritedChunks.Count - 1; i >= 0; i--) { - _addedMemberNames.Add(injectChunk.MemberName); - chunkTree.Chunks.Add(TransformChunk(injectChunk)); + var injectChunk = inheritedChunks[i] as InjectChunk; + if (injectChunk != null && + _addedMemberNames.Add(injectChunk.MemberName)) + { + chunkTree.Chunks.Add(TransformChunk(injectChunk)); + } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs index 6235c6466d..18802ec877 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -31,32 +33,38 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives throw new ArgumentNullException(nameof(chunk)); } - var setBaseTypeChunk = ChunkHelper.EnsureChunk(chunk); - setBaseTypeChunk.TypeName = ChunkHelper.ReplaceTModel(setBaseTypeChunk.TypeName, _modelType); - _isBaseTypeSet = true; + var setBaseTypeChunk = chunk as SetBaseTypeChunk; + if (setBaseTypeChunk != null) + { + setBaseTypeChunk.TypeName = ChunkHelper.ReplaceTModel(setBaseTypeChunk.TypeName, _modelType); + _isBaseTypeSet = true; + } } /// - public void Merge(ChunkTree chunkTree, Chunk chunk) + public void MergeInheritedChunks(ChunkTree chunkTree, IReadOnlyList inheritedChunks) { if (chunkTree == null) { throw new ArgumentNullException(nameof(chunkTree)); } - if (chunk == null) + if (inheritedChunks == null) { - throw new ArgumentNullException(nameof(chunk)); + throw new ArgumentNullException(nameof(inheritedChunks)); } if (!_isBaseTypeSet) { - var baseTypeChunk = ChunkHelper.EnsureChunk(chunk); - - // The base type can set exactly once and the first one we encounter wins. - _isBaseTypeSet = true; - - chunkTree.Chunks.Add(TransformChunk(baseTypeChunk)); + for (var i = inheritedChunks.Count - 1; i >= 0; i--) + { + var baseTypeChunk = inheritedChunks[i] as SetBaseTypeChunk; + if (baseTypeChunk != null) + { + chunkTree.Chunks.Add(TransformChunk(baseTypeChunk)); + break; + } + } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs index a8b8cc1bd0..896aae6f7b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -22,29 +23,33 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives throw new ArgumentNullException(nameof(chunk)); } - var namespaceChunk = ChunkHelper.EnsureChunk(chunk); - _currentUsings.Add(namespaceChunk.Namespace); + var namespaceChunk = chunk as UsingChunk; + if (namespaceChunk != null) + { + _currentUsings.Add(namespaceChunk.Namespace); + } } /// - public void Merge(ChunkTree chunkTree, Chunk chunk) + public void MergeInheritedChunks(ChunkTree chunkTree, IReadOnlyList inheritedChunks) { if (chunkTree == null) { throw new ArgumentNullException(nameof(chunkTree)); } - if (chunk == null) + if (inheritedChunks == null) { - throw new ArgumentNullException(nameof(chunk)); + throw new ArgumentNullException(nameof(inheritedChunks)); } - var namespaceChunk = ChunkHelper.EnsureChunk(chunk); - - if (!_currentUsings.Contains(namespaceChunk.Namespace)) + var namespaceChunks = inheritedChunks.OfType(); + foreach (var namespaceChunk in namespaceChunks) { - _currentUsings.Add(namespaceChunk.Namespace); - chunkTree.Chunks.Add(namespaceChunk); + if (_currentUsings.Add(namespaceChunk.Namespace)) + { + chunkTree.Chunks.Add(namespaceChunk); + } } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs index 4e39469c35..862fb6db7b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs @@ -117,15 +117,8 @@ namespace Microsoft.AspNet.Mvc.Razor { var descriptors = new List(); - // For tag helpers, the @removeTagHelper only applies tag helpers that were added prior to it. - // Consequently we must visit tag helpers outside-in - furthest _ViewImports first and nearest one last. - // This is different from the behavior of chunk merging where we visit the nearest one first and ignore - // chunks that were previously visited. - var chunksFromViewImports = inheritedChunkTrees - .Reverse() - .SelectMany(tree => tree.Chunks); - var chunksInOrder = defaultInheritedChunks.Concat(chunksFromViewImports); - foreach (var chunk in chunksInOrder) + var inheritedChunks = defaultInheritedChunks.Concat(inheritedChunkTrees.SelectMany(tree => tree.Chunks)); + foreach (var chunk in inheritedChunks) { // All TagHelperDirectiveDescriptors created here have undefined source locations because the source // that created them is not in the same file. diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Properties/Resources.Designer.cs index 272b2a49b8..9546523379 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Properties/Resources.Designer.cs @@ -26,22 +26,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Host return GetString("ArgumentCannotBeNullOrEmpy"); } - /// - /// Argument must be an instance of '{0}'. - /// - internal static string ArgumentMustBeOfType - { - get { return GetString("ArgumentMustBeOfType"); } - } - - /// - /// Argument must be an instance of '{0}'. - /// - internal static string FormatArgumentMustBeOfType(object p0) - { - return string.Format(CultureInfo.CurrentCulture, GetString("ArgumentMustBeOfType"), p0); - } - /// /// The 'inherits' keyword is not allowed when a '{0}' keyword is used. /// diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Resources.resx b/src/Microsoft.AspNet.Mvc.Razor.Host/Resources.resx index d3d51166bc..a1c3afc652 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Resources.resx +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Resources.resx @@ -1,17 +1,17 @@ - @@ -120,9 +120,6 @@ Value cannot be null or empty. - - Argument must be an instance of '{0}'. - The 'inherits' keyword is not allowed when a '{0}' keyword is used. diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs index bb76b5a41a..5d56c2c6fc 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs @@ -152,6 +152,19 @@ page:root-content" Assert.Equal(expected, result.Trim(), ignoreLineEndingDifferences: true); } + [Fact] + public async Task DefaultInheritedTagsCanBeRemoved() + { + // Arrange + var expected = +@"Virtual path"; + + var result = await Client.GetStringAsync("RemoveDefaultInheritedTagHelpers"); + + // Assert + Assert.Equal(expected, result.Trim(), ignoreLineEndingDifferences: true); + } + [Fact] public async Task ViewsWithModelMetadataAttributes_CanRenderForm() { diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs index 7a43d8690b..0fec67f0bf 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs @@ -40,28 +40,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Assert Assert.Collection(chunkTreeResults, - chunkTreeResult => - { - var viewImportsPath = PlatformNormalizer.NormalizePath(@"Views\home\_ViewImports.cshtml"); - Assert.Collection(chunkTreeResult.ChunkTree.Chunks, - chunk => - { - Assert.IsType(chunk); - Assert.Equal(viewImportsPath, chunk.Start.FilePath); - }, - chunk => - { - var usingChunk = Assert.IsType(chunk); - Assert.Equal("MyNamespace", usingChunk.Namespace); - Assert.Equal(viewImportsPath, chunk.Start.FilePath); - }, - chunk => - { - Assert.IsType(chunk); - Assert.Equal(viewImportsPath, chunk.Start.FilePath); - }); - Assert.Equal(viewImportsPath, chunkTreeResult.FilePath); - }, chunkTreeResult => { var viewImportsPath = PlatformNormalizer.NormalizePath(@"Views\_ViewImports.cshtml"); @@ -88,7 +66,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var setBaseTypeChunk = Assert.IsType(chunk); Assert.Equal("MyBaseType", setBaseTypeChunk.TypeName); Assert.Equal(viewImportsPath, chunk.Start.FilePath); - }, chunk => { @@ -106,6 +83,28 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives Assert.Equal(viewImportsPath, chunk.Start.FilePath); }); Assert.Equal(viewImportsPath, chunkTreeResult.FilePath); + }, + chunkTreeResult => + { + var viewImportsPath = PlatformNormalizer.NormalizePath(@"Views\home\_ViewImports.cshtml"); + Assert.Collection(chunkTreeResult.ChunkTree.Chunks, + chunk => + { + Assert.IsType(chunk); + Assert.Equal(viewImportsPath, chunk.Start.FilePath); + }, + chunk => + { + var usingChunk = Assert.IsType(chunk); + Assert.Equal("MyNamespace", usingChunk.Namespace); + Assert.Equal(viewImportsPath, chunk.Start.FilePath); + }, + chunk => + { + Assert.IsType(chunk); + Assert.Equal(viewImportsPath, chunk.Start.FilePath); + }); + Assert.Equal(viewImportsPath, chunkTreeResult.FilePath); }); } @@ -173,10 +172,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives utility.MergeInheritedChunkTrees(chunkTree, inheritedChunkTrees, "dynamic"); // Assert - Assert.Equal(3, chunkTree.Chunks.Count); - Assert.Same(inheritedChunkTrees[0].Chunks[0], chunkTree.Chunks[0]); - Assert.Same(inheritedChunkTrees[1].Chunks[0], chunkTree.Chunks[1]); - Assert.Same(defaultChunks[0], chunkTree.Chunks[2]); + Assert.Collection(chunkTree.Chunks, + chunk => Assert.Same(defaultChunks[1], chunk), + chunk => Assert.Same(inheritedChunkTrees[0].Chunks[0], chunk), + chunk => Assert.Same(defaultChunks[0], chunk)); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs index 41a3bbf451..14fbc0fd4f 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs @@ -2,24 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Razor.Chunks; -using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.Razor.Directives { public class InjectChunkMergerTest { - [Fact] - public void Visit_ThrowsIfThePassedInChunkIsNotAInjectChunk() - { - // Arrange - var expected = "Argument must be an instance of 'Microsoft.AspNet.Mvc.Razor.InjectChunk'."; - var merger = new InjectChunkMerger("dynamic"); - - // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.VisitChunk(new LiteralChunk()), "chunk", expected); - } - [Theory] [InlineData("MyApp.TestHelper", "MyApp.TestHelper")] [InlineData("TestBaseType", "TestBaseType")] @@ -37,17 +25,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives Assert.Equal("TestHelper", chunk.MemberName); } - [Fact] - public void Merge_ThrowsIfThePassedInChunkIsNotAInjectChunk() - { - // Arrange - var expected = "Argument must be an instance of 'Microsoft.AspNet.Mvc.Razor.InjectChunk'."; - var merger = new InjectChunkMerger("dynamic"); - - // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected); - } - [Fact] public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInChunkTree() { @@ -56,9 +33,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var expectedProperty = "MyHelper"; var merger = new InjectChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new InjectChunk(expectedType, expectedProperty) + }; // Act - merger.Merge(chunkTree, new InjectChunk(expectedType, expectedProperty)); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert var chunk = Assert.Single(chunkTree.Chunks); @@ -73,10 +54,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Arrange var merger = new InjectChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new InjectChunk("MyTypeB", "MyProperty") + }; // Act merger.VisitChunk(new InjectChunk("MyTypeA", "MyProperty")); - merger.Merge(chunkTree, new InjectChunk("MyTypeB", "MyProperty")); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert Assert.Empty(chunkTree.Chunks); @@ -88,11 +73,15 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Arrange var merger = new InjectChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new InjectChunk("MyTypeB", "different-property"), + new InjectChunk("MyType", "myproperty"), + }; // Act merger.VisitChunk(new InjectChunk("MyType", "MyProperty")); - merger.Merge(chunkTree, new InjectChunk("MyType", "myproperty")); - merger.Merge(chunkTree, new InjectChunk("MyTypeB", "different-property")); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert Assert.Equal(2, chunkTree.Chunks.Count); @@ -111,9 +100,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Arrange var merger = new InjectChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new InjectChunk("MyHelper", "MyProperty") + }; // Act - merger.Merge(chunkTree, new InjectChunk("MyHelper", "MyProperty")); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert var chunk = Assert.Single(chunkTree.Chunks); @@ -128,9 +121,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Arrange var merger = new InjectChunkMerger("MyTestModel2"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new InjectChunk("MyHelper", "MyProperty") + }; // Act - merger.Merge(chunkTree, new InjectChunk("MyHelper", "MyProperty")); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert var chunk = Assert.Single(chunkTree.Chunks); @@ -140,21 +137,36 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } [Fact] - public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasPreviouslyMerged() + public void Merge_UsesTheLastInjectChunkOfAPropertyName() { // Arrange var merger = new InjectChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new Chunk[] + { + new LiteralChunk(), + new InjectChunk("SomeOtherType", "Property"), + new InjectChunk("DifferentPropertyType", "DifferentProperty"), + new InjectChunk("SomeType", "Property"), + }; // Act - merger.Merge(chunkTree, new InjectChunk("SomeType", "Property")); - merger.Merge(chunkTree, new InjectChunk("SomeOtherType", "Property")); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert - var chunk = Assert.Single(chunkTree.Chunks); - var injectChunk = Assert.IsType(chunk); - Assert.Equal("SomeType", injectChunk.TypeName); - Assert.Equal("Property", injectChunk.MemberName); + Assert.Collection(chunkTree.Chunks, + chunk => + { + var injectChunk = Assert.IsType(chunk); + Assert.Equal("SomeType", injectChunk.TypeName); + Assert.Equal("Property", injectChunk.MemberName); + }, + chunk => + { + var injectChunk = Assert.IsType(chunk); + Assert.Equal("DifferentPropertyType", injectChunk.TypeName); + Assert.Equal("DifferentProperty", injectChunk.MemberName); + }); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs index 5142e455cc..16bf468625 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs @@ -2,25 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Razor.Chunks; -using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.Razor.Directives { public class SetBaseTypeChunkMergerTest { - [Fact] - public void Visit_ThrowsIfThePassedInChunkIsNotASetBaseTypeChunk() - { - // Arrange - var expected = "Argument must be an instance of " + - "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'."; - var merger = new SetBaseTypeChunkMerger("dynamic"); - - // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.VisitChunk(new LiteralChunk()), "chunk", expected); - } - [Theory] [InlineData("MyApp.BaseType", "MyApp.BaseType")] [InlineData("TestBaseType", "TestBaseType")] @@ -40,18 +27,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives Assert.Equal(expectedValue, chunk.TypeName); } - [Fact] - public void Merge_ThrowsIfThePassedInChunkIsNotASetBaseTypeChunk() - { - // Arrange - var expected = "Argument must be an instance of " + - "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'."; - var merger = new SetBaseTypeChunkMerger("dynamic"); - - // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected); - } - [Fact] public void Merge_SetsBaseTypeIfItHasNotBeenSetInChunkTree() { @@ -59,9 +34,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var expected = "MyApp.Razor.MyBaseType"; var merger = new SetBaseTypeChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new SetBaseTypeChunk { TypeName = expected } + }; // Act - merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = expected }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert var chunk = Assert.Single(chunkTree.Chunks); @@ -75,25 +54,34 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Arrange var merger = new SetBaseTypeChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new SetBaseTypeChunk { TypeName = "MyBaseType2" } + }; // Act merger.VisitChunk(new SetBaseTypeChunk { TypeName = "MyBaseType1" }); - merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert Assert.Empty(chunkTree.Chunks); } [Fact] - public void Merge_IgnoresSetBaseTypeChunksIfSetBaseTypeWasPreviouslyMerged() + public void Merge_PicksLastBaseTypeChunkFromChunkTree() { // Arrange var merger = new SetBaseTypeChunkMerger("dynamic"); var chunkTree = new ChunkTree(); + var inheritedChunks = new Chunk[] + { + new SetBaseTypeChunk { TypeName = "MyBase2" }, + new LiteralChunk(), + new SetBaseTypeChunk { TypeName = "MyBase1" }, + }; // Act - merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase1" }); - merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase2" }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert var chunk = Assert.Single(chunkTree.Chunks); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs index 58ea1daa8d..47d70d457d 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs @@ -9,28 +9,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { public class UsingChunkMergerTest { - [Fact] - public void Visit_ThrowsIfThePassedInChunkIsNotAUsingChunk() - { - // Arrange - var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Chunks.UsingChunk'."; - var merger = new UsingChunkMerger(); - - // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.VisitChunk(new LiteralChunk()), "chunk", expected); - } - - [Fact] - public void Merge_ThrowsIfThePassedInChunkIsNotAUsingChunk() - { - // Arrange - var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Chunks.UsingChunk'."; - var merger = new UsingChunkMerger(); - - // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected); - } - [Fact] public void Merge_AddsNamespacesThatHaveNotBeenVisitedInChunkTree() { @@ -38,10 +16,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var expected = "MyApp.Models"; var merger = new UsingChunkMerger(); var chunkTree = new ChunkTree(); + var inheritedChunks = new Chunk[] + { + new UsingChunk { Namespace = expected }, + }; // Act merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(chunkTree, new UsingChunk { Namespace = expected }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert var chunk = Assert.Single(chunkTree.Chunks); @@ -55,26 +37,36 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Arrange var merger = new UsingChunkMerger(); var chunkTree = new ChunkTree(); + var inheritedChunks = new Chunk[] + { + new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }, + new InjectChunk("Foo", "Bar") + }; // Act merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert Assert.Empty(chunkTree.Chunks); } [Fact] - public void Merge_IgnoresNamespacesThatHaveBeenVisitedDuringMerge() + public void Merge_DoesNotAddMoreThanOneInstanceOfTheSameInheritedNamespace() { // Arrange var merger = new UsingChunkMerger(); var chunkTree = new ChunkTree(); + var inheritedChunks = new Chunk[] + { + new LiteralChunk(), + new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }, + new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }, + new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" } + }; // Act - merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert Assert.Equal(2, chunkTree.Chunks.Count); @@ -85,15 +77,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } [Fact] - public void Merge_MacthesNamespacesInCaseSensitiveManner() + public void Merge_MatchesNamespacesInCaseSensitiveManner() { // Arrange var merger = new UsingChunkMerger(); var chunkTree = new ChunkTree(); + var inheritedChunks = new[] + { + new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }, + new UsingChunk { Namespace = "Microsoft.AspNet.mvc" } + }; // Act - merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.mvc" }); + merger.MergeInheritedChunks(chunkTree, inheritedChunks); // Assert Assert.Equal(2, chunkTree.Chunks.Count); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs index df6845c59a..c7348d3e9c 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Parser; @@ -66,8 +65,8 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), }, new[] { CreateDirectiveDescriptor("THP1", TagHelperDirectiveType.TagHelperPrefix) } }, @@ -89,10 +88,10 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { + CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }), CreateChunkTree( new LiteralChunk { Text = "Hello world" }, new AddTagHelperChunk { LookupText = "ATH" }), - CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }) }, new[] { @@ -103,11 +102,11 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }), + CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }), CreateChunkTree( new LiteralChunk { Text = "Hello world" }, new AddTagHelperChunk { LookupText = "ATH" }), - CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }) + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }), }, new[] { @@ -119,10 +118,10 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), - CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }), - CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), + CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }), + CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }), + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), }, new[] { diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Basic.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Basic.cs index 70e14bcb89..12b8fe71b3 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Basic.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Basic.cs @@ -16,13 +16,13 @@ namespace Asp } #line hidden [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Inject.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Inject.cs index a7faa99fa2..daeb196d90 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Inject.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Inject.cs @@ -30,13 +30,13 @@ using MyNamespace #line hidden { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithModel.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithModel.cs index 037c920c0d..f450aaa679 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithModel.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithModel.cs @@ -38,11 +38,11 @@ namespace Asp #line hidden { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithSemicolon.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithSemicolon.cs index c1ad592cac..870cfefac0 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithSemicolon.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/InjectWithSemicolon.cs @@ -54,11 +54,11 @@ namespace Asp #line hidden { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Model.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Model.cs index d2ca7a6afa..fd10a02d57 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Model.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/Model.cs @@ -22,13 +22,13 @@ namespace Asp } #line hidden [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/ModelExpressionTagHelper.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/ModelExpressionTagHelper.cs index 295b1a8313..8cc6727db1 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/ModelExpressionTagHelper.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/DesignTime/ModelExpressionTagHelper.cs @@ -38,13 +38,13 @@ namespace Asp } #line hidden [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Basic.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Basic.cs index d3f2c1a1c3..25eeaef83e 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Basic.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Basic.cs @@ -16,13 +16,13 @@ namespace Asp } #line hidden [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Inject.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Inject.cs index e292d01dd3..988bb5c6c1 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Inject.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Inject.cs @@ -24,13 +24,13 @@ using MyNamespace [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public MyApp MyPropertyName { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithModel.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithModel.cs index 67670371e0..ade4477345 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithModel.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithModel.cs @@ -26,11 +26,11 @@ namespace Asp [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public MyService Html { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithSemicolon.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithSemicolon.cs index 497f48ca5b..a8e1c90e5e 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithSemicolon.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/InjectWithSemicolon.cs @@ -30,11 +30,11 @@ namespace Asp [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public MyService Html2 { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Model.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Model.cs index fb0a1d19d8..9e37256e86 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Model.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/Model.cs @@ -22,13 +22,13 @@ namespace Asp } #line hidden [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/ModelExpressionTagHelper.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/ModelExpressionTagHelper.cs index b29dbb65f4..80f62e1b9f 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/ModelExpressionTagHelper.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFiles/Output/Runtime/ModelExpressionTagHelper.cs @@ -31,13 +31,13 @@ namespace Asp } #line hidden [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } - [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] public Microsoft.AspNet.Mvc.IViewComponentHelper Component { get; private set; } [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] - public Microsoft.AspNet.Mvc.IUrlHelper Url { get; private set; } + public Microsoft.AspNet.Mvc.Rendering.IJsonHelper Json { get; private set; } + [Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute] + public Microsoft.AspNet.Mvc.Rendering.IHtmlHelper Html { get; private set; } #line hidden diff --git a/test/WebSites/TagHelpersWebSite/Controllers/RemoveDefaultInheritedTagHelpersController.cs b/test/WebSites/TagHelpersWebSite/Controllers/RemoveDefaultInheritedTagHelpersController.cs new file mode 100644 index 0000000000..28f07fc5f2 --- /dev/null +++ b/test/WebSites/TagHelpersWebSite/Controllers/RemoveDefaultInheritedTagHelpersController.cs @@ -0,0 +1,12 @@ +// 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.AspNet.Mvc; + +namespace TagHelpersWebSite.Controllers +{ + public class RemoveDefaultInheritedTagHelpersController : Controller + { + public IActionResult Index() => View(); + } +} diff --git a/test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/Index.cshtml b/test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/Index.cshtml new file mode 100644 index 0000000000..efd3d4337a --- /dev/null +++ b/test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/Index.cshtml @@ -0,0 +1,4 @@ +@{ + Layout = null; +} +Virtual path \ No newline at end of file diff --git a/test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/_ViewImports.cshtml b/test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/_ViewImports.cshtml new file mode 100644 index 0000000000..96259fcd21 --- /dev/null +++ b/test/WebSites/TagHelpersWebSite/Views/RemoveDefaultInheritedTagHelpers/_ViewImports.cshtml @@ -0,0 +1 @@ +@removeTagHelper "*, Microsoft.AspNet.Mvc.Razor" \ No newline at end of file