public void TryGetPageDirective_Directive_WithoutPathOrContent()
        {
            // Arrange
            var projectItem = new TestRazorProjectItem("Test.cshtml", @"@page");

            // Act & Assert
            Assert.True(PageDirectiveFeature.TryGetPageDirective(NullLogger.Instance, projectItem, out var template));
            Assert.Null(template);
        }
        public void TryGetPageDirective_JunkBeforeDirective()
        {
            // Arrange
            var projectItem = new TestRazorProjectItem("Test.cshtml", @"Not a directive @page ""Some/Path/{value}""");
            var sink        = new TestSink();
            var logger      = new TestLogger("logger", sink, enabled: true);

            // Act & Assert
            Assert.False(PageDirectiveFeature.TryGetPageDirective(logger, projectItem, out var template));
            Assert.Null(template);
            Assert.Empty(sink.Writes);
        }
        public void TryGetPageDirective_NoNewLine()
        {
            // Arrange
            var projectItem = new TestRazorProjectItem("Test.cshtml", @"@page ""Some/Path/{value}""");
            var sink        = new TestSink();
            var logger      = new TestLogger("logger", sink, enabled: true);

            // Act & Assert
            Assert.True(PageDirectiveFeature.TryGetPageDirective(logger, projectItem, out var template));
            Assert.Equal("Some/Path/{value}", template);
            Assert.Empty(sink.Writes);
        }
        public void TryGetPageDirective_NoDirective()
        {
            // Arrange
            var projectItem = new TestRazorProjectItem("Test.cshtml", @"This is junk
Nobody will use it");
            var sink        = new TestSink();
            var logger      = new TestLogger("logger", sink, enabled: true);

            // Act & Assert
            Assert.False(PageDirectiveFeature.TryGetPageDirective(logger, projectItem, out var template));
            Assert.Null(template);
            Assert.Empty(sink.Writes);
        }
        public void TryGetPageDirective_DirectiveWithContent_WithoutPath()
        {
            // Arrange
            var projectItem = new TestRazorProjectItem("Test.cshtml", @"@page
Non-path things");
            var sink        = new TestSink();
            var logger      = new TestLogger("logger", sink, enabled: true);

            // Act & Assert
            Assert.True(PageDirectiveFeature.TryGetPageDirective(logger, projectItem, out var template));
            Assert.Null(template);
            Assert.Empty(sink.Writes);
        }
        public void TryGetPageDirective_WithoutBothQuotes_LogsWarning(string inTemplate)
        {
            // Arrange
            var expected    = "The page directive at 'Test.cshtml' is malformed. Please fix the following issues: The 'page' directive expects a string surrounded by double quotes.";
            var sink        = new TestSink();
            var logger      = new TestLogger("logger", sink, enabled: true);
            var projectItem = new TestRazorProjectItem("Test.cshtml", $@"@page {inTemplate}");

            // Act & Assert
            Assert.True(PageDirectiveFeature.TryGetPageDirective(logger, projectItem, out var template));
            Assert.Null(template);
            Assert.Collection(sink.Writes,
                              log =>
            {
                Assert.Equal(LogLevel.Warning, log.LogLevel);
                Assert.Equal(expected, log.State.ToString());
            });
        }