Skip to content

Commit

Permalink
HtmlHelper.Value(string) fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtoroq committed Mar 6, 2018
1 parent 5a36d68 commit 0738bbe
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/Xcst.AspNet/Framework/HtmlHelper.cs
Expand Up @@ -331,7 +331,9 @@ public HtmlHelper(ViewContext viewContext, IViewDataContainer viewDataContainer)

if (name == null) throw new ArgumentNullException(nameof(name));

return ValueHelper(name, value: null, format: this.ViewData.ModelMetadata.EditFormatString, useViewData: true);
ModelMetadata metadata = ModelMetadata.FromStringExpression(name, this.ViewData);

return ValueHelper(name, value: null, format: metadata.EditFormatString, useViewData: true);
}

public string Value(string name, string format) {
Expand Down
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<c:module version='1.0' language='C#'
xmlns:c='http://maxtoroq.github.io/XCST'
xmlns:a='http://maxtoroq.github.io/XCST/application'
extension-element-prefixes='a'>

<c:type name='Foo'>
<c:member name='bar' as='decimal' format='{0:#.#}' apply-format-in-edit-mode='yes'/>
</c:type>

<c:template name='c:initial-template' expand-text='yes'>
<a:model value='new Foo { bar = 0.1m }' helper-name='htm'>
<ul>
<li>{htm.Value("bar")}</li>
<li>{htm.ValueFor(p => p.bar)}</li>
</ul>
</a:model>
</c:template>

<c:template name='expected'>
<ul>
<li>.1</li>
<li>.1</li>
</ul>
</c:template>

</c:module>
Expand Up @@ -17,16 +17,16 @@
using Xcst.Web.Mvc;
using TestAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace Xcst.Web.Tests.Extension {
namespace Xcst.Web.Tests {

static class ExtensionTestsHelper {
static class TestsHelper {

static readonly XcstCompilerFactory CompilerFactory = new XcstCompilerFactory();

static readonly QualifiedName InitialName = new QualifiedName("initial-template", "http://maxtoroq.github.io/XCST");
static readonly QualifiedName ExpectedName = new QualifiedName("expected");

static ExtensionTestsHelper() {
static TestsHelper() {
CompilerFactory.EnableExtensions = true;
CompilerFactory.PackageTypeResolver = typeName => Assembly.GetExecutingAssembly().GetType(typeName);
CompilerFactory.RegisterApplicationExtension();
Expand Down Expand Up @@ -106,7 +106,7 @@ static class ExtensionTestsHelper {
static Tuple<CompileResult, string> GenerateCode(Uri packageUri, string usePackageBase) {

XcstCompiler compiler = CompilerFactory.CreateCompiler();
compiler.TargetNamespace = typeof(ExtensionTestsHelper).Namespace + ".Runtime";
compiler.TargetNamespace = typeof(TestsHelper).Namespace + ".Runtime";
compiler.TargetClass = "TestModule";
compiler.UseLineDirective = true;
compiler.UsePackageBase = usePackageBase;
Expand Down
9 changes: 5 additions & 4 deletions tests/Xcst.AspNet.Tests/Xcst.AspNet.Tests.csproj
Expand Up @@ -153,8 +153,8 @@
</Compile>
<Compile Include="Extension\Display\Templates\Enum\EnumWithDisplayName.cs" />
<Compile Include="Extension\Editor\Templates\Enum\EnumWithDisplayName.cs" />
<Compile Include="Extension\ExtensionTests.generated.cs" />
<Compile Include="Extension\ExtensionTestsHelper.cs" />
<Compile Include="Tests.generated.cs" />
<Compile Include="TestsHelper.cs" />
<None Include="app.config" />
<None Include="Extension\CheckBox\check-box.autofocus.type.i.xcst" />
<None Include="Extension\CheckBox\check-box.disabled.type.i.xcst" />
Expand Down Expand Up @@ -189,7 +189,7 @@
<None Include="Extension\Editor\Templates\Time.c.xcst" />
<None Include="Extension\Editor\Templates\DateTime.c.xcst" />
<None Include="Extension\Editor\Templates\Date.c.xcst" />
<None Include="Extension\generate-extension-tests.ps1" />
<None Include="generate-tests.ps1" />
</ItemGroup>
<ItemGroup>
<None Include="Extension\AntiForgeryToken\anti-forgery-token.foo.i.xcst" />
Expand Down Expand Up @@ -316,6 +316,7 @@
<None Include="Extension\Editor\editor.for_name.mutex.i.xcst" />
<None Include="Extension\Editor\editor.with-params.type.i.xcst" />
<None Include="Extension\Editor\editor.attributes.type.i.xcst" />
<None Include="Framework\HtmlHelper\Value\UsesEditFormatString.c.xcst" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -352,7 +353,7 @@
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>powershell -NoProfile -ExecutionPolicy RemoteSigned -File $(ProjectDir)Extension\generate-extension-tests.ps1 $(ConfigurationName)</PreBuildEvent>
<PreBuildEvent>powershell -NoProfile -ExecutionPolicy RemoteSigned -File $(ProjectDir)generate-tests.ps1 $(ConfigurationName)</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Expand Up @@ -22,12 +22,11 @@ function WriteLine($line = "") {

function GenerateTests {

$compilerPath = Resolve-Path ..\..\..\src\Xcst.AspNet\bin\$Configuration
$compilerPath = Resolve-Path ..\..\src\Xcst.AspNet\bin\$Configuration

Add-Type -Path $compilerPath\Xcst.Compiler.dll

$compilerFactory = New-Object Xcst.Compiler.XcstCompilerFactory
$startDirectory = Get-Item .

@"
//------------------------------------------------------------------------------
Expand All @@ -41,18 +40,16 @@ function GenerateTests {
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Xcst.Web.Tests {
using static Extension.ExtensionTestsHelper;
using static Xcst.Web.Tests.TestsHelper;
"@
PushIndent
GenerateTestsForDirectory $startDirectory $startDirectory.Name
PopIndent
"}"
foreach ($subDirectory in ls -Directory) {
GenerateTestsForDirectory $subDirectory $subDirectory.Name
}
}

function GenerateTestsForDirectory([IO.DirectoryInfo]$directory, $category) {
function GenerateTestsForDirectory([IO.DirectoryInfo]$directory, [string]$relativeNs) {

$ns = "Xcst.AspNet.Tests.$relativeNs"

foreach ($file in ls $directory.FullName *.pxcst) {

Expand All @@ -68,13 +65,13 @@ function GenerateTestsForDirectory([IO.DirectoryInfo]$directory, $category) {
}
}

WriteLine
WriteLine "namespace $($directory.Name) {"
PushIndent

$tests = ls $directory.FullName *.xcst

if ($tests.Length -gt 0) {

WriteLine
WriteLine "namespace $ns {"
PushIndent

WriteLine
WriteLine "[TestClass]"
Expand All @@ -95,7 +92,7 @@ function GenerateTestsForDirectory([IO.DirectoryInfo]$directory, $category) {

WriteLine
WriteLine "#line 1 ""$($file.FullName)"""
WriteLine "[TestMethod, TestCategory(""$category"")]"
WriteLine "[TestMethod, TestCategory(""$relativeNs"")]"

if (!$correct) {
WriteLine "[ExpectedException(typeof(Xcst.Compiler.CompileException))]"
Expand All @@ -113,19 +110,19 @@ function GenerateTestsForDirectory([IO.DirectoryInfo]$directory, $category) {

PopIndent
WriteLine "}"

PopIndent
WriteLine "}"
}

foreach ($subDirectory in ls $directory.FullName -Directory) {
GenerateTestsForDirectory $subDirectory ($category + "." + $subDirectory.Name)
GenerateTestsForDirectory $subDirectory ($relativeNs + "." + $subDirectory.Name)
}

PopIndent
WriteLine "}"
}

try {

GenerateTests | Out-File ExtensionTests.generated.cs -Encoding utf8
GenerateTests | Out-File Tests.generated.cs -Encoding utf8

} finally {
Pop-Location
Expand Down

0 comments on commit 0738bbe

Please sign in to comment.