public static IHostBuilder CreateMiruHost <TStartup>() where TStartup : class { return(MiruHost.CreateMiruHost <TStartup>() .ConfigureWebHost(host => { // we don't want the tests fail because there is no tcp port available // so here, listen to any available port host.UseKestrelAnyLocalPort(); })); }
public void Miru_host_should_have_miru_consolables() { var consolableTypes = MiruHost .CreateMiruHost() .Build() .Services .GetRegisteredServices <IConsolable>(); // act consolableTypes.ShouldContain(m => m == typeof(ConfigShowConsolable)); consolableTypes.ShouldContain(m => m == typeof(DbMigrateConsolable)); }
public async Task Should_run_web_host() { // arrange var hostBuilder = MiruHost .CreateMiruHost() .ConfigureWebHostDefaults(m => m.UseStartup <Startup>()); // act await hostBuilder.RunMiruAsync(); Startup.Executed.ShouldBeTrue(); }
public async Task Should_run_web_host() { // arrange // TODO: automatic port var hostBuilder = MiruHost .CreateMiruHost() .ConfigureWebHostDefaults(m => m.UseStartup <Startup>().UseKestrelAnyLocalPort()); // act await hostBuilder.RunMiruAsync(); Startup.Executed.ShouldBeTrue(); }
public async Task Should_process_a_scheduled_task() { // arrange var hostBuilder = MiruHost .CreateMiruHost() .ConfigureServices(services => { services.AddMiruTestFixture() .AddTaskScheduling <ScheduledTaskConfig>(); }); // act await hostBuilder.RunMiruAsync(); SomeTask.Executed.ShouldBeTrue(); }
public async Task Can_run_config_show() { var defaultWriter = Console.Out; var writer = new StringWriter(); Console.SetOut(writer); await MiruHost.CreateMiruHost <Startup>("miru", "config:show", "-e", "Test").RunMiruAsync(); var output = writer.ToString(); output.ShouldContain("EnvironmentName: Test"); Console.SetOut(defaultWriter); Console.Write(writer.ToString()); }
public async Task Should_support_dependency_injection() { // arrange var host = MiruHost.CreateMiruHost("miru", "miru.dependency", "--name", "Paul") .ConfigureServices(services => { services.AddScoped <IDependency, Dependency>(); services.AddConsolable <ExampleConsolable>(); }); // act await host.RunMiruAsync(); // assert var output = _outWriter.ToString(); output.ShouldStartWith("Name: Paul, Surname: McCartney"); }
public async Task Should_run_miru_cli_host() { // arrange var hostBuilder = MiruHost .CreateMiruHost("miru", "test.assert") .ConfigureServices(services => { services .AddConsolable <TestAssertConsolable>() .AddSingleton(services); }); // act await hostBuilder.RunMiruAsync(); // assert TestAssertConsolable.Executed.ShouldBeTrue(); }
public async Task Should_create_database_only() { var app = MiruHost.CreateMiruHost() .ConfigureServices(services => { services.AddEfCoreSqlServer <TestDbContext>(); var appSettings = new DatabaseOptions() { ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=miru_test;Integrated Security=SSPI;" }; services.AddSingleton(appSettings); }) .BuildApp(); await app.Get <IDatabaseCreator>().Create(); }
public async Task Should_run_a_miru_command() { // arrange var host = MiruHost.CreateMiruHost("miru", "config.show") .ConfigureServices(services => { services .AddMiruCliHost() .AddConsolable <ConfigShowConsolable>(); }); // act await host.RunMiruAsync(); // assert var output = _outWriter.ToString(); output.ShouldContain("Miru version: "); output.ShouldContain("Host:"); output.ShouldContain("EnvironmentName: Development"); output.ShouldContain("All Configurations:"); }
public MailingTest() { _host = new MiruTestWebHost(MiruHost.CreateMiruHost(), services => { services .AddStorage() .AddMiruMvc() .AddMiruUrls() .AddLogging() .AddSerilogConfig() .AddSingleton <IUrlMaps, StubUrlMaps>() .AddMailing(options => { options.EmailDefaults(email => { email.From("*****@*****.**", "Mailing Test"); email.ReplyTo("*****@*****.**"); }); options.AppUrl = "http://www.contoso.com"; options.TemplatePath = new SolutionFinder().FromCurrentDir().Solution.AppTestsDir; }) .AddMiruTestFixture() .AddSenderMemory() .AddSingleton <MiruSolution, MiruTestSolution>() .AddQueuing((sp, cfg) => cfg.UseMemoryStorage()) .AddMediatR(typeof(MailingTest).Assembly); }); _sp = _host.Services; _mailer = _sp.GetService <IMailer>(); _emailsSent = _sp.GetService <MemorySender>(); _ = _sp.GetService <ITestFixture>(); }
public async Task Should_run_help() { // arrange var host = MiruHost.CreateMiruHost("miru") .ConfigureServices(services => { services .AddMiruCliHost() .AddConsolables <ConfigShowConsolable>(); }); // act await host.RunMiruAsync(); // assert var output = _outWriter.ToString(); Console.WriteLine(output); output.ShouldContain("config.show"); output.ShouldContain("Show the configuration will be used"); output.ShouldContain("help"); }
public void Run_host_specifying_environment_shortcut() { var sp = MiruHost.CreateMiruHost("-e", "Test").Build().Services; sp.GetService <IHostEnvironment>().EnvironmentName.ShouldBe("Test"); }
public void Run_host_specifying_environment() { var sp = MiruHost.CreateMiruHost("--environment", "Staging").Build().Services; sp.GetService <IHostEnvironment>().EnvironmentName.ShouldBe("Staging"); }
public void Run_host_without_environment_should_be_development() { var sp = MiruHost.CreateMiruHost().Build().Services; sp.GetService <IHostEnvironment>().EnvironmentName.ShouldBe("Development"); }
public void Run_host_with_configuration_from_command_line_args() { var sp = MiruHost.CreateMiruHost("--Database:ConnectionString=DataSource={{ db_dir }}App_dev.db").Build().Services; sp.GetService <DatabaseOptions>().ConnectionString.ShouldBe("DataSource={{ db_dir }}App_dev.db"); }
public virtual IHostBuilder GetHostBuilder() { return(MiruHost.CreateMiruHost <Startup>()); }
public static async Task Main(string[] args) => await MiruHost .CreateMiruWebHost <Startup>(args) .RunMiruAsync();
public virtual IHostBuilder GetHostBuilder() => MiruHost.CreateMiruHost <Startup>();