Пример #1
0
            public async Task DocumentGatherHeadingsLevelSetting()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper
                                            .Factory
                                            .CreateWeb(Array.Empty <string>())
                                            .AddSetting(WebKeys.GatherHeadingsLevel, 3);
                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/foo.html",
                        @"GatherHeadingsLevel: 2
---" + GatherHeadingsFile
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Content)][Phase.Process].ShouldHaveSingleItem();

                document
                .GetDocumentList(HtmlKeys.Headings)
                .Flatten()
                .Select(x => x.GetContentStringAsync().Result)
                .ShouldBe(new[] { "1.1", "1.2", "2.1", "2.2", "2.3" }, true);
            }
Пример #2
0
            public async Task GeneratesNetlifyRedirects()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper.Factory
                                            .CreateWeb(Array.Empty <string>())
                                            .AddSetting(WebKeys.NetlifyRedirects, true)
                                            .AddSetting(WebKeys.MetaRefreshRedirects, false);
                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/a/b/c.md",
                        @"RedirectFrom: x/y
---
Foo"
                    },
                    {
                        "/input/d/e.md",
                        "Bar"
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Redirects)][Phase.Process].ShouldHaveSingleItem();

                document.Destination.ShouldBe("_redirects");
                (await document.GetContentStringAsync()).ShouldBe("/x/y /a/b/c");
            }
Пример #3
0
            public async Task ExcludeFromSitemapWhenSpecified()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper
                                            .Factory
                                            .CreateWeb(Array.Empty <string>())
                                            .AddSetting(WebKeys.GenerateSitemap, true);

                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/foo.html",
                        @"IncludeInSitemap: false
---" + ContentFile
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document       = result.Outputs[nameof(Sitemap)][Phase.Output].ShouldHaveSingleItem();
                string    sitemapContent = await document.GetContentStringAsync();

                sitemapContent.ShouldNotContain("<loc>/foo</loc>");
            }
Пример #4
0
            public async Task GeneratesClientRedirects()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/a/b/c.md",
                        @"RedirectFrom: x/y
---
Foo"
                    },
                    {
                        "/input/d/e.md",
                        "Bar"
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Redirects)][Phase.Process].ShouldHaveSingleItem();

                document.Destination.ShouldBe("x/y.html");
                (await document.GetContentStringAsync()).ShouldContain(@"<meta http-equiv=""refresh"" content=""0;url='/a/b/c'"" />");
            }
Пример #5
0
            public async Task IncludeInSitemapByDefault()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper
                                            .Factory
                                            .CreateWeb(Array.Empty <string>());

                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/foo.html",
                        ContentFile
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document       = result.Outputs[nameof(Sitemap)][Phase.Output].ShouldHaveSingleItem();
                string    sitemapContent = await document.GetContentStringAsync();

                sitemapContent.ShouldContain("<loc>/foo</loc>");
            }
Пример #6
0
            public async Task FrontMatterOverridesDirectoryMetadata()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/a/b/c.json",
                        @"Fizz: Buzz
---
{ ""Foo"": ""Bar"" }"
                    },
                    { "/input/a/_directory.json", "{ \"Fizz\": \"Bazz\", \"Blue\": \"Green\" }" }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();

                document["Fizz"].ShouldBe("Buzz");
                document["Blue"].ShouldBe("Green");
                document["Foo"].ShouldBe("Bar");
                (await document.GetContentStringAsync()).ShouldBe("{ \"Foo\": \"Bar\" }");
            }
Пример #7
0
            public async Task ParsesYamlWithFrontMatter()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/a/b/c.yaml",
                        @"Fizz: Buzz
---
Foo: Bar"
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();

                document["Fizz"].ShouldBe("Buzz");
                document["Foo"].ShouldBe("Bar");
                (await document.GetContentStringAsync()).ShouldBe("Foo: Bar");
            }
            public async Task AddsDefaultThemeInputPath()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper
                                            .Factory
                                            .CreateWeb(Array.Empty <string>());

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.Engine.FileSystem.InputPaths.ShouldBe(new NormalizedPath[] { "theme/input", "input" });
            }
            public async Task CommandLineSettingsAreCaseInsensitive()
            {
                // Given
                string[]         args         = new[] { "--setting", "foo=bar" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                bootstrapper.AddPipeline("Test");

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.Engine.Settings["Foo"].ShouldBe("bar");
            }
            public async Task LogsVersion()
            {
                // Given
                string[]         args         = new[] { "build" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.Create(args);
                bootstrapper.AddCommand <PipelinesCommand <EngineCommandSettings> >("build");
                bootstrapper.AddPipeline("Foo");

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.LogMessages.ShouldContain(x => x.FormattedMessage.StartsWith("Statiq version"));
            }
            public async Task SetsFlagFromCommandLine()
            {
                // Given
                string[]         args         = new string[] { "--noclean" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                object           value        = null;

                bootstrapper.AddPipeline("Foo", new ExecuteConfig(Config.FromContext(x => value = x.Settings[Keys.CleanOutputPath])));

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                value.ShouldBe(false);
            }
            public async Task NoPipelinesWarning()
            {
                // Given
                string[]         args         = new[] { "build" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.Create(args);
                bootstrapper.AddCommand <PipelinesCommand <EngineCommandSettings> >("build");

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(LogLevel.None);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.LogMessages.ShouldContain(x =>
                                                 x.LogLevel == LogLevel.Warning &&
                                                 x.FormattedMessage == "No pipelines are configured or specified for execution.");
            }
            public async Task CatalogsType()
            {
                // Given
                string[]         args         = new[] { "build", "-l", "Debug" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.Create(args);
                bootstrapper.AddCommand <PipelinesCommand <EngineCommandSettings> >("build");
                bootstrapper.AddPipeline("Foo");

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                bootstrapper.ClassCatalog.GetTypesAssignableTo <BootstrapperFixture>().Count().ShouldBe(1);
                result.LogMessages.ShouldContain(x => x.FormattedMessage.StartsWith("Cataloging types in assembly"));
            }
            public async Task CommandLineSettingTakesPrecedenceOverDefaultSettings()
            {
                // Given
                string[]         args         = new string[] { "-s", $"{Keys.LinkHideIndexPages}=false" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                object           variable     = null;

                bootstrapper.AddPipeline("Foo", new ExecuteConfig(Config.FromContext(x => variable = x.Settings[Keys.LinkHideIndexPages])));

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                variable.ShouldBe("false");
            }
            public async Task CommandLineSettingTakesPrecedenceOverEnvironmentVariables()
            {
                // Given
                string[] args = new string[] { "-s", $"{nameof(CommandLineSettingTakesPrecedenceOverEnvironmentVariables)}=Bar" };
                Environment.SetEnvironmentVariable(nameof(CommandLineSettingTakesPrecedenceOverEnvironmentVariables), "Foo");
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                object           variable     = null;

                bootstrapper.AddPipeline("Foo", new ExecuteConfig(Config.FromContext(x => variable = x.Settings[nameof(CommandLineSettingTakesPrecedenceOverEnvironmentVariables)])));

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                variable.ShouldBe("Bar");
            }
            public async Task EnvironmentVariableConfiguration()
            {
                // Given
                string[] args = new string[] { };
                Environment.SetEnvironmentVariable(nameof(EnvironmentVariableConfiguration), "Foo");
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                object           variable     = null;

                bootstrapper.AddPipeline("Foo", new ExecuteConfig(Config.FromContext(x => variable = x.Settings[nameof(EnvironmentVariableConfiguration)])));

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                variable.ShouldBe("Foo");
            }
            public async Task AddsThemePath()
            {
                // Given
                ThemeManager themeManager = null;
                Bootstrapper bootstrapper = Bootstrapper
                                            .Factory
                                            .CreateWeb(Array.Empty <string>())
                                            .AddThemePath("foo")
                                            .ConfigureEngine(engine => themeManager = engine.Services.GetRequiredService <ThemeManager>());

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                themeManager.ThemePaths.ShouldBe(new NormalizedPath[] { "theme", "foo" });
            }
            public async Task CanReadConfigurationValues()
            {
                // Given
                string[] args = new string[] { };
                Environment.SetEnvironmentVariable(nameof(CanReadConfigurationValues), "Foo");
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                object           variable     = null;

                bootstrapper.ConfigureSettings(x => variable = x[nameof(CanReadConfigurationValues)]);
                bootstrapper.AddPipeline("Foo");

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                variable.ShouldBe("Foo");
            }
Пример #19
0
            public async Task ParsesJson()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    { "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();

                document["Foo"].ShouldBe("Bar");
            }
            public async Task AddsComputedMetadataFromCommandLine()
            {
                // Given
                string[]         args         = new[] { "--setting", "\"Foo = => 1 + 1\"" };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.CreateDefault(args);
                object           value        = null;

                bootstrapper.AddPipeline(
                    "Test",
                    new ExecuteConfig(Config.FromSettings(x => value = x["Foo"])));

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync();

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                value.ShouldBe(2);
            }
Пример #21
0
            public async Task SupportsMultipleDataFilesPatterns()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());

                bootstrapper.AddSetting(WebKeys.DataFiles, new[] { "a/**/*.json", "x/**/*.json" });
                TestFileProvider fileProvider = new TestFileProvider
                {
                    { "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
                    { "/input/x/y/z.json", "{ \"Foo\": \"Buz\" }" }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.Outputs[nameof(Data)][Phase.Process].Select(x => x["Foo"]).ShouldBe(new[] { "Bar", "Buz" }, true);
            }
Пример #22
0
            public async Task DoesNotAddNonRecursiveDirectoryMetadata()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    { "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
                    { "/input/a/_directory.json", "{ \"Fizz\": \"Buzz\", \"Recursive\": \"false\" }" }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();

                document["Foo"].ShouldBe("Bar");
                document.ContainsKey("Fizz").ShouldBeFalse();
            }
Пример #23
0
            public async Task IncludesDocumentsFromDependencies()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());

                bootstrapper.AddSetting(WebKeys.DataFiles, "x/**/*.json");
                bootstrapper.BuildPipeline("Test", builder => builder
                                           .WithInputReadFiles("a/**/*.json")
                                           .AsDependencyOf(nameof(Data)));
                TestFileProvider fileProvider = new TestFileProvider
                {
                    { "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
                    { "/input/x/y/z.json", "{ \"Foo\": \"Buz\" }" }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.Outputs[nameof(Data)][Phase.Process].Select(x => x["Foo"]).ShouldBe(new[] { "Bar", "Buz" }, true);
            }
Пример #24
0
            public async Task ProcessesJsonSidecarFileWithDifferentExtension()
            {
                // Given
                Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());

                bootstrapper.AddSetting(WebKeys.DataFiles, "**/*.foo");
                TestFileProvider fileProvider = new TestFileProvider
                {
                    { "/input/a/b/c.foo", "Foobar" },
                    { "/input/a/b/_c.json", "{ \"Fizz\": \"Buzz\" }" }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();

                document["Fizz"].ShouldBe("Buzz");
                (await document.GetContentStringAsync()).ShouldBe("Foobar");
            }
            public async Task SetsLogLevel(string logLevel, int expected)
            {
                // Given
                string[]         args         = new[] { "build", "-l", logLevel };
                App.Bootstrapper bootstrapper = App.Bootstrapper.Factory.Create(args);
                bootstrapper.AddCommand <PipelinesCommand <EngineCommandSettings> >("build");
                bootstrapper.AddPipeline(
                    "Foo",
                    new Core.LogMessage(LogLevel.Trace, "A"),
                    new Core.LogMessage(LogLevel.Debug, "B"),
                    new Core.LogMessage(LogLevel.Information, "C"),
                    new Core.LogMessage(LogLevel.Warning, "D"),
                    new Core.LogMessage(LogLevel.Error, "E"),
                    new Core.LogMessage(LogLevel.Critical, "F"));

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(LogLevel.None);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.LogMessages.Count(x => x.FormattedMessage.StartsWith("Foo/Process")).ShouldBe(expected);
            }
Пример #26
0
            public async Task EnumeratesValues()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    {
                        "/input/a/b/c.json",
                        @"Enumerate:
  - Apple
  - Orange
---
{ ""Foo"": ""Bar"" }"
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                result.Outputs[nameof(Data)][Phase.Process].Select(x => x["Current"]).ShouldBe(new[] { "Apple", "Orange" }, true);
            }
Пример #27
0
            public async Task AllowsStringIds()
            {
                // Given
                Bootstrapper     bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty <string>());
                TestFileProvider fileProvider = new TestFileProvider
                {
                    { "/input/foo.md", "Hi!" },
                    {
                        "/input/feed.yml",
                        @"FeedItemId: => ""Bar""
FeedRss: true"
                    }
                };

                // When
                BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

                // Then
                result.ExitCode.ShouldBe((int)ExitCode.Normal);
                IDocument document = result.Outputs[nameof(Web.Pipelines.Feeds)][Phase.Process].ShouldHaveSingleItem();

                (await document.GetContentStringAsync()).ShouldContain(@"<guid isPermaLink=""false"">Bar</guid>");
            }