Update TModel code generation.

- Prior to this TModel would be set to a potentially non-fully qualified name. This would cause errors in default MVC templates.
- Regenerated test files to reflect new TModel.
- Updated unit test to reflect new behavior.

#1222
This commit is contained in:
N. Taylor Mullen 2017-04-13 23:51:16 -07:00
parent d273c6cd4c
commit 6f7cb763a2
18 changed files with 19 additions and 19 deletions

View File

@ -75,9 +75,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
if (_designTime) if (_designTime)
{ {
// Alias the TModel token to a known type ('object' if the model type is unknown). // Alias the TModel token to a known type.
// This allows design time compilation to succeed for Razor files where the token isn't replaced. // This allows design time compilation to succeed for Razor files where the token isn't replaced.
var typeName = modelType == "dynamic" ? $"global::{typeof(object).FullName}" : modelType; var typeName = $"global::{typeof(object).FullName}";
var usingNode = new UsingStatementIRNode() var usingNode = new UsingStatementIRNode()
{ {
Content = $"TModel = {typeName}" Content = $"TModel = {typeName}"

View File

@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
var @namespace = FindNamespaceNode(irDocument); var @namespace = FindNamespaceNode(irDocument);
var usingNode = Assert.IsType<UsingStatementIRNode>(@namespace.Children[0]); var usingNode = Assert.IsType<UsingStatementIRNode>(@namespace.Children[0]);
Assert.Equal($"TModel = SomeType", usingNode.Content); Assert.Equal($"TModel = global::System.Object", usingNode.Content);
} }
private RazorCodeDocument CreateDocument(string content) private RazorCodeDocument CreateDocument(string content)

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = MyModel; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = MyModel UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = MyModel; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = MyModel UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = DateTime; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = DateTime UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = System.Collections.IEnumerable; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = System.Collections.IEnumerable UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = System.Collections.IEnumerable; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = System.Collections.IEnumerable UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace Test.Namespace namespace Test.Namespace
{ {
#line hidden #line hidden
using TModel = PageWithNamespace_Page; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - Test.Namespace NamespaceDeclaration - - Test.Namespace
UsingStatement - - TModel = PageWithNamespace_Page UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorPagesWithoutModel_cshtml; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorPagesWithoutModel_cshtml UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq

View File

@ -1,7 +1,7 @@
namespace AspNetCore namespace AspNetCore
{ {
#line hidden #line hidden
using TModel = NewModel; using TModel = global::System.Object;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;

View File

@ -1,7 +1,7 @@
Document - Document -
Checksum - Checksum -
NamespaceDeclaration - - AspNetCore NamespaceDeclaration - - AspNetCore
UsingStatement - - TModel = NewModel UsingStatement - - TModel = global::System.Object
UsingStatement - (1:0,1 [12] ) - System UsingStatement - (1:0,1 [12] ) - System
UsingStatement - - System.Threading.Tasks UsingStatement - - System.Threading.Tasks
UsingStatement - (16:1,1 [17] ) - System.Linq UsingStatement - (16:1,1 [17] ) - System.Linq