MigrationsTests.cs 1.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Coscine.Configuration;
using Coscine.Database.Helpers;
using Coscine.Migrations;
using NUnit.Framework;
using System;

namespace Migrations.Tests
{
    [TestFixture]
    public class MigrationsTests
    {

        private CoscineMigrations _migrator;
        private DatabaseMasterHelper _helper;
        private string _databaseName;

        [OneTimeSetUp]
        public void OneTimeSetUp()
        {
            _databaseName = $"Coscine_Migrations.Tests_{Guid.NewGuid()}";

            _migrator = new CoscineMigrations();
            var settings = new ConfigurationConnectionSettings() { Configuration = new ConsulConfiguration ()};

            settings.LoadSettingsFromConfiguration();
            _migrator.ConnectionSettings = settings;
            _migrator.ConnectionSettings.Database = _databaseName;

            _helper = new DatabaseMasterHelper
            {
                ConnectionSettings = settings
            };

        }

        [OneTimeTearDown]
        public void OneTimeTearDown()
        {
            if (_helper.DatabaseExists(_databaseName))
            {
                _helper.KillConnectionsToDatabase(_databaseName);
                _helper.DropDatabase(_databaseName);
            }
        }

        [Test]
        public void MigrationTest()
        {
            _helper.EnsureDatabase(_databaseName);
            _migrator.MigrateUp();
            _helper.KillConnectionsToDatabase(_databaseName);
            _helper.DropDatabase(_databaseName);
        }
    }
}