DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
CreateTableTests.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 
17 using Deveel.Data.Security;
18 using Deveel.Data.Sql.Tables;
19 using Deveel.Data.Types;
20 
21 using NUnit.Framework;
22 
23 namespace Deveel.Data.Sql {
24  [TestFixture]
26  private const string TestUserName = "test";
27  private const string TestPassword = "abc1234";
28 
29  protected override ISession CreateAdminSession(IDatabase database) {
30  using (var session = database.CreateUserSession(AdminUserName, AdminPassword)) {
31  using (var query = session.CreateQuery()) {
32  if (TestContext.CurrentContext.Test.Name.Equals("CreateSimple_RegularUser")) {
33  var user = query.CreateUser(TestUserName, TestPassword);
34  //queryContext.GrantHostAccessToUser(TestUserName, KnownConnectionProtocols.Local, "%");
35  query.GrantToUserOnSchema("APP", user.Name, Privileges.Create);
36  query.Commit();
37  }
38  }
39  }
40 
41  return base.CreateAdminSession(database);
42  }
43 
44  [Test]
46  var tableName = ObjectName.Parse("APP.test_table");
47  var tableInfo = new TableInfo(tableName);
48  tableInfo.AddColumn("a", PrimitiveTypes.Integer(), true);
49  tableInfo.AddColumn("b", PrimitiveTypes.String());
50 
51  using (var session = CreateUserSession(AdminUserName, AdminPassword)) {
52  using (var query = session.CreateQuery()) {
53  Assert.DoesNotThrow(() => query.CreateTable(tableInfo));
54  Assert.DoesNotThrow(() => query.Commit());
55  }
56  }
57 
58  using (var session = CreateUserSession(AdminUserName, AdminPassword)) {
59  using (var query = session.CreateQuery()) {
60  bool exists = false;
61  Assert.DoesNotThrow(() => exists = query.TableExists(tableName));
62  Assert.IsTrue(exists);
63  }
64  }
65  }
66 
67  [Test]
68  public void CreateSimple_RegularUser() {
69  var tableName = ObjectName.Parse("APP.test_table");
70  var tableInfo = new TableInfo(tableName);
71  tableInfo.AddColumn("a", PrimitiveTypes.Integer(), true);
72  tableInfo.AddColumn("b", PrimitiveTypes.String());
73 
74  using (var session = CreateUserSession(TestUserName, TestPassword)) {
75  using (var query = session.CreateQuery()) {
76  Assert.DoesNotThrow(() => query.CreateTable(tableInfo));
77  }
78  }
79  }
80  }
81 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
void Commit()
Commits the latest changes made by the user in the session.
Describes the name of an object within a database.
Definition: ObjectName.cs:44
The representation of a single database in the system.
Definition: IDatabase.cs:40
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
override ISession CreateAdminSession(IDatabase database)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41