NAnt2 / NDbUnit2

A revived .NET library for managing database state during unit testing, with roots in NDbUnit project
Apache License 2.0
1 stars 0 forks source link

Cannot use NDbUnit with schema containing dots #17

Open savornicesei opened 6 years ago

savornicesei commented 6 years ago

Issue by ChristopheL77 Wednesday Jan 06, 2016 at 14:31 GMT Originally opened as https://github.com/NDbUnit/NDbUnit/issues/60


I tried using NDbUnit to test Workflow Foundation 4.

WF4 uses tables with schema [System.Activities.DurableInstancing]

For example, with a table named [System.Activities.DurableInstancing].DefinitionIdentityTable, NDBUnit will fail because it splits table name with dot and then rewrites it like this : [System].[Activities].[DurableInstancing].[DefinitionIdentityTable].

I debugged a little and the method that creates the table name is : TableNameHelper.FormatTableName.

The following code works for SQLServer for tables with a schema and a table name but should be extended to support other DBMS or with tables containing database name :

` Regex quotedExpr = new Regex(@"^((?'ns'[(\w+.)*(\w+)]).)?(([(?'tn'\w+)])|(?'tn'\w+))$");

        Match match = quotedExpr.Match(declaredTableName);
        string nmspace = null;
        string tableName = null;
        if (match != null && match.Success)
        {
            if (match.Groups["ns"].Length != 0)
            {
                nmspace = match.Groups["ns"].Value;
            }

            tableName = match.Groups["tn"].Value;

            StringBuilder result = new StringBuilder();

            if (nmspace != null)
            {
                result.Append(nmspace);
                result.Append(".");
            }
            result.AppendFormat("[{0}]", tableName);
            return result.ToString();
        }

`