public async Task ProcessAsync_SetsValueOnContext() { // Arrange var characterCountContext = new CharacterCountContext(); var context = new TagHelperContext( tagName: "govuk-character-count-value", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(CharacterCountContext), characterCountContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-character-count-value", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Value"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new CharacterCountValueTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("Value", characterCountContext.Value?.ToString()); }
public void SetValue_AlreadySet_ThrowsInvalidOperationException() { // Arrange var context = new CharacterCountContext(); context.SetValue(new HtmlString("Existing value")); // Act var ex = Record.Exception(() => context.SetValue(new HtmlString("Value"))); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("Only one <govuk-character-count-value> element is permitted within each <govuk-character-count>.", ex.Message); }
public void SetLabel_AlreadyGotValue_ThrowsInvalidOperationException() { // Arrange var context = new CharacterCountContext(); context.SetValue(new HtmlString("Value")); // Act var ex = Record.Exception(() => context.SetLabel(false, null, new HtmlString("Error"))); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("<govuk-character-count-label> must be specified before <govuk-character-count-value>.", ex.Message); }