public void When_creating_connection_with_non_memory_connection_string() { var fileConnectionString = SQLiteConnectionStringProvider.GetFileConnectionString(new FileInfo("SomeFile.db")); Should.Throw <ArgumentException>(() => new SQLiteInMemoryConnection(fileConnectionString)) .Message.ShouldBe("Not a valid SQLite memory connection-string."); }
public void When_creating_connection_with_valid_connection_string() { using (var conn = new SQLiteInMemoryConnection(SQLiteConnectionStringProvider.GetInMemoryConnectionString())) { conn.ConnectionString.ShouldBe("Data Source=:memory:"); conn.ConnectionTimeout.ShouldBe(15); conn.DataSource.ShouldBeNull(); conn.Database.ShouldBe("main"); conn.ServerVersion.ShouldBe("3.21.0"); conn.State.ShouldBe(ConnectionState.Closed); } }
public void When_creating_connection_with_valid_connection_string_with_parameters() { using (var conn = new SQLiteFileConnection(SQLiteConnectionStringProvider.GetFileConnectionString(new FileInfo("C:\\SomeFile.db")))) { conn.ConnectionString.ShouldBe(@"data source=C:\SomeFile.db;failifmissing=False;pooling=False;binaryguid=False;datetimekind=Utc;datetimeformat=UnixEpoch;journal mode=Wal;synchronous=Off;useutf16encoding=False;read only=False;legacy format=False;page size=4096;cache size=-2000"); conn.File.FullName.ShouldBe("C:\\SomeFile.db"); conn.ConnectionTimeout.ShouldBe(15); conn.DataSource.ShouldBeNull(); conn.Database.ShouldBe("main"); conn.ServerVersion.ShouldBe("3.28.0"); conn.State.ShouldBe(ConnectionState.Closed); } }
/// <summary> /// Creates an instance of the <see cref="SQLiteAttachedConnection"/>. /// </summary> /// <param name="dbFiles">Database files to attached where the key is the alias to be used for the database.</param> public SQLiteAttachedConnection(IReadOnlyDictionary <string, FileInfo> dbFiles) : base(SQLiteConnectionStringProvider.GetInMemoryConnectionString()) { FilesToAttach = Ensure.NotNull(dbFiles, nameof(dbFiles)); Ensure.That(dbFiles.Count != 0, "The dbFiles cannot be empty."); var cmdBuilder = StringBuilderCache.Acquire(); foreach (var pair in dbFiles) { cmdBuilder.AppendFormat("ATTACH DATABASE '{0}' AS '{1}';\r\n", pair.Value.FullName, pair.Key); } _attachCommands = StringBuilderCache.GetStringAndRelease(cmdBuilder); }
/// <summary> /// Creates an instance of the <see cref="SQLiteAttachedConnection"/>. /// </summary> /// <param name="dbFiles">Database files to attached where the key is the alias to be used for the database.</param> public SQLiteAttachedConnection(IReadOnlyDictionary <string, FileInfo> dbFiles) : base(SQLiteConnectionStringProvider.GetInMemoryConnectionString()) { FilesToAttach = dbFiles ?? throw new ArgumentNullException(nameof(dbFiles)); if (dbFiles.Count == 0) { throw new ArgumentException(nameof(dbFiles) + " cannot be empty."); } var cmdBuilder = StringBuilderCache.Acquire(); foreach (var pair in dbFiles) { cmdBuilder.AppendFormat("ATTACH DATABASE '{0}' AS '{1}';\r\n", pair.Value.FullName, pair.Key); } _attachCommands = StringBuilderCache.GetStringAndRelease(cmdBuilder); }
/// <summary> /// Creates an instance of the <see cref="SQLiteInMemoryConnection"/>. /// </summary> public SQLiteFileConnection(FileSystemInfo fileInfo) : base(SQLiteConnectionStringProvider.GetFileConnectionString(fileInfo)) { }
/// <summary> /// Creates an instance of the <see cref="SQLiteInMemoryConnection"/>. /// </summary> public SQLiteFileConnection(FileInfo dbFile) : base(SQLiteConnectionStringProvider.GetFileConnectionString(dbFile)) => File = dbFile;
/// <summary> /// Creates an instance of the <see cref="SQLiteInMemoryConnection"/>. /// </summary> public SQLiteInMemoryConnection() : base(SQLiteConnectionStringProvider.GetInMemoryConnectionString()) { }