public async Task ProcessAsync_SetsValueOnContext()
        {
            // Arrange
            var textAreaContext = new TextAreaContext();

            var context = new TagHelperContext(
                tagName: "govuk-textarea-value",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(TextAreaContext), textAreaContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-textarea-value",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Value");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new TextAreaValueTagHelper();

            // Act
            await tagHelper.ProcessAsync(context, output);

            // Assert
            Assert.Equal("Value", textAreaContext.Value?.ToString());
        }
Exemplo n.º 2
0
        public void SetValue_AlreadySet_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new TextAreaContext();

            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-textarea-value> element is permitted within each <govuk-textarea>.", ex.Message);
        }
Exemplo n.º 3
0
        public void SetLabel_AlreadyGotValue_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new TextAreaContext();

            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-textarea-label> must be specified before <govuk-textarea-value>.", ex.Message);
        }