Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using HtmlTags.Conventions;
using HtmlTags.Conventions.Elements;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -200,6 +201,18 @@ public void ShouldAllowOverridingOfConventions()
editor.Value().ShouldBe(GetDateValue(offset));
}

[Fact]
public void ShouldAllowOverridingOfConventionTextUsingCustomBuilder()
{
var offset = new DateTimeOffset(2018, 1, 1, 12, 00, 00, TimeSpan.FromHours(-6));
var subject = new Subject {DateValue = offset};
var helper = GetHtmlHelper(subject);

var display = helper.Display(m => m.DateValue);

display.Text().ShouldBe(DateTimeBuilder.Token);
}

public static HtmlHelper<TModel> GetHtmlHelper<TModel>(TModel model)
{
return GetHtmlHelper(model, CreateViewEngine());
Expand Down Expand Up @@ -339,6 +352,8 @@ private static HtmlHelper<TModel> GetHtmlHelper<TModel>(
reg.Editors.IfPropertyIs<DateTimeOffset>().ModifyWith(m =>
m.CurrentTag.Attr("type", "datetime-local")
.Value(GetDateValue(m.Value<DateTimeOffset?>())));

reg.Displays.IfPropertyIs<DateTimeOffset>().BuildBy<DateTimeBuilder>();
});

var serviceProvider = serviceCollection.BuildServiceProvider();
Expand Down Expand Up @@ -419,6 +434,16 @@ private static string FormatOutput(ModelExplorer modelExplorer)
modelExplorer.GetSimpleDisplayText() ?? "(null)");
}

public class DateTimeBuilder : IElementBuilder
{
public static string Token = "date-time-builder";

public HtmlTag Build(ElementRequest request)
{
return new HtmlTag("span").Text(Token);
}
}

public class TestOptionsManager<TOptions> : IOptions<TOptions>
where TOptions : class, new()
{
Expand Down