Exemplo n.º 1
0
        public void SetBody_AlreadyGotBody_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new PanelContext();

            context.SetBody(new HtmlString("Body"));

            // Act
            var ex = Record.Exception(() => context.SetBody(new HtmlString("Body")));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("Only one <govuk-panel-body> element is permitted within each <govuk-panel>.", ex.Message);
        }
        public async Task ProcessAsync_ParentAlreadyHasBody_ThrowsInvalidOperationException()
        {
            // Arrange
            var panelContext = new PanelContext();

            panelContext.SetBody(new HtmlString("The body"));

            var context = new TagHelperContext(
                tagName: "govuk-panel-title",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(PanelContext), panelContext }
            },
                uniqueId: "test");

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

            var tagHelper = new PanelTitleTagHelper();

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

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-panel-title> must be specified before <govuk-panel-body>.", ex.Message);
        }
Exemplo n.º 3
0
        public void SetTitle_AlreadyGotBody_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new PanelContext();

            context.SetBody(new HtmlString("Body"));

            // Act
            var ex = Record.Exception(() => context.SetTitle(new HtmlString("Title")));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-panel-title> must be specified before <govuk-panel-body>.", ex.Message);
        }