Exemple #1
0
        public void OpenFieldset_AlreadyOpen_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesContext(name: null, aspFor: null);

            context.OpenFieldset();

            // Act
            var ex = Record.Exception(() => context.OpenFieldset());

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-checkboxes-fieldset> cannot be nested inside another <govuk-checkboxes-fieldset>.", ex.Message);
        }
Exemple #2
0
        public void OpenFieldset_AlreadyGotFieldset_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesContext(name: null, aspFor: null);

            context.OpenFieldset();
            context.CloseFieldset(new CheckboxesFieldsetContext(attributes: null));

            // Act
            var ex = Record.Exception(() => context.OpenFieldset());

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal <object>("Only one <govuk-checkboxes-fieldset> element is permitted within each <govuk-checkboxes>.", ex.Message);
        }
Exemple #3
0
        public void OpenFieldset_AlreadyGotErrorMessage_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesContext(name: null, aspFor: null);

            context.SetErrorMessage(visuallyHiddenText: null, attributes: null, content: new HtmlString("Error"));

            // Act
            var ex = Record.Exception(() => context.OpenFieldset());

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-checkboxes-fieldset> must be the only direct child of the <govuk-checkboxes>.", ex.Message);
        }
Exemple #4
0
        public void OpenFieldset_AlreadyGotItem_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesContext(name: null, aspFor: null);

            var item = new CheckboxesItem()
            {
                LabelContent = new HtmlString("Item 1"),
                Value        = "item1"
            };

            context.AddItem(item);

            // Act
            var ex = Record.Exception(() => context.OpenFieldset());

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-checkboxes-fieldset> must be the only direct child of the <govuk-checkboxes>.", ex.Message);
        }
Exemple #5
0
        public async Task ProcessAsync_ParentAlreadyHasFieldset_ThrowsInvalidOperationException()
        {
            // Arrange
            var checkboxesContext = new CheckboxesContext(name: null, aspFor: null);

            checkboxesContext.OpenFieldset();
            var checkboxesFieldsetContext = new CheckboxesFieldsetContext(attributes: null);

            checkboxesFieldsetContext.SetLegend(isPageHeading: false, attributes: null, content: new HtmlString("Existing legend"));
            checkboxesContext.CloseFieldset(checkboxesFieldsetContext);

            var context = new TagHelperContext(
                tagName: "govuk-checkboxes-fieldset",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(CheckboxesContext), checkboxesContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-checkboxes-fieldset",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var fieldsetContext = context.GetContextItem <CheckboxesFieldsetContext>();
                fieldsetContext.SetLegend(isPageHeading: true, attributes: null, content: new HtmlString("Legend"));

                var tagHelperContent = new DefaultTagHelperContent();
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new CheckboxesFieldsetTagHelper();

            // Act
            var ex = await Record.ExceptionAsync(() => tagHelper.ProcessAsync(context, output));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("Only one <govuk-checkboxes-fieldset> element is permitted within each <govuk-checkboxes>.", ex.Message);
        }
Exemple #6
0
        public void AddItem_OutsideOfFieldset_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesContext(name: null, aspFor: null);

            var item = new CheckboxesItem()
            {
                LabelContent = new HtmlString("Item 1"),
                Value        = "item1"
            };

            context.OpenFieldset();
            var fieldsetContext = new CheckboxesFieldsetContext(attributes: null);

            context.CloseFieldset(fieldsetContext);

            // Act
            var ex = Record.Exception(() => context.AddItem(item));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-checkboxes-item> must be inside <govuk-checkboxes-fieldset>.", ex.Message);
        }