DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SingleFileStoreTests.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.IO;
17 
19 
20 using NUnit.Framework;
21 
22 namespace Deveel.Data.Store {
23  [TestFixture]
24  public class SingleFileStoreTests {
27 
28  private const string DatabaseName = "test_db";
29  private const string TestAdminUser = "SA";
30  private const string TestAdminPass = "abc1234";
31 
33  var dbConfig = new Configuration.Configuration();
34  dbConfig.SetValue("database.name", DatabaseName);
35  dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.SingleFile);
36  dbConfig.SetValue("database.basePath", Environment.CurrentDirectory);
37  return dbConfig;
38  }
39 
40  private static string GetDbFileName() {
41  var localPath = Environment.CurrentDirectory;
42  var fileName = String.Format("{0}.db", DatabaseName);
43  return Path.Combine(localPath, fileName);
44  }
45 
46  private void OnSetUp(string testName) {
47  var systemBuilder = new SystemBuilder();
48  systemContext = systemBuilder.BuildSystem();
49 
50  var dbConfig = CreateDatabaseConfig();
51 
52  if (testName != "CreateNewDatabase") {
53  database = systemContext.CreateDatabase(dbConfig, TestAdminUser, TestAdminPass);
54  }
55  }
56 
57  [SetUp]
58  public void SetUp() {
59  var test = TestContext.CurrentContext.Test;
60 
61  OnSetUp(test.Name);
62  }
63 
64  [TearDown]
65  public void TearDown() {
66  if (database != null) {
67  database.Close();
68  database.Dispose();
69  }
70 
71  var fileName = GetDbFileName();
72  if (File.Exists(fileName))
73  File.Delete(fileName);
74  }
75 
76  [Test]
77  public void CreateNewDatabase() {
78  var dbConfig = CreateDatabaseConfig();
79  database = systemContext.CreateDatabase(dbConfig, TestAdminUser, TestAdminPass);
80  }
81  }
82 }
void Close()
Closes the database making it not accessible to connections.
IDatabase CreateDatabase(IConfiguration configuration, string adminUser, string adminPassword)
The representation of a single database in the system.
Definition: IDatabase.cs:40
Defines the contract for the configuration node of a component within the system or of the system its...
Configuration(bool isRoot)
Constructs the Configuration.