public async Task SetsLogLevel(string logLevel, int expected) { // Given string[] args = new[] { "build", "-l", logLevel }; IBootstrapper bootstrapper = App.Bootstrapper.Create(args); bootstrapper.AddCommand <BuildCommand <EngineCommandSettings> >("build"); TestLoggerProvider provider = new TestLoggerProvider { ThrowLogLevel = LogLevel.None }; bootstrapper.ConfigureServices(services => services.AddSingleton <ILoggerProvider>(provider)); 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 int exitCode = await bootstrapper.RunAsync(); // Then exitCode.ShouldBe((int)ExitCode.Normal); provider.Messages.Count(x => x.FormattedMessage.StartsWith("Foo/Process")).ShouldBe(expected); }
public async Task LogsVersion() { // Given string[] args = new[] { "build" }; TestLoggerProvider provider = new TestLoggerProvider(); IBootstrapper bootstrapper = App.Bootstrapper.Create(args); bootstrapper.AddCommand <BuildCommand>("build"); bootstrapper.AddServices(services => services.AddSingleton <ILoggerProvider>(provider)); bootstrapper.AddPipeline("Foo"); // When int exitCode = await bootstrapper.RunAsync(); // Then exitCode.ShouldBe((int)ExitCode.Normal); provider.Messages.ShouldContain(x => x.FormattedMessage.StartsWith("Statiq version")); }
public async Task CommandLineSettingTakesPrecedenceOverDefaultSettings() { // Given string[] args = new string[] { "-s", $"{Keys.LinkHideIndexPages}=false" }; IBootstrapper bootstrapper = App.Bootstrapper.CreateDefault(args); TestLoggerProvider provider = new TestLoggerProvider(); bootstrapper.ConfigureServices(services => services.AddSingleton <ILoggerProvider>(provider)); object variable = null; bootstrapper.AddPipeline("Foo", new ExecuteConfig(Config.FromContext(x => variable = x.Settings[Keys.LinkHideIndexPages]))); // When int exitCode = await bootstrapper.RunAsync(); // Then exitCode.ShouldBe((int)ExitCode.Normal); variable.ShouldBe("false"); }
public async Task CatalogsType() { // Given string[] args = new[] { "build", "-l", "Debug" }; TestLoggerProvider provider = new TestLoggerProvider(); IBootstrapper bootstrapper = App.Bootstrapper.Create(args); bootstrapper.AddCommand <BuildCommand>("build"); bootstrapper.AddServices(services => services.AddSingleton <ILoggerProvider>(provider)); bootstrapper.AddPipeline("Foo"); // When int exitCode = await bootstrapper.RunAsync(); // Then exitCode.ShouldBe((int)ExitCode.Normal); bootstrapper.ClassCatalog.GetAssignableFrom <BootstrapperFixture>().Count().ShouldBe(1); provider.Messages.ShouldContain(x => x.FormattedMessage.StartsWith("Cataloging types in assembly")); }
public async Task CommandLineSettingTakesPrecedenceOverEnvironmentVariables() { // Given string[] args = new string[] { "-s", $"{nameof(CommandLineSettingTakesPrecedenceOverEnvironmentVariables)}=Bar" }; Environment.SetEnvironmentVariable(nameof(CommandLineSettingTakesPrecedenceOverEnvironmentVariables), "Foo"); IBootstrapper bootstrapper = App.Bootstrapper.CreateDefault(args); TestLoggerProvider provider = new TestLoggerProvider(); bootstrapper.ConfigureServices(services => services.AddSingleton <ILoggerProvider>(provider)); object variable = null; bootstrapper.AddPipeline("Foo", new ExecuteConfig(Config.FromContext(x => variable = x.Settings[nameof(CommandLineSettingTakesPrecedenceOverEnvironmentVariables)]))); // When int exitCode = await bootstrapper.RunAsync(); // Then exitCode.ShouldBe((int)ExitCode.Normal); variable.ShouldBe("Bar"); }
public async Task CanReadConfigurationValues() { // Given string[] args = new string[] { }; Environment.SetEnvironmentVariable(nameof(CanReadConfigurationValues), "Foo"); IBootstrapper bootstrapper = App.Bootstrapper.CreateDefault(args); TestLoggerProvider provider = new TestLoggerProvider(); bootstrapper.ConfigureServices(services => services.AddSingleton <ILoggerProvider>(provider)); string variable = null; bootstrapper.ConfigureSettings(x => variable = x[nameof(CanReadConfigurationValues)]); bootstrapper.AddPipeline("Foo"); // When int exitCode = await bootstrapper.RunAsync(); // Then exitCode.ShouldBe((int)ExitCode.Normal); variable.ShouldBe("Foo"); }