private void DeleteAllData() { var conn = ConnectionUtil.GetConnectionString(); using (var connection = ConnectionUtil.CreateConnection(conn)) { connection.Execute($@" TRUNCATE TABLE cap.published; TRUNCATE TABLE cap.received;"); } }
protected DatabaseTestHost() { Logger = new Mock <ILogger <SqlServerStorage> >().Object; CapOptions = new Mock <CapOptions>().Object; SqlSeverOptions = new SqlServerOptions() { ConnectionString = ConnectionUtil.GetConnectionString() }; DiagnosticProcessorObserver = new DiagnosticProcessorObserver(new Mock <IDispatcher>().Object); InitializeDatabase(); }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); _connectionString = ConnectionUtil.GetConnectionString(); services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString }); services.AddSingleton <SqlServerStorage>(); _services = services; }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); _connectionString = ConnectionUtil.GetConnectionString(); services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString }); services.AddSingleton <SqlServerStorage>(); services.AddDbContext <TestDbContext>(options => options.UseSqlServer(_connectionString)); _services = services; }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); ConnectionString = ConnectionUtil.GetConnectionString(); services.AddOptions <CapOptions>(); services.Configure <SqlServerOptions>(x => { x.ConnectionString = ConnectionString; }); services.AddSingleton <SqlServerDataStorage>(); services.AddSingleton <IStorageInitializer, SqlServerStorageInitializer>(); _services = services; }
protected DatabaseTestHost() { Logger = new Mock <ILogger <SqlServerStorage> >().Object; var capOptions = new Mock <IOptions <CapOptions> >(); capOptions.Setup(x => x.Value).Returns(new CapOptions()); CapOptions = capOptions.Object; var options = new Mock <IOptions <SqlServerOptions> >(); options.Setup(x => x.Value).Returns(new SqlServerOptions { ConnectionString = ConnectionUtil.GetConnectionString() }); SqlSeverOptions = options.Object; DiagnosticProcessorObserver = new DiagnosticProcessorObserver(new Mock <IDispatcher>().Object); InitializeDatabase(); }
private void DeleteAllData() { var conn = ConnectionUtil.GetConnectionString(); using (var connection = new SqlConnection(conn)) { var commands = new[] { "DISABLE TRIGGER ALL ON ?", "ALTER TABLE ? NOCHECK CONSTRAINT ALL", "DELETE FROM ?", "ALTER TABLE ? CHECK CONSTRAINT ALL", "ENABLE TRIGGER ALL ON ?" }; foreach (var command in commands) { connection.Execute( "sp_MSforeachtable", new { command1 = command }, commandType: CommandType.StoredProcedure); } } }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var connectionString = ConnectionUtil.GetConnectionString(); optionsBuilder.UseSqlServer(connectionString); }