Browse Source

Add tests for code in C# Aspx and Razor empty view T4 templates.

pull/18/head
Matt Ward 14 years ago
parent
commit
901ca06928
  1. 2
      src/AddIns/BackendBindings/AspNet.Mvc/AspNet.Mvc.sln
  2. 12
      src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj
  3. 322
      src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/AspxCSharp/Empty.cs
  4. 24
      src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/AspxCSharp/Empty.tt
  5. 303
      src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Empty.cs
  6. 24
      src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Empty.tt
  7. 26
      src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/AspxVisualBasic/Empty.tt
  8. 23
      src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/VBHTML/Empty.tt
  9. 3
      src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj
  10. 57
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/AspxCSharpEmptyViewTemplateTests.cs
  11. 58
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpEmptyViewTemplateTests.cs

2
src/AddIns/BackendBindings/AspNet.Mvc/AspNet.Mvc.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.1.0.7683-alpha
# SharpDevelop 4.1.0.8000
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Mvc", "Project\AspNet.Mvc.csproj", "{D781721F-C2A7-4E95-B76F-247170AC3B13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Mvc.Tests", "Test\AspNet.Mvc.Tests.csproj", "{0B12A079-B2DB-42B9-8A8E-AA5CBC2B3225}"

12
src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj

@ -47,6 +47,12 @@ @@ -47,6 +47,12 @@
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.cs">
<DependentUpon>Empty.tt</DependentUpon>
</Compile>
<Compile Include="ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.cs">
<DependentUpon>Empty.tt</DependentUpon>
</Compile>
<Compile Include="Src\AddMvcControllerToProjectCommand.cs" />
<Compile Include="Src\AddMvcControllerToProjectView.xaml.cs">
<DependentUpon>AddMvcControllerToProjectView.xaml</DependentUpon>
@ -186,9 +192,15 @@ @@ -186,9 +192,15 @@
</None>
<None Include="ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Generator>TextTemplatingFilePreprocessor</Generator>
<CustomToolNamespace>ICSharpCode.AspNet.Mvc.AspxCSharp</CustomToolNamespace>
<LastGenOutput>Empty.cs</LastGenOutput>
</None>
<None Include="ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Generator>TextTemplatingFilePreprocessor</Generator>
<CustomToolNamespace>ICSharpCode.AspNet.Mvc.CSHtml</CustomToolNamespace>
<LastGenOutput>Empty.cs</LastGenOutput>
</None>
<None Include="ItemTemplates\VisualBasic\CodeTemplates\AddController\Controller.tt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

322
src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/AspxCSharp/Empty.cs

@ -0,0 +1,322 @@ @@ -0,0 +1,322 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.239
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ICSharpCode.AspNet.Mvc.AspxCSharp {
using ICSharpCode.AspNet.Mvc;
using System;
public partial class Empty : EmptyBase {
private global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost hostValue;
#line 31 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
MvcTextTemplateHost MvcHost {
get { return (MvcTextTemplateHost)Host; }
}
public string GetViewPageType()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
if (!String.IsNullOrEmpty(viewDataTypeName)) {
return String.Format("<{0}>", viewDataTypeName);
}
return String.Empty;
}
#line default
#line hidden
public global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost Host {
get {
return this.hostValue;
}
set {
this.hostValue = value;
}
}
public virtual string TransformText() {
this.GenerationEnvironment = null;
#line 3 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
if (MvcHost.IsPartialView) {
#line default
#line hidden
#line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("<%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl\" %>\r\n\r\n");
#line default
#line hidden
#line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
} else if(MvcHost.IsContentPage) {
#line default
#line hidden
#line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("<%@ Page Language=\"C#\" MasterPageFile=\"");
#line default
#line hidden
#line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.MasterPageFile ));
#line default
#line hidden
#line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("\" Inherits=\"System.Web.Mvc.ViewPage");
#line default
#line hidden
#line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetViewPageType() ));
#line default
#line hidden
#line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("\" %>\r\n\r\n<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"Title\" runat=\"server\">\r\n" +
"");
#line default
#line hidden
#line 10 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
#line 10 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("\r\n</asp:Content>\r\n\r\n<asp:Content ID=\"Content2\" ContentPlaceHolderID=\"");
#line default
#line hidden
#line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.PrimaryContentPlaceHolderID ));
#line default
#line hidden
#line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("\" runat=\"server\">\r\n\t\r\n</asp:Content>\r\n");
#line default
#line hidden
#line 16 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
} else {
#line default
#line hidden
#line 17 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("<%@ Page Language=\"C#\" Inherits=\"System.Web.Mvc.ViewPage");
#line default
#line hidden
#line 17 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetViewPageType() ));
#line default
#line hidden
#line 17 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("\" %>\r\n\r\n<!DOCTYPE html>\r\n<html>\r\n\t<head runat=\"server\">\r\n\t\t<title>");
#line default
#line hidden
#line 22 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
#line 22 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
this.Write("</title>\r\n\t</head>\r\n\t<body>\r\n\t\t<div>\r\n\t\t\r\n\t\t</div>\r\n\t</body>\r\n</html>\r\n");
#line default
#line hidden
#line 30 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt"
}
#line default
#line hidden
return this.GenerationEnvironment.ToString();
}
protected virtual void Initialize() {
}
}
public class EmptyBase {
private global::System.Text.StringBuilder builder;
private global::System.Collections.Generic.IDictionary<string, object> session;
private global::System.CodeDom.Compiler.CompilerErrorCollection errors;
private string currentIndent = string.Empty;
private global::System.Collections.Generic.Stack<int> indents;
private ToStringInstanceHelper _toStringHelper = new ToStringInstanceHelper();
public virtual global::System.Collections.Generic.IDictionary<string, object> Session {
get {
return this.session;
}
set {
this.session = value;
}
}
public global::System.Text.StringBuilder GenerationEnvironment {
get {
if ((this.builder == null)) {
this.builder = new global::System.Text.StringBuilder();
}
return this.builder;
}
set {
this.builder = value;
}
}
protected global::System.CodeDom.Compiler.CompilerErrorCollection Errors {
get {
if ((this.errors == null)) {
this.errors = new global::System.CodeDom.Compiler.CompilerErrorCollection();
}
return this.errors;
}
}
public string CurrentIndent {
get {
return this.currentIndent;
}
}
private global::System.Collections.Generic.Stack<int> Indents {
get {
if ((this.indents == null)) {
this.indents = new global::System.Collections.Generic.Stack<int>();
}
return this.indents;
}
}
public ToStringInstanceHelper ToStringHelper {
get {
return this._toStringHelper;
}
}
public void Error(string message) {
this.Errors.Add(new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message));
}
public void Warning(string message) {
global::System.CodeDom.Compiler.CompilerError val = new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message);
val.IsWarning = true;
this.Errors.Add(val);
}
public string PopIndent() {
if ((this.Indents.Count == 0)) {
return string.Empty;
}
int lastPos = (this.currentIndent.Length - this.Indents.Pop());
string last = this.currentIndent.Substring(lastPos);
this.currentIndent = this.currentIndent.Substring(0, lastPos);
return last;
}
public void PushIndent(string indent) {
this.Indents.Push(indent.Length);
this.currentIndent = (this.currentIndent + indent);
}
public void ClearIndent() {
this.currentIndent = string.Empty;
this.Indents.Clear();
}
public void Write(string textToAppend) {
this.GenerationEnvironment.Append(textToAppend);
}
public void Write(string format, params object[] args) {
this.GenerationEnvironment.AppendFormat(format, args);
}
public void WriteLine(string textToAppend) {
this.GenerationEnvironment.Append(this.currentIndent);
this.GenerationEnvironment.AppendLine(textToAppend);
}
public void WriteLine(string format, params object[] args) {
this.GenerationEnvironment.Append(this.currentIndent);
this.GenerationEnvironment.AppendFormat(format, args);
this.GenerationEnvironment.AppendLine();
}
public class ToStringInstanceHelper {
private global::System.IFormatProvider formatProvider = global::System.Globalization.CultureInfo.InvariantCulture;
public global::System.IFormatProvider FormatProvider {
get {
return this.formatProvider;
}
set {
if ((this.formatProvider == null)) {
throw new global::System.ArgumentNullException("formatProvider");
}
this.formatProvider = value;
}
}
public string ToStringWithCulture(object objectToConvert) {
if ((objectToConvert == null)) {
throw new global::System.ArgumentNullException("objectToConvert");
}
global::System.Type type = objectToConvert.GetType();
global::System.Type iConvertibleType = typeof(global::System.IConvertible);
if (iConvertibleType.IsAssignableFrom(type)) {
return ((global::System.IConvertible)(objectToConvert)).ToString(this.formatProvider);
}
global::System.Reflection.MethodInfo methInfo = type.GetMethod("ToString", new global::System.Type[] {
iConvertibleType});
if ((methInfo != null)) {
return ((string)(methInfo.Invoke(objectToConvert, new object[] {
this.formatProvider})));
}
return objectToConvert.ToString();
}
}
}
}

24
src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/AspxCSharp/Empty.tt

@ -1,18 +1,16 @@ @@ -1,18 +1,16 @@
<#@ template language="C#" HostSpecific="true" #>
<#
mvcHost = (MvcTextTemplateHost)Host;
#>
<# if (mvcHost.IsPartialView) { #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
<# if (MvcHost.IsPartialView) { #>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<# } else if(mvcHost.IsContentPage) { #>
<%@ Page Language="C#" MasterPageFile="<#= mvcHost.MasterPageFile #>" Inherits="System.Web.Mvc.ViewPage<#= GetViewPageType() #>" %>
<# } else if(MvcHost.IsContentPage) { #>
<%@ Page Language="C#" MasterPageFile="<#= MvcHost.MasterPageFile #>" Inherits="System.Web.Mvc.ViewPage<#= GetViewPageType() #>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Title" runat="server">
<#= mvcHost.ViewName #>
<#= MvcHost.ViewName #>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="<#= mvcHost.PrimaryContentPlaceHolderID #>" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="<#= MvcHost.PrimaryContentPlaceHolderID #>" runat="server">
</asp:Content>
<# } else { #>
@ -21,7 +19,7 @@ @@ -21,7 +19,7 @@
<!DOCTYPE html>
<html>
<head runat="server">
<title><#= mvcHost.ViewName #></title>
<title><#= MvcHost.ViewName #></title>
</head>
<body>
<div>
@ -31,11 +29,13 @@ @@ -31,11 +29,13 @@
</html>
<# } #>
<#+
MvcTextTemplateHost mvcHost;
MvcTextTemplateHost MvcHost {
get { return (MvcTextTemplateHost)Host; }
}
string GetViewPageType()
public string GetViewPageType()
{
string viewDataTypeName = mvcHost.ViewDataTypeName;
string viewDataTypeName = MvcHost.ViewDataTypeName;
if (!String.IsNullOrEmpty(viewDataTypeName)) {
return String.Format("<{0}>", viewDataTypeName);
}

303
src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Empty.cs

@ -0,0 +1,303 @@ @@ -0,0 +1,303 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.239
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ICSharpCode.AspNet.Mvc.CSHtml {
using ICSharpCode.AspNet.Mvc;
using System;
public partial class Empty : EmptyBase {
private global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost hostValue;
#line 29 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
MvcTextTemplateHost MvcHost {
get { return (MvcTextTemplateHost)Host; }
}
public string GetModelDirective()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
if (!String.IsNullOrEmpty(viewDataTypeName)) {
return String.Format("@model {0}", viewDataTypeName);
}
return String.Empty;
}
#line default
#line hidden
public global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost Host {
get {
return this.hostValue;
}
set {
this.hostValue = value;
}
}
public virtual string TransformText() {
this.GenerationEnvironment = null;
#line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
if (MvcHost.IsPartialView) {
#line default
#line hidden
#line 5 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("\r\n");
#line default
#line hidden
#line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
} else if (MvcHost.IsContentPage) {
#line default
#line hidden
#line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("@{\r\n\tViewBag.Title = \"");
#line default
#line hidden
#line 8 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
#line 8 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("\";\r\n\tLayout = \"");
#line default
#line hidden
#line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.MasterPageFile ));
#line default
#line hidden
#line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("\";\r\n}\r\n\r\n<h2>");
#line default
#line hidden
#line 12 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
#line 12 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("</h2>\r\n\r\n");
#line default
#line hidden
#line 14 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
} else {
#line default
#line hidden
#line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetModelDirective() ));
#line default
#line hidden
#line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("\r\n\r\n<!DOCTYPE html>\r\n<html>\r\n\t<head>\r\n\t\t<title>");
#line default
#line hidden
#line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
#line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
this.Write("</title>\r\n\t</head>\r\n\t<body>\r\n\t\t<div>\r\n\t\t\r\n\t\t</div>\r\n\t</body>\r\n</html>\r\n");
#line default
#line hidden
#line 28 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Empty.tt"
}
#line default
#line hidden
return this.GenerationEnvironment.ToString();
}
protected virtual void Initialize() {
}
}
public class EmptyBase {
private global::System.Text.StringBuilder builder;
private global::System.Collections.Generic.IDictionary<string, object> session;
private global::System.CodeDom.Compiler.CompilerErrorCollection errors;
private string currentIndent = string.Empty;
private global::System.Collections.Generic.Stack<int> indents;
private ToStringInstanceHelper _toStringHelper = new ToStringInstanceHelper();
public virtual global::System.Collections.Generic.IDictionary<string, object> Session {
get {
return this.session;
}
set {
this.session = value;
}
}
public global::System.Text.StringBuilder GenerationEnvironment {
get {
if ((this.builder == null)) {
this.builder = new global::System.Text.StringBuilder();
}
return this.builder;
}
set {
this.builder = value;
}
}
protected global::System.CodeDom.Compiler.CompilerErrorCollection Errors {
get {
if ((this.errors == null)) {
this.errors = new global::System.CodeDom.Compiler.CompilerErrorCollection();
}
return this.errors;
}
}
public string CurrentIndent {
get {
return this.currentIndent;
}
}
private global::System.Collections.Generic.Stack<int> Indents {
get {
if ((this.indents == null)) {
this.indents = new global::System.Collections.Generic.Stack<int>();
}
return this.indents;
}
}
public ToStringInstanceHelper ToStringHelper {
get {
return this._toStringHelper;
}
}
public void Error(string message) {
this.Errors.Add(new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message));
}
public void Warning(string message) {
global::System.CodeDom.Compiler.CompilerError val = new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message);
val.IsWarning = true;
this.Errors.Add(val);
}
public string PopIndent() {
if ((this.Indents.Count == 0)) {
return string.Empty;
}
int lastPos = (this.currentIndent.Length - this.Indents.Pop());
string last = this.currentIndent.Substring(lastPos);
this.currentIndent = this.currentIndent.Substring(0, lastPos);
return last;
}
public void PushIndent(string indent) {
this.Indents.Push(indent.Length);
this.currentIndent = (this.currentIndent + indent);
}
public void ClearIndent() {
this.currentIndent = string.Empty;
this.Indents.Clear();
}
public void Write(string textToAppend) {
this.GenerationEnvironment.Append(textToAppend);
}
public void Write(string format, params object[] args) {
this.GenerationEnvironment.AppendFormat(format, args);
}
public void WriteLine(string textToAppend) {
this.GenerationEnvironment.Append(this.currentIndent);
this.GenerationEnvironment.AppendLine(textToAppend);
}
public void WriteLine(string format, params object[] args) {
this.GenerationEnvironment.Append(this.currentIndent);
this.GenerationEnvironment.AppendFormat(format, args);
this.GenerationEnvironment.AppendLine();
}
public class ToStringInstanceHelper {
private global::System.IFormatProvider formatProvider = global::System.Globalization.CultureInfo.InvariantCulture;
public global::System.IFormatProvider FormatProvider {
get {
return this.formatProvider;
}
set {
if ((this.formatProvider == null)) {
throw new global::System.ArgumentNullException("formatProvider");
}
this.formatProvider = value;
}
}
public string ToStringWithCulture(object objectToConvert) {
if ((objectToConvert == null)) {
throw new global::System.ArgumentNullException("objectToConvert");
}
global::System.Type type = objectToConvert.GetType();
global::System.Type iConvertibleType = typeof(global::System.IConvertible);
if (iConvertibleType.IsAssignableFrom(type)) {
return ((global::System.IConvertible)(objectToConvert)).ToString(this.formatProvider);
}
global::System.Reflection.MethodInfo methInfo = type.GetMethod("ToString", new global::System.Type[] {
iConvertibleType});
if ((methInfo != null)) {
return ((string)(methInfo.Invoke(objectToConvert, new object[] {
this.formatProvider})));
}
return objectToConvert.ToString();
}
}
}
}

24
src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Empty.tt

@ -1,17 +1,15 @@ @@ -1,17 +1,15 @@
<#@ template language="C#" HostSpecific="true" #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
<#@ output extension=".cshtml" #>
<#
mvcHost = (MvcTextTemplateHost)Host;
#>
<# if (mvcHost.IsPartialView) { #>
<# if (MvcHost.IsPartialView) { #>
<# } else if (mvcHost.IsContentPage) { #>
<# } else if (MvcHost.IsContentPage) { #>
@{
ViewBag.Title = "<#= mvcHost.ViewName #>";
Layout = "<#= mvcHost.MasterPageFile #>";
ViewBag.Title = "<#= MvcHost.ViewName #>";
Layout = "<#= MvcHost.MasterPageFile #>";
}
<h2><#= mvcHost.ViewName #></h2>
<h2><#= MvcHost.ViewName #></h2>
<# } else { #>
<#= GetModelDirective() #>
@ -19,7 +17,7 @@ @@ -19,7 +17,7 @@
<!DOCTYPE html>
<html>
<head>
<title><#= mvcHost.ViewName #></title>
<title><#= MvcHost.ViewName #></title>
</head>
<body>
<div>
@ -29,11 +27,13 @@ @@ -29,11 +27,13 @@
</html>
<# } #>
<#+
MvcTextTemplateHost mvcHost;
MvcTextTemplateHost MvcHost {
get { return (MvcTextTemplateHost)Host; }
}
string GetModelDirective()
public string GetModelDirective()
{
string viewDataTypeName = mvcHost.ViewDataTypeName;
string viewDataTypeName = MvcHost.ViewDataTypeName;
if (!String.IsNullOrEmpty(viewDataTypeName)) {
return String.Format("@model {0}", viewDataTypeName);
}

26
src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/AspxVisualBasic/Empty.tt

@ -1,18 +1,16 @@ @@ -1,18 +1,16 @@
<#@ template language="VB" HostSpecific="true" #>
<#
mvcHost = DirectCast(Host, MvcTextTemplateHost)
#>
<# If mvcHost.IsPartialView Then #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
<# If MvcHost.IsPartialView Then #>
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<# ElseIf mvcHost.IsContentPage Then #>
<%@ Page Language="VB" MasterPageFile="<#= mvcHost.MasterPageFile #>" Inherits="System.Web.Mvc.ViewPage<#= GetViewPageType() #>" %>
<# ElseIf MvcHost.IsContentPage Then #>
<%@ Page Language="VB" MasterPageFile="<#= MvcHost.MasterPageFile #>" Inherits="System.Web.Mvc.ViewPage<#= GetViewPageType() #>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Title" runat="server">
<#= mvcHost.ViewName #>
<#= MvcHost.ViewName #>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="<#= mvcHost.PrimaryContentPlaceHolderID #>" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="<#= MvcHost.PrimaryContentPlaceHolderID #>" runat="server">
</asp:Content>
<# Else #>
@ -21,7 +19,7 @@ @@ -21,7 +19,7 @@
<!DOCTYPE html>
<html>
<head runat="server">
<title><#= mvcHost.ViewName #></title>
<title><#= MvcHost.ViewName #></title>
</head>
<body>
<div>
@ -31,10 +29,14 @@ @@ -31,10 +29,14 @@
</html>
<# End If #>
<#+
Private mvcHost As MvcTextTemplateHost
ReadOnly Property MvcHost As MvcTextTemplateHost
Get
Return DirectCast(Host, MvcTextTemplateHost)
End Get
End Property
Function GetViewPageType() As String
Dim viewDataTypeName As String = mvcHost.ViewDataTypeName
Public Function GetViewPageType() As String
Dim viewDataTypeName As String = MvcHost.ViewDataTypeName
If Not String.IsNullOrEmpty(viewDataTypeName) Then
Return String.Format("(Of {0})", viewDataTypeName)
End If

23
src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/VBHTML/Empty.tt

@ -1,17 +1,14 @@ @@ -1,17 +1,14 @@
<#@ template language="VB" HostSpecific="true" #>
<#@ output extension=".vbhtml" #>
<#
mvcHost = DirectCast(Host, MvcTextTemplateHost)
#>
<# If mvcHost.IsPartialView Then #>
<# If MvcHost.IsPartialView Then #>
<# ElseIf mvcHost.IsContentPage Then #>
<# ElseIf MvcHost.IsContentPage Then #>
@Code
ViewData("Title") = "<#= mvcHost.ViewName #>"
Layout = "<#= mvcHost.MasterPageFile #>"
ViewData("Title") = "<#= MvcHost.ViewName #>"
Layout = "<#= MvcHost.MasterPageFile #>"
End Code
<h2><#= mvcHost.ViewName #></h2>
<h2><#= MvcHost.ViewName #></h2>
<# Else #>
<#= GetModelDirective() #>
@ -19,7 +16,7 @@ End Code @@ -19,7 +16,7 @@ End Code
<!DOCTYPE html>
<html>
<head>
<title><#= mvcHost.ViewName #></title>
<title><#= MvcHost.ViewName #></title>
</head>
<body>
<div>
@ -29,10 +26,14 @@ End Code @@ -29,10 +26,14 @@ End Code
</html>
<# End If #>
<#+
Private mvcHost As MvcTextTemplateHost
ReadOnly Property MvcHost As MvcTextTemplateHost
Get
Return DirectCast(Host, MvcTextTemplateHost)
End Get
End Property
Function GetModelDirective() As String
Dim viewDataTypeName As String = mvcHost.ViewDataTypeName
Dim viewDataTypeName As String = MvcHost.ViewDataTypeName
If Not String.IsNullOrEmpty(viewDataTypeName) Then
Return String.Format("@ModelType {0}", viewDataTypeName)
End If

3
src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj

@ -85,6 +85,8 @@ @@ -85,6 +85,8 @@
<Compile Include="Src\AddMvcViewToProjectCommandTests.cs" />
<Compile Include="Src\AddMvcViewToProjectViewModelTests.cs" />
<Compile Include="Src\BooleanToVisibilityConverterTests.cs" />
<Compile Include="Src\CodeTemplates\AspxCSharpEmptyViewTemplateTests.cs" />
<Compile Include="Src\CodeTemplates\RazorCSharpEmptyViewTemplateTests.cs" />
<Compile Include="Src\IsMvcControllerFolderSelectedConditionEvaluatorTests.cs" />
<Compile Include="Src\IsMvcViewFolderSelectedConditionEvaluatorTests.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
@ -129,6 +131,7 @@ @@ -129,6 +131,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Helpers" />
<Folder Include="Src\CodeTemplates" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

57
src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/AspxCSharpEmptyViewTemplateTests.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc.AspxCSharp;
using NUnit.Framework;
namespace AspNet.Mvc.Tests.CodeTemplates
{
[TestFixture]
public class AspxCSharpEmptyViewTemplateTests
{
Empty emptyViewTemplate;
TestableMvcTextTemplateHost mvcHost;
void CreateEmptyViewTemplatePreprocessor()
{
mvcHost = new TestableMvcTextTemplateHost();
emptyViewTemplate = new Empty();
emptyViewTemplate.Host = mvcHost;
}
[Test]
public void GetViewPageType_HostViewDataTypeNameIsMyAppMyModel_ReturnsMyAppMyModelSurroundedByAngleBrackets()
{
CreateEmptyViewTemplatePreprocessor();
mvcHost.ViewDataTypeName = "MyApp.MyModel";
string viewPageType = emptyViewTemplate.GetViewPageType();
Assert.AreEqual("<MyApp.MyModel>", viewPageType);
}
[Test]
public void GetViewPageType_HostViewDataTypeNameIsNull_ReturnsEmptyString()
{
CreateEmptyViewTemplatePreprocessor();
mvcHost.ViewDataTypeName = null;
string viewPageType = emptyViewTemplate.GetViewPageType();
Assert.AreEqual(String.Empty, viewPageType);
}
[Test]
public void GetViewPageType_HostViewDataTypeNameIsEmptyString_ReturnsEmptyString()
{
CreateEmptyViewTemplatePreprocessor();
mvcHost.ViewDataTypeName = String.Empty;
string viewPageType = emptyViewTemplate.GetViewPageType();
Assert.AreEqual(String.Empty, viewPageType);
}
}
}

58
src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpEmptyViewTemplateTests.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc.CSHtml;
using NUnit.Framework;
namespace AspNet.Mvc.Tests.CodeTemplates
{
[TestFixture]
public class RazorCSharpEmptyViewTemplateTests
{
Empty emptyViewTemplate;
TestableMvcTextTemplateHost mvcHost;
void CreateEmptyViewTemplatePreprocessor()
{
mvcHost = new TestableMvcTextTemplateHost();
emptyViewTemplate = new Empty();
emptyViewTemplate.Host = mvcHost;
}
[Test]
public void GetModelDirective_HostViewDataTypeNameIsMyAppMyModel_ReturnsRazorModelFollowedByMyAppMyModel()
{
CreateEmptyViewTemplatePreprocessor();
mvcHost.ViewDataTypeName = "MyApp.MyModel";
string modelDirective = emptyViewTemplate.GetModelDirective();
Assert.AreEqual("@model MyApp.MyModel", modelDirective);
}
[Test]
public void GetModelDirective_HostViewDataTypeNameIsNull_ReturnsEmptyString()
{
CreateEmptyViewTemplatePreprocessor();
mvcHost.ViewDataTypeName = null;
string modelDirective = emptyViewTemplate.GetModelDirective();
Assert.AreEqual(String.Empty, modelDirective);
}
[Test]
public void GetModelDirective_HostViewDataTypeNameIsEmptyString_ReturnsEmptyString()
{
CreateEmptyViewTemplatePreprocessor();
mvcHost.ViewDataTypeName = String.Empty;
string modelDirective = emptyViewTemplate.GetModelDirective();
Assert.AreEqual(String.Empty, modelDirective);
}
}
}
Loading…
Cancel
Save