Exemplo n.º 1
0
        public void Use_With_Dependency_Injection()
        {
            // Register with SQL LocalDB services
            var services = new ServiceCollection()
                           .AddLogging((builder) => builder.AddXUnit(OutputHelper))
                           .AddSqlLocalDB();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                ISqlLocalDbApi             localDB  = scope.ServiceProvider.GetService <ISqlLocalDbApi>();
                ISqlLocalDbInstanceInfo    instance = localDB.GetDefaultInstance();
                ISqlLocalDbInstanceManager manager  = instance.Manage();

                if (!instance.IsRunning)
                {
                    manager.Start();
                }

                using (SqlConnection connection = instance.CreateConnection())
                {
                    connection.Open();

                    // Use the SQL connection...
                }
            }
        }
Exemplo n.º 2
0
        public void GetDefaultInstance_Throws_If_Api_Is_Null()
        {
            // Arrange
            ISqlLocalDbApi api = null;

            // Act and Assert
            Assert.Throws <ArgumentNullException>("api", () => api.GetDefaultInstance());
        }