\r\n\t\t |\r\n\t\t<%: Html.ActionLink(\"Back\", \"Index\") %>\r\n\t
\r\n<% }" + + " %>\r\n"); + + #line default + #line hidden + + #line 39 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Delete.tt" + + if (MvcHost.IsPartialView) { + // Do nothing. + } else if (MvcHost.IsContentPage) { + PopIndent(); + + + #line default + #line hidden + + #line 45 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Delete.tt" + this.Write("+ | + <%: Html.ActionLink("Back", "Index") %> +
+<% } %> +<# + if (MvcHost.IsPartialView) { + // Do nothing. + } else if (MvcHost.IsContentPage) { + PopIndent(); +#> +\r\n\t\t |\r\n\t\t@Html.ActionLink(\"Back\", \"Index\")\r\n\t
\r\n}\r\n"); + + #line default + #line hidden + + #line 40 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt" + + if (MvcHost.IsPartialView) { + // Do nothing. + } else if (!MvcHost.IsContentPage) { + PopIndent(); + + + #line default + #line hidden + + #line 46 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt" + this.Write("\t\r\n\r\n"); + + #line default + #line hidden + + #line 48 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt" + } + + #line default + #line hidden + return this.GenerationEnvironment.ToString(); + } + + protected virtual void Initialize() { + } + } + + public class DeleteBase { + + private global::System.Text.StringBuilder builder; + + private global::System.Collections.Generic.IDictionary+ | + @Html.ActionLink("Back", "Index") +
+} +<# + if (MvcHost.IsPartialView) { + // Do nothing. + } else if (!MvcHost.IsContentPage) { + PopIndent(); +#> + + +<# } #> +<#+ + 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; + } +#> \ No newline at end of file diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/AspxVisualBasic/Delete.tt b/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/AspxVisualBasic/Delete.tt new file mode 100644 index 0000000000..b7ee3248d9 --- /dev/null +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/AspxVisualBasic/Delete.tt @@ -0,0 +1,68 @@ +<#@ template language="VB" HostSpecific="true" #> +<#@ import namespace="ICSharpCode.AspNet.Mvc" #> +<#@ import namespace="Microsoft.VisualBasic.Constants" #> +<# If MvcHost.IsPartialView Then #> +<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl<#= GetViewPageType() #>" %> + +<# ElseIf MvcHost.IsContentPage Then #> +<%@ Page Language="VB" MasterPageFile="<#= MvcHost.MasterPageFile #>" Inherits="System.Web.Mvc.ViewPage<#= GetViewPageType() #>" %> + ++ | + <%: Html.ActionLink("Back", "Index") %> +
+<% End Using %> +<# + If MvcHost.IsPartialView Then + ' Do nothing. + ElseIf MvcHost.IsContentPage Then + PopIndent() +#> ++ | + @Html.ActionLink("Back", "Index") +
+End Using +<# + If MvcHost.IsPartialView Then + ' Do nothing. + ElseIf Not MvcHost.IsContentPage Then + PopIndent() +#> + + +<# End If #> +<#+ + ReadOnly Property MvcHost As MvcTextTemplateHost + Get + Return DirectCast(Host, MvcTextTemplateHost) + End Get + End Property + + Function GetModelDirective() As String + Dim viewDataTypeName As String = MvcHost.ViewDataTypeName + If Not String.IsNullOrEmpty(viewDataTypeName) Then + Return String.Format("@ModelType {0}", viewDataTypeName) + End If + Return String.Empty + End Function +#> \ No newline at end of file diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj b/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj index bf36912fc4..a238b0a7c2 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj @@ -86,12 +86,14 @@+ | + <%: Html.ActionLink(""Back"", ""Index"") %> +
+ <% } %> + + +"; + Assert.AreEqual(expectedOutput, output); + } + + [Test] + public void TransformText_ModelHasNoPropertiesAndIsContentPage_ReturnsContentPageWithFormAndFieldSetForModel() + { + CreateViewTemplatePreprocessor(); + mvcHost.IsContentPage = true; + Type modelType = typeof(ModelWithNoProperties); + mvcHost.ViewDataType = modelType; + mvcHost.ViewDataTypeName = modelType.FullName; + mvcHost.ViewName = "MyView"; + mvcHost.MasterPageFile = "~/Views/Shared/Site.master"; + mvcHost.PrimaryContentPlaceHolderID = "Main"; + + string output = templatePreprocessor.TransformText(); + + string expectedOutput = +@"<%@ Page Language=""C#"" MasterPageFile=""~/Views/Shared/Site.master"" Inherits=""System.Web.Mvc.ViewPage+ | + <%: Html.ActionLink(""Back"", ""Index"") %> +
+ <% } %> ++ | + <%: Html.ActionLink(""Back"", ""Index"") %> +
+<% } %> +"; + Assert.AreEqual(expectedOutput, output); + } + } +} diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpDeleteViewTemplateTests.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpDeleteViewTemplateTests.cs new file mode 100644 index 0000000000..f2e1582ce4 --- /dev/null +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpDeleteViewTemplateTests.cs @@ -0,0 +1,158 @@ +// 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.CodeTemplates.Models; +using AspNet.Mvc.Tests.Helpers; +using ICSharpCode.AspNet.Mvc.CSHtml; +using NUnit.Framework; + +namespace AspNet.Mvc.Tests.CodeTemplates +{ + [TestFixture] + public class RazorCSharpDeleteViewTemplateTests + { + Delete templatePreprocessor; + TestableMvcTextTemplateHost mvcHost; + + void CreateViewTemplatePreprocessor() + { + mvcHost = new TestableMvcTextTemplateHost(); + templatePreprocessor = new Delete(); + templatePreprocessor.Host = mvcHost; + } + + [Test] + public void GetModelDirective_HostViewDataTypeNameIsMyAppMyModel_ReturnsRazorModelFollowedByMyAppMyModel() + { + CreateViewTemplatePreprocessor(); + mvcHost.ViewDataTypeName = "MyApp.MyModel"; + + string modelDirective = templatePreprocessor.GetModelDirective(); + + Assert.AreEqual("@model MyApp.MyModel", modelDirective); + } + + [Test] + public void GetModelDirective_HostViewDataTypeNameIsNull_ReturnsEmptyString() + { + CreateViewTemplatePreprocessor(); + mvcHost.ViewDataTypeName = null; + + string modelDirective = templatePreprocessor.GetModelDirective(); + + Assert.AreEqual(String.Empty, modelDirective); + } + + [Test] + public void GetModelDirective_HostViewDataTypeNameIsEmptyString_ReturnsEmptyString() + { + CreateViewTemplatePreprocessor(); + mvcHost.ViewDataTypeName = String.Empty; + + string modelDirective = templatePreprocessor.GetModelDirective(); + + Assert.AreEqual(String.Empty, modelDirective); + } + + [Test] + public void TransformText_ModelHasNoPropertiesAndNoMasterPage_ReturnsFullHtmlPageWithFormAndFieldSetForModel() + { + CreateViewTemplatePreprocessor(); + Type modelType = typeof(ModelWithNoProperties); + mvcHost.ViewDataType = modelType; + mvcHost.ViewDataTypeName = modelType.FullName; + mvcHost.ViewName = "MyView"; + + string output = templatePreprocessor.TransformText(); + + string expectedOutput = +@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithNoProperties + + + + ++ | + @Html.ActionLink(""Back"", ""Index"") +
+ } + + +"; + Assert.AreEqual(expectedOutput, output); + } + + [Test] + public void TransformText_ModelHasNoPropertiesAndIsPartialView_ReturnsControlWithFormAndFieldSetForModel() + { + CreateViewTemplatePreprocessor(); + mvcHost.IsPartialView = true; + Type modelType = typeof(ModelWithNoProperties); + mvcHost.ViewDataType = modelType; + mvcHost.ViewDataTypeName = modelType.FullName; + mvcHost.ViewName = "MyView"; + + string output = templatePreprocessor.TransformText(); + + string expectedOutput = +@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithNoProperties + + +@using (Html.BeginForm()) { ++ | + @Html.ActionLink(""Back"", ""Index"") +
+} +"; + Assert.AreEqual(expectedOutput, output); + } + + [Test] + public void TransformText_ModelHasNoPropertiesAndIsContentPage_ReturnsContentPageWithFormAndFieldSetForModel() + { + CreateViewTemplatePreprocessor(); + mvcHost.IsContentPage = true; + Type modelType = typeof(ModelWithNoProperties); + mvcHost.ViewDataType = modelType; + mvcHost.ViewDataTypeName = modelType.FullName; + mvcHost.ViewName = "MyView"; + mvcHost.MasterPageFile = "~/Views/Shared/Site.master"; + mvcHost.PrimaryContentPlaceHolderID = "Main"; + + string output = templatePreprocessor.TransformText(); + + string expectedOutput = +@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithNoProperties + +@{ + ViewBag.Title = ""MyView""; + Layout = ""~/Views/Shared/Site.master""; +} + ++ | + @Html.ActionLink(""Back"", ""Index"") +
+} +"; + Assert.AreEqual(expectedOutput, output); + } + } +}