Click here to Skip to main content
15,887,746 members
Articles / Programming Languages / XML

DBKeeperNet - Keeps Your DB Schema Up-to-date

Rate me:
Please Sign up or sign in to vote.
4.88/5 (14 votes)
26 Aug 2014BSD4 min read 50.5K   575   89  
An article describing a simple .NET library which simply keeps your database schema up-to-date.
using NUnit.Framework;
using DbKeeperNet.Engine.Extensions.DatabaseServices;

namespace DbKeeperNet.Engine.Tests.Extensions.DatabaseServices
{
    /// <summary>
    /// Tests which requires configured MSSQL database.
    /// As prerequisities may be those table created.
    /// </summary>
    [TestFixture]
    [Explicit]
    [Category("oracle")]
    public class OracleDatabaseServicesLiveTests : DatabaseServiceTests<OracleDatabaseService>
    {
        const string CONNECTION_STRING = "oracle";

        public OracleDatabaseServicesLiveTests() : base(CONNECTION_STRING)
        {
        }

        [SetUp]
        public void Setup()
        {
            Cleanup();

            IUpdateContext context = new UpdateContext();
            context.LoadExtensions();
            context.InitializeDatabaseService(CONNECTION_STRING);

            Updater updater = new Updater(context);
            updater.ExecuteXml(typeof(DbServicesExtension).Assembly.GetManifestResourceStream("DbKeeperNet.Engine.Extensions.DatabaseServices.OracleDatabaseServiceInstall.xml"));
        }

        [TearDown]
        public void Teardown()
        {
            Cleanup();
        }

        [Test]
        public void TestIsUpdateStepExecutedFalse()
        {
            OracleDatabaseService service = new OracleDatabaseService();

            using (IDatabaseService connectedService = service.CloneForConnectionString(CONNECTION_STRING))
            {
                Assert.That(connectedService.IsUpdateStepExecuted("MyTestingAssembly", "x.x99", 222), Is.False);
            }
        }

        [Test]
        public void TestSetUpdateStepExecuted()
        {
            OracleDatabaseService service = new OracleDatabaseService();

            using (IDatabaseService connectedService = service.CloneForConnectionString(CONNECTION_STRING))
            {
                connectedService.SetUpdateStepExecuted("MyTestingAssembly.TestSetUpdateStepExecuted", "1.00", 1);
                Assert.That(connectedService.IsUpdateStepExecuted("MyTestingAssembly.TestSetUpdateStepExecuted", "1.00", 1), Is.True);
            }
        }

        private void Cleanup()
        {
            using (var service = CreateConnectedDbService())
            {
                ExecuteSqlAndIgnoreException(service, @"DROP TRIGGER ""BI_DBKEEPERNET_STEP""");
                ExecuteSqlAndIgnoreException(service, @"DROP TRIGGER ""BI_DBKEEPERNET_VERSION""");
                ExecuteSqlAndIgnoreException(service, @"DROP TRIGGER ""BI_DBKEEPERNET_ASSEMBLY""");

                ExecuteSqlAndIgnoreException(service, @"DROP GENERATOR ""DBKEEPERNET_STEP_SEQ""");
                ExecuteSqlAndIgnoreException(service, @"DROP GENERATOR ""DBKEEPERNET_VERSION_SEQ""");
                ExecuteSqlAndIgnoreException(service, @"DROP GENERATOR ""DBKEEPERNET_ASSEMBLY_SEQ""");


                ExecuteSqlAndIgnoreException(service, @"DROP TABLE ""DBKEEPERNET_STEP""");
                ExecuteSqlAndIgnoreException(service, @"DROP TABLE ""DBKEEPERNET_VERSION""");
                ExecuteSqlAndIgnoreException(service, @"DROP TABLE ""DBKEEPERNET_ASSEMBLY""");
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Team Leader NCR
Czech Republic Czech Republic
I'm software developer since 1996. I started with assembler on Intel 8051 CPUs, during years I was interested in C, C++, Sybase PowerBuilder, PHP, Sybase Anywhere Database, MSSQL server and multiplatform development.

Currently I'm developing in C++ and C# (this is my favorit and I spent some time with MCPD achievement). I'm also interested in design patterns.

Comments and Discussions