コード例 #1
0
        public void CreateLeasingSessionForConnectionString()
        {
            var session = new SqlSession(new SqlConnection(ConnectionStrings.AlenosoftTestDb));

            Assert.False(session.OwnsConnection);
            Assert.True(session.ConnectionState == ConnectionState.Closed);
            Assert.Throws<InvalidOperationException>(() => session.OpenConnectionAsync().GetAwaiter().GetResult());
            Assert.True(session.ConnectionState == ConnectionState.Closed);
        }
コード例 #2
0
        public void CreateOwningSessionForConnectionString()
        {
            var session = new SqlSession(ConnectionStrings.AlenosoftTestDb);

            Assert.True(session.OwnsConnection);
            Assert.True(session.ConnectionState == ConnectionState.Closed);

            using (session.OpenConnectionAsync().GetAwaiter().GetResult())
            {
                Assert.True(session.ConnectionState == ConnectionState.Open);
            }

            Assert.True(session.ConnectionState == ConnectionState.Closed);
        }
コード例 #3
0
        public void OpenConnection()
        {
            var session = new SqlSession(ConnectionStrings.AlenosoftTestDb);

            using (session.OpenConnectionAsync().GetAwaiter().GetResult())
            {
                Assert.Equal(ConnectionState.Open, session.ConnectionState);
                var date = (DateTime)session.ExecuteScalarAsync(new SqlCommand(@"SELECT CONVERT(DATETIME, '01-01-3000', 105)")).GetAwaiter().GetResult();
                Assert.Equal(date, new DateTime(3000, 01, 01));
                Assert.Equal(ConnectionState.Open, session.ConnectionState);
            }

            Assert.Equal(ConnectionState.Closed, session.ConnectionState);
        }