コード例 #1
0
        public void Dispose_does_not_throw_exception_if_connection_is_null()
        {
            var context = new TestableSqliteTransaction();
            var sut     = new SqliteTransaction(context.ConnectionStringFactory.Object, IsolationLevel.ReadCommitted);

            sut.Dispose();

            Assert.False(sut.IsOpen);
            Assert.True(sut.IsOwner);
        }
コード例 #2
0
        public void Connection_is_same_as_parent_when_child()
        {
            var context = new TestableSqliteTransaction();

            var parent = new SqliteTransaction(context.ConnectionStringFactory.Object, IsolationLevel.ReadCommitted);

            var child = new SqliteTransaction(parent);

            Assert.False(child.IsOwner);
            Assert.True(child.IsOpen);
            Assert.True(child.Connection == parent.Connection);
        }
コード例 #3
0
        public void ctor_does_create_open_connection()
        {
            var context = new TestableSqliteTransaction();

            var sut = new SqliteTransaction(context.ConnectionStringFactory.Object, IsolationLevel.ReadCommitted);

            Assert.NotNull(sut.Connection);
            Assert.Equal(ConnectionState.Open, sut.Connection.State);

            sut.Connection.Execute("CREATE TABLE [City] ([Id] INT NOT NULL PRIMARY KEY, [Name] TEXT NOT NULL)");
            sut.Connection.Execute("INSERT INTO [City] ([Id], [Name]) VALUES (1, 'Phoenix')");

            var cities = sut.Connection.Query <City>("SELECT * FROM [City]")
                         .ToList();

            Assert.Single(cities);
            Assert.Equal("Phoenix", cities[0].Name);
            Assert.Equal(1, cities[0].Id);
        }