コード例 #1
0
        public async Task When_creating_connection()
        {
            var sampleDbs = GetSampleDBs();

            using (var conn = new SQLiteAttachedConnection(sampleDbs))
            {
                conn.FilesToAttach.ShouldBe(sampleDbs);

                conn.ConnectionString.ShouldBe("Data Source=:memory:");
                conn.ConnectionTimeout.ShouldBe(15);
                conn.DataSource.ShouldBeNull();
                conn.Database.ShouldBe("main");
                conn.ServerVersion.ShouldBe("3.28.0");
                conn.State.ShouldBe(ConnectionState.Closed);

                var attachedDbs = await conn.GetAttachedDatabases();

                attachedDbs.Count.ShouldBe(4);

                attachedDbs["main"].ShouldBeNull();
                attachedDbs["a"].FullName.ShouldBe(sampleDbs["a"].FullName);
                attachedDbs["b"].FullName.ShouldBe(sampleDbs["b"].FullName);
                attachedDbs["c"].FullName.ShouldBe(sampleDbs["c"].FullName);

                conn.Close();

                attachedDbs = await conn.GetAttachedDatabases();

                attachedDbs.Count.ShouldBe(4);

                conn.DataSource.ShouldBe(":memory:");
            }
        }
コード例 #2
0
        public void When_changing_connection_state()
        {
            var sampleDbs = GetSampleDBs();

            var conn = new SQLiteAttachedConnection(sampleDbs);

            conn.State.ShouldBe(ConnectionState.Closed);

            conn.Open();

            conn.State.ShouldBe(ConnectionState.Open);

            conn.Close();
            conn.State.ShouldBe(ConnectionState.Closed);

            conn.Dispose();

            Should.Throw <ObjectDisposedException>(() => conn.State.ShouldBe(ConnectionState.Closed))
            .Message.ShouldBe("Cannot access a disposed object.\r\nObject name: 'SQLiteConnection'.");
        }