コード例 #1
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);
        }
コード例 #2
0
        public void SetErrorMessage_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.SetErrorMessage(visuallyHiddenText: null, attributes: null, new HtmlString("Error")));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-checkboxes-error-message> must be specified before <govuk-checkboxes-item>.", ex.Message);
        }
コード例 #3
0
        public void SetErrorMessage_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.SetErrorMessage(visuallyHiddenText: null, attributes: null, new HtmlString("Error")));

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