DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DbConnectionTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 using System;
16 using System.Data;
17 
18 using NUnit.Framework;
19 
20 namespace Deveel.Data.Client {
21  [TestFixture]
22  public sealed class DbConnectionTests : ContextBasedTest {
23  [Test]
24  public void OpenForAdmin() {
25  IDbConnection connection = null;
26  Assert.DoesNotThrow(() => connection = Database.CreateDbConnection(AdminUserName, AdminPassword));
27  Assert.IsNotNull(connection);
28 
29  Assert.AreEqual(ConnectionState.Closed, connection.State);
30  Assert.DoesNotThrow(() => connection.Open());
31  Assert.AreEqual(ConnectionState.Open, connection.State);
32  Assert.DoesNotThrow(() => connection.Close());
33  Assert.AreEqual(ConnectionState.Closed, connection.State);
34  }
35 
36  [Test]
37  public void QueryScalarForAdmin() {
38  IDbConnection connection = null;
39  Assert.DoesNotThrow(() => connection = Database.CreateDbConnection(AdminUserName, AdminPassword));
40  Assert.IsNotNull(connection);
41 
42  IDbCommand command = null;
43  Assert.DoesNotThrow(() => command = connection.CreateCommand());
44  Assert.IsNotNull(command);
45 
46  command.CommandText = "SELECT user()";
47 
48  object value = null;
49  Assert.DoesNotThrow(() => value = command.ExecuteScalar());
50  Assert.IsNotNull(value);
51  Assert.IsInstanceOf<string>(value);
52  Assert.AreEqual(AdminUserName, value);
53 
54  Assert.DoesNotThrow(() => connection.Dispose());
55  }
56 
57  [Test]
58  public void QueryForAdmin() {
59  IDbConnection connection = null;
60  Assert.DoesNotThrow(() => connection = Database.CreateDbConnection(AdminUserName, AdminPassword));
61  Assert.IsNotNull(connection);
62 
63  IDbCommand command = null;
64  Assert.DoesNotThrow(() => command = connection.CreateCommand());
65  Assert.IsNotNull(command);
66 
67  command.CommandText = "SELECT user()";
68 
69  IDataReader reader = null;
70  Assert.DoesNotThrow(() => reader = command.ExecuteReader());
71  Assert.IsNotNull(reader);
72  Assert.AreEqual(1, reader.FieldCount);
73  Assert.IsTrue(reader.Read());
74 
75  object value = null;
76  Assert.DoesNotThrow(() => value = reader.GetValue(0));
77  Assert.IsInstanceOf<string>(value);
78  }
79  }
80 }
The default implementation of a database in a system.
Definition: Database.cs:38