示例#1
0
        public async Task ProcessAsync_SetsLabelOnContext()
        {
            // Arrange
            var itemContext = new DateInputItemContext("govuk-date-input-day", "govuk-date-input-day-label");

            var context = new TagHelperContext(
                tagName: "govuk-date-input-day-label",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(DateInputItemContext), itemContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-date-input-day-label",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Label");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new DateInputItemLabelTagHelper();

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

            // Assert
            Assert.Equal("Label", itemContext.Label?.Content?.ToString());
        }
示例#2
0
        public void SetLabel_SetsLabelOnContext()
        {
            // Arrange
            var context = new DateInputItemContext("govuk-date-input-day", "govuk-date-input-day-label");

            // Act
            context.SetLabel(content: new HtmlString("Label"), attributes: new AttributeDictionary());

            // Assert
            Assert.Equal("Label", context.Label?.Content?.RenderToString());
        }
示例#3
0
        public void SetLabel_AlreadyGotLabel_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new DateInputItemContext("govuk-date-input-day", "govuk-date-input-day-label");

            context.SetLabel(content: new HtmlString("Existing label"), attributes: new AttributeDictionary());

            // Act
            var ex = Record.Exception(() => context.SetLabel(content: new HtmlString("Label"), attributes: new AttributeDictionary()));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("Only one <govuk-date-input-day-label> element is permitted within each <govuk-date-input-day>.", ex.Message);
        }