Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Services.Authentication Prototype/UnitTests/AbstractHeuristicLabTest.cs @ 4021

Last change on this file since 4021 was 3970, checked in by bfarka, 14 years ago

made Database configable with app.config in the Persistence Project --> 2 different DBs can be configured (one for UnitTesting and a real one) (#1063)

File size: 1.5 KB
Line 
1using Persistence;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using System;
4
5namespace UnitTests {
6  /// <summary>
7  ///This is a abstract test class for all HeuristicLab unit tests
8  ///</summary>
9  public abstract class AbstractHeuristicLabTest {
10
11    /// <summary>
12    /// shared database for all test methods
13    /// </summary>
14    protected Persistence.DataClassesDataContext db;
15
16    /// <summary>
17    /// constructor creates database connection for all other test methods
18    /// </summary>
19    public AbstractHeuristicLabTest() {
20      Persistence.DatabaseUtil.ProductionDatabase = false;
21      db = Persistence.DatabaseUtil.createDataClassesDataContext();
22    }
23
24    /// <summary>
25    /// creates and opens a local database out of the DataClasses and checks connection state
26    /// </summary>
27    [TestInitialize()]
28    public virtual void updateDBConnection() {
29      Assert.IsNotNull(db);
30      DatabaseUtil.createDatabase(db);
31      if (db.Connection.State != System.Data.ConnectionState.Open) {
32        db.Connection.Open();
33      }
34      Assert.AreEqual<System.Data.ConnectionState>(System.Data.ConnectionState.Open, db.Connection.State);
35    }
36
37    /// <summary>
38    /// closes db connection
39    /// </summary>
40    [TestCleanup()]
41    public virtual void closeDBConnection() {
42      if (db.Connection.State == System.Data.ConnectionState.Open) {
43        db.Connection.Close();
44      }
45      Assert.AreEqual<System.Data.ConnectionState>(System.Data.ConnectionState.Closed, db.Connection.State);
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.