public FileMetaServiceFixture() { serviceProvider = new ServiceCollection() .AddOptions() .Configure <FileMetaServiceSettings>( fileMetaServiceSettings => new ConfigurationBuilder() .AddJsonFile("appsettings.json", false, false) .Build() .GetSection("FileMetaService") .Bind(fileMetaServiceSettings) ) .AddSingleton(Assembly.GetExecutingAssembly()) .AddSingleton <IEmbeddedResourceResolver, EmbeddedResourceResolver>() .AddSingleton <IFileMetaDbFactory, FileMetaDbFactoryImpl>() .AddSingleton <IFileRegistry, FileRegistryImpl>() .AddSingleton <IFileMetaService, FileMetaServiceImpl>() .BuildServiceProvider(); embeddedResourceResolver = serviceProvider.GetService <IEmbeddedResourceResolver>(); fileMetaDbFactory = serviceProvider.GetService <IFileMetaDbFactory>(); using (var stream = embeddedResourceResolver.GetStream($"sql/mysql_init.sql")) using (var connection = fileMetaDbFactory.CreateConnection()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = new StreamReader(stream).ReadToEnd(); command.ExecuteNonQuery(); } } }
public Stream GetSqlScript(string name) { return(embeddedResourceResolver.GetStream($"sql/{name}")); }