public async Task ProcessAsync_SetsSuffixOnContext() { // Arrange var inputContext = new TextInputContext(); var context = new TagHelperContext( tagName: "govuk-input-suffix", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(TextInputContext), inputContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-input-suffix", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.AppendHtml(new HtmlString("Suffix")); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new TextInputSuffixTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.True(inputContext.Suffix.HasValue); Assert.Equal("Suffix", inputContext.Suffix.Value.Content.RenderToString()); }
public InputTransformer(ITextMiddleware readMiddleware, ITextMiddleware[] middlewares, ITextContentWriter writer, TextInputContext ctx) { _readMiddleware = readMiddleware; _middlewares = middlewares; _writer = writer; _ctx = ctx; }
public void SetLabel_AlreadyGotSuffix_ThrowsInvalidOperationException() { // Arrange var context = new TextInputContext(); context.SetSuffix(attributes: null, content: new HtmlString("Prefix")); // Act var ex = Record.Exception(() => context.SetLabel(false, null, new HtmlString("Error"))); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("<govuk-input-label> must be specified before <govuk-input-suffix>.", ex.Message); }
public void SetSuffix_AlreadySet_ThrowsInvalidOperationException() { // Arrange var context = new TextInputContext(); context.SetSuffix(attributes: null, content: new HtmlString("Existing prefix")); // Act var ex = Record.Exception(() => context.SetSuffix(null, new HtmlString("Prefix"))); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("Only one <govuk-input-suffix> element is permitted within each <govuk-input>.", ex.Message); }
private async Task <InputItems> ExecuteAsync(IStaticSite site, IInput input, ITextMiddleware[] middlewares, bool write) { try { var textContext = new TextInputContext(site, input); var executor = new InputTransformer(_readMiddleware, middlewares, write ? _writer : null, textContext); await executor.ExecuteAsync().ConfigureAwait(false); return(textContext.Items); } catch (Exception e) { throw new ParseException($"Error while parsing file {input.RelativeName}", e); } }