示例#1
0
 public RuleTest(IList <Tuple <string, string> > testScripts, TSqlModelOptions databaseOptions, SqlServerVersion sqlVersion)
 {
     this._trash          = new List <TSqlModel>(); //DisposableList();
     this.TestScripts     = testScripts;
     this.DatabaseOptions = databaseOptions ?? new TSqlModelOptions();
     this.SqlVersion      = sqlVersion;
 }
示例#2
0
 public RuleTest(IList <Tuple <string, string> > testScripts, TSqlModelOptions databaseOptions, SqlServerVersion sqlVersion)
 {
     _trash          = new DisposableList();
     TestScripts     = testScripts;
     DatabaseOptions = databaseOptions ?? new TSqlModelOptions();
     SqlVersion      = sqlVersion;
 }
示例#3
0
        /// <summary>
        /// Creates a new filtered model by copying elements from an existing model
        /// </summary>
        public TSqlModel CreateFilteredModel(TSqlModel model)
        {
            // CloneModelOptions copies the database options of the existing model so that it can be used during
            // model creation
            TSqlModelOptions options = model.CloneModelOptions();

            TSqlModel filteredModel = new TSqlModel(model.Version, options);

            // A call to GetObjects with no ModelTypeClasses specified returns all top-level objects.
            // These are objects such as Tables, Views, Indexes - anything that can be defined by itself in TSQL.
            // Examples of non-top level objects are Columns.
            IEnumerable <TSqlObject> allObjects = model.GetObjects(QueryScopes);

            // Filter the objects and copy them to the new model.
            // Note that some objects such as DatabaseOptions, and any inlined constraints, will
            // not support being scripted out. DatabaseOptions don't get a TSQL representation (hence the clone method),
            // and inline constraints get scripted out with table/view definitions so to avoid duplication errors they
            // can't be scripted
            IFilter allFilters = new CompositeFilter(_filters);

            foreach (TSqlObject tsqlObject in allFilters.Filter(allObjects))
            {
                string script;
                if (tsqlObject.TryGetScript(out script))
                {
                    // Some objects such as the DatabaseOptions can't be scripted out.
                    filteredModel.AddObjects(script);
                }
            }

            return(filteredModel);
        }
示例#4
0
 public DacCreator(string dacpacPath, List <Reference> references, SqlServerVersion version, TSqlModelOptions sqlModelOptions, string preDeploy, string postDeploy)
 {
     _outputPath       = dacpacPath;
     _references       = references;
     _version          = version;
     _options          = sqlModelOptions;
     _preDeployScript  = preDeploy;
     _postDeployScript = postDeploy;
 }
示例#5
0
 public DacCreator(Args args)
 {
     _outputPath = args.DacpacPath;
     _sourceFolder = args.SourcePath;
     _references = args.References;
     _version = args.SqlServerVersion;
     _options = args.SqlModelOptions;
     _preDeployScript = args.PreCompareScript;
     _postDeployScript = args.PostCompareScript;
     if(args.FixDeployScripts)
         ScriptFixer = new DdlScriptParser(_version);
 }
示例#6
0
 public DacCreator(Args args)
 {
     _outputPath       = args.DacpacPath;
     _sourceFolder     = args.SourcePath;
     _references       = args.References;
     _version          = args.SqlServerVersion;
     _options          = args.SqlModelOptions;
     _preDeployScript  = args.PreCompareScript;
     _postDeployScript = args.PostCompareScript;
     if (args.FixDeployScripts)
     {
         ScriptFixer = new DdlScriptParser(_version);
     }
 }
        /// <summary>
        /// Creates a new baselined test. The input files and baseline file will be loaded from 
        /// the 
        /// </summary>
        public BaselinedRuleTest(
            TestContext testContext, 
            string testName, 
            TSqlModelOptions databaseOptions,
            SqlServerVersion sqlVersion)
            : base(new List<Tuple<string, string>>(), databaseOptions, sqlVersion)
        {
            ScriptsFolder = GetScriptsFolder(testName);
            Assert.IsTrue(Directory.Exists(ScriptsFolder), "Expected the test folder '{0}' to exist", ScriptsFolder);

            string outputDir = testContext.TestResultsDirectory;
            string outputFilename = String.Format("{0}-{1}.txt", testName, Output);
            OutputFilePath = Path.Combine(outputDir, testName, outputFilename);

            string baselineFilename = String.Format("{0}-{1}.txt", testName, Baseline);
            BaselineFilePath = Path.Combine(ScriptsFolder, baselineFilename);
        }
示例#8
0
        /// <summary>
        /// Creates a new baselined test. The input files and baseline file will be loaded from
        /// the
        /// </summary>
        public BaselinedRuleTest(
            TestContext testContext,
            string testName,
            TSqlModelOptions databaseOptions,
            SqlServerVersion sqlVersion)
            : base(new List <Tuple <string, string> >(), databaseOptions, sqlVersion)
        {
            ScriptsFolder = GetScriptsFolder(testName);
            Assert.IsTrue(Directory.Exists(ScriptsFolder), "Expected the test folder '{0}' to exist", ScriptsFolder);

            string outputDir      = testContext.TestResultsDirectory;
            string outputFilename = String.Format("{0}-{1}.txt", testName, Output);

            OutputFilePath = Path.Combine(outputDir, testName, outputFilename);

            string baselineFilename = String.Format("{0}-{1}.txt", testName, Baseline);

            BaselineFilePath = Path.Combine(ScriptsFolder, baselineFilename);
        }
        public BaselineSetup(TestContext testContext, string testName, TSqlModelOptions databaseOptions, SqlServerVersion sqlServerVersion = SqlServerVersion.Sql150)
            : base(new List <Tuple <string, string> >(), databaseOptions, sqlServerVersion)
        {
            var folder = Path.Combine(GetBaseFolder(), TestScriptsFolder);

            ScriptsFolder = Directory.EnumerateDirectories(folder, testName, SearchOption.AllDirectories).FirstOrDefault();
            Assert.IsTrue(Directory.Exists(ScriptsFolder), $"Expected the test folder '{ScriptsFolder}' to exist");

            SetupFolder = Path.Combine(GetBaseFolder(), TestScriptsFolder, SetupScriptsFolder);

            string outputDir      = testContext.TestResultsDirectory;
            string outputFilename = $"{testName}-{Output}.txt";

            OutputFilePath = Path.Combine(outputDir, testName, outputFilename);

            string baselineFilename = $"{testName}-{Baseline}.txt";

            BaselineFilePath = Path.Combine(ScriptsFolder, baselineFilename);
        }
示例#10
0
        public ParseResult Parse()
        {
            SqlModelOptions  = new TSqlModelOptions();
            References       = new List <Reference>();
            SourcePath       = new List <Source>();
            FixDeployScripts = false;

            foreach (var argUpper in _args)
            {
                var arg = argUpper.ToLower();

                if (arg.StartsWith("/fixddlscripts") || arg.StartsWith("/fix"))
                {
                    FixDeployScripts = true;
                }

                if (arg.StartsWith("/sp=") || arg.StartsWith("/sourcepath="))
                {
                    ReadSourcePath(argUpper);
                    continue;
                }

                if (arg.StartsWith("/pre=") || arg.StartsWith("/precompare="))
                {
                    ReadPreComparePath(arg);
                    continue;
                }

                if (arg.StartsWith("/post=") || arg.StartsWith("/postcompare="))
                {
                    ReadPostComparePath(arg);
                    continue;
                }

                if (arg.StartsWith("/dp=") || arg.StartsWith("/dacpacpath="))
                {
                    ReadDacpacPath(arg);
                    continue;
                }

                if (arg.StartsWith("/sv=") || arg.StartsWith("/sqlversion="))
                {
                    if (!ReadSqlVersion(arg))
                    {
                        return(ParseResult.Error);
                    }

                    continue;
                }

                if (arg.StartsWith("/do=") || arg.StartsWith("/databaseoption="))
                {
                    if (!ReadDatabaseOption(arg, argUpper))
                    {
                        return(ParseResult.Error);
                    }

                    continue;
                }

                if (arg.StartsWith("/r=") || arg.StartsWith("/ref="))
                {
                    if (!ReadReference(arg, argUpper))
                    {
                        return(ParseResult.Error);
                    }

                    continue;
                }

                if (arg.StartsWith("/?"))
                {
                    PrintArgs();
                    return(ParseResult.OkShowError);
                }
            }

            return(ParseResult.Ok);
        }
示例#11
0
 public TSqlTypedModel(SqlServerVersion modelTargetVersion, TSqlModelOptions modelCreationOptions)
 {
     model = new TSqlModel(modelTargetVersion, modelCreationOptions);
 }
        /// <summary>
        /// Copies the <see cref="DatabaseOptions"/> for the model to a <see cref="TSqlModelOptions"/> object.
        /// This is useful if you wish to duplicate the options for a model when creating a new model.
        /// Note that this method may be included in the public model framework in the future.
        /// </summary>
        public static TSqlModelOptions CloneModelOptions(this TSqlModel model)
        {
            TSqlModelOptions clonedOptions = new TSqlModelOptions();
            TSqlObject       options       = model.GetObjects(DacQueryScopes.All, DatabaseOptions.TypeClass).FirstOrDefault();

            if (options == null)
            {
                return(clonedOptions);
            }

            clonedOptions.Collation = options.GetProperty <string>(DatabaseOptions.Collation);
            clonedOptions.AllowSnapshotIsolation = options.GetProperty <bool>(DatabaseOptions.AllowSnapshotIsolation);
            clonedOptions.TransactionIsolationReadCommittedSnapshot = options.GetProperty <bool>(DatabaseOptions.TransactionIsolationReadCommittedSnapshot);
            clonedOptions.AnsiNullDefaultOn             = options.GetProperty <bool>(DatabaseOptions.AnsiNullDefaultOn);
            clonedOptions.AnsiNullsOn                   = options.GetProperty <bool>(DatabaseOptions.AnsiNullsOn);
            clonedOptions.AnsiPaddingOn                 = options.GetProperty <bool>(DatabaseOptions.AnsiPaddingOn);
            clonedOptions.AnsiWarningsOn                = options.GetProperty <bool>(DatabaseOptions.AnsiWarningsOn);
            clonedOptions.ArithAbortOn                  = options.GetProperty <bool>(DatabaseOptions.ArithAbortOn);
            clonedOptions.AutoClose                     = options.GetProperty <bool>(DatabaseOptions.AutoClose);
            clonedOptions.AutoCreateStatistics          = options.GetProperty <bool>(DatabaseOptions.AutoCreateStatistics);
            clonedOptions.AutoShrink                    = options.GetProperty <bool>(DatabaseOptions.AutoShrink);
            clonedOptions.AutoUpdateStatistics          = options.GetProperty <bool>(DatabaseOptions.AutoUpdateStatistics);
            clonedOptions.AutoUpdateStatisticsAsync     = options.GetProperty <bool>(DatabaseOptions.AutoUpdateStatisticsAsync);
            clonedOptions.ChangeTrackingAutoCleanup     = options.GetProperty <bool>(DatabaseOptions.ChangeTrackingAutoCleanup);
            clonedOptions.ChangeTrackingEnabled         = options.GetProperty <bool>(DatabaseOptions.ChangeTrackingEnabled);
            clonedOptions.ChangeTrackingRetentionPeriod = options.GetProperty <int>(DatabaseOptions.ChangeTrackingRetentionPeriod);
            clonedOptions.ChangeTrackingRetentionUnit   = options.GetProperty <TimeUnit>(DatabaseOptions.ChangeTrackingRetentionUnit);
            clonedOptions.CompatibilityLevel            = options.GetProperty <int>(DatabaseOptions.CompatibilityLevel);
            clonedOptions.ConcatNullYieldsNull          = options.GetProperty <bool>(DatabaseOptions.ConcatNullYieldsNull);
            clonedOptions.Containment                   = options.GetProperty <Containment>(DatabaseOptions.Containment);
            clonedOptions.CursorCloseOnCommit           = options.GetProperty <bool>(DatabaseOptions.CursorCloseOnCommit);
            clonedOptions.CursorDefaultGlobalScope      = options.GetProperty <bool>(DatabaseOptions.CursorDefaultGlobalScope);
            clonedOptions.DatabaseStateOffline          = options.GetProperty <bool>(DatabaseOptions.DatabaseStateOffline);
            clonedOptions.DateCorrelationOptimizationOn = options.GetProperty <bool>(DatabaseOptions.DateCorrelationOptimizationOn);
            clonedOptions.DefaultFullTextLanguage       = options.GetProperty <string>(DatabaseOptions.DefaultFullTextLanguage);
            clonedOptions.DefaultLanguage               = options.GetProperty <string>(DatabaseOptions.DefaultLanguage);
            clonedOptions.DBChainingOn                  = options.GetProperty <bool>(DatabaseOptions.DBChainingOn);
            clonedOptions.FileStreamDirectoryName       = options.GetProperty <string>(DatabaseOptions.FileStreamDirectoryName);
            clonedOptions.FullTextEnabled               = options.GetProperty <bool>(DatabaseOptions.FullTextEnabled);
            clonedOptions.HonorBrokerPriority           = options.GetProperty <bool>(DatabaseOptions.HonorBrokerPriority);
            clonedOptions.NestedTriggersOn              = options.GetProperty <bool>(DatabaseOptions.NestedTriggersOn);
            clonedOptions.NonTransactedFileStreamAccess = options.GetProperty <NonTransactedFileStreamAccess>(DatabaseOptions.NonTransactedFileStreamAccess);
            clonedOptions.NumericRoundAbortOn           = options.GetProperty <bool>(DatabaseOptions.NumericRoundAbortOn);
            clonedOptions.PageVerifyMode                = options.GetProperty <PageVerifyMode>(DatabaseOptions.PageVerifyMode);
            clonedOptions.ParameterizationOption        = options.GetProperty <ParameterizationOption>(DatabaseOptions.ParameterizationOption);
            clonedOptions.QuotedIdentifierOn            = options.GetProperty <bool>(DatabaseOptions.QuotedIdentifierOn);
            clonedOptions.ReadOnly                  = options.GetProperty <bool>(DatabaseOptions.ReadOnly);
            clonedOptions.RecoveryMode              = options.GetProperty <RecoveryMode>(DatabaseOptions.RecoveryMode);
            clonedOptions.RecursiveTriggersOn       = options.GetProperty <bool>(DatabaseOptions.RecursiveTriggersOn);
            clonedOptions.ServiceBrokerOption       = options.GetProperty <ServiceBrokerOption>(DatabaseOptions.ServiceBrokerOption);
            clonedOptions.SupplementalLoggingOn     = options.GetProperty <bool>(DatabaseOptions.SupplementalLoggingOn);
            clonedOptions.TargetRecoveryTimePeriod  = options.GetProperty <int>(DatabaseOptions.TargetRecoveryTimePeriod);
            clonedOptions.TargetRecoveryTimeUnit    = options.GetProperty <TimeUnit>(DatabaseOptions.TargetRecoveryTimeUnit);
            clonedOptions.TornPageProtectionOn      = options.GetProperty <bool>(DatabaseOptions.TornPageProtectionOn);
            clonedOptions.TransformNoiseWords       = options.GetProperty <bool>(DatabaseOptions.TransformNoiseWords);
            clonedOptions.Trustworthy               = options.GetProperty <bool>(DatabaseOptions.Trustworthy);
            clonedOptions.TwoDigitYearCutoff        = options.GetProperty <short>(DatabaseOptions.TwoDigitYearCutoff);
            clonedOptions.VardecimalStorageFormatOn = options.GetProperty <bool>(DatabaseOptions.VardecimalStorageFormatOn);
            clonedOptions.UserAccessOption          = options.GetProperty <UserAccessOption>(DatabaseOptions.UserAccessOption);
            clonedOptions.WithEncryption            = options.GetProperty <bool>(DatabaseOptions.WithEncryption);

            return(clonedOptions);
        }
        /// <summary>
        /// Copies the <see cref="DatabaseOptions"/> for the model to a <see cref="TSqlModelOptions"/> object.
        /// This is useful if you wish to duplicate the options for a model when creating a new model.
        /// Note that this method may be included in the public model framework in the future.
        /// </summary>
        public static TSqlModelOptions CloneModelOptions(this TSqlModel model)
        {
            TSqlModelOptions clonedOptions = new TSqlModelOptions();
            TSqlObject options = model.GetObjects(DacQueryScopes.All, DatabaseOptions.TypeClass).FirstOrDefault();
            if (options == null)
            {
                return clonedOptions;
            }

            clonedOptions.Collation = options.GetProperty<string>(DatabaseOptions.Collation);
            clonedOptions.AllowSnapshotIsolation = options.GetProperty<bool>(DatabaseOptions.AllowSnapshotIsolation);
            clonedOptions.TransactionIsolationReadCommittedSnapshot = options.GetProperty<bool>(DatabaseOptions.TransactionIsolationReadCommittedSnapshot);
            clonedOptions.AnsiNullDefaultOn = options.GetProperty<bool>(DatabaseOptions.AnsiNullDefaultOn);
            clonedOptions.AnsiNullsOn = options.GetProperty<bool>(DatabaseOptions.AnsiNullsOn);
            clonedOptions.AnsiPaddingOn = options.GetProperty<bool>(DatabaseOptions.AnsiPaddingOn);
            clonedOptions.AnsiWarningsOn = options.GetProperty<bool>(DatabaseOptions.AnsiWarningsOn);
            clonedOptions.ArithAbortOn = options.GetProperty<bool>(DatabaseOptions.ArithAbortOn);
            clonedOptions.AutoClose = options.GetProperty<bool>(DatabaseOptions.AutoClose);
            clonedOptions.AutoCreateStatistics = options.GetProperty<bool>(DatabaseOptions.AutoCreateStatistics);
            clonedOptions.AutoShrink = options.GetProperty<bool>(DatabaseOptions.AutoShrink);
            clonedOptions.AutoUpdateStatistics = options.GetProperty<bool>(DatabaseOptions.AutoUpdateStatistics);
            clonedOptions.AutoUpdateStatisticsAsync = options.GetProperty<bool>(DatabaseOptions.AutoUpdateStatisticsAsync);
            clonedOptions.ChangeTrackingAutoCleanup = options.GetProperty<bool>(DatabaseOptions.ChangeTrackingAutoCleanup);
            clonedOptions.ChangeTrackingEnabled = options.GetProperty<bool>(DatabaseOptions.ChangeTrackingEnabled);
            clonedOptions.ChangeTrackingRetentionPeriod = options.GetProperty<int>(DatabaseOptions.ChangeTrackingRetentionPeriod);
            clonedOptions.ChangeTrackingRetentionUnit = options.GetProperty<TimeUnit>(DatabaseOptions.ChangeTrackingRetentionUnit);
            clonedOptions.CompatibilityLevel = options.GetProperty<int>(DatabaseOptions.CompatibilityLevel);
            clonedOptions.ConcatNullYieldsNull = options.GetProperty<bool>(DatabaseOptions.ConcatNullYieldsNull);
            clonedOptions.Containment = options.GetProperty<Containment>(DatabaseOptions.Containment);
            clonedOptions.CursorCloseOnCommit = options.GetProperty<bool>(DatabaseOptions.CursorCloseOnCommit);
            clonedOptions.CursorDefaultGlobalScope = options.GetProperty<bool>(DatabaseOptions.CursorDefaultGlobalScope);
            clonedOptions.DatabaseStateOffline = options.GetProperty<bool>(DatabaseOptions.DatabaseStateOffline);
            clonedOptions.DateCorrelationOptimizationOn = options.GetProperty<bool>(DatabaseOptions.DateCorrelationOptimizationOn);
            clonedOptions.DefaultFullTextLanguage = options.GetProperty<string>(DatabaseOptions.DefaultFullTextLanguage);
            clonedOptions.DefaultLanguage = options.GetProperty<string>(DatabaseOptions.DefaultLanguage);
            clonedOptions.DBChainingOn = options.GetProperty<bool>(DatabaseOptions.DBChainingOn);
            clonedOptions.FileStreamDirectoryName = options.GetProperty<string>(DatabaseOptions.FileStreamDirectoryName);
            clonedOptions.FullTextEnabled = options.GetProperty<bool>(DatabaseOptions.FullTextEnabled);
            clonedOptions.HonorBrokerPriority = options.GetProperty<bool>(DatabaseOptions.HonorBrokerPriority);
            clonedOptions.NestedTriggersOn = options.GetProperty<bool>(DatabaseOptions.NestedTriggersOn);
            clonedOptions.NonTransactedFileStreamAccess = options.GetProperty<NonTransactedFileStreamAccess>(DatabaseOptions.NonTransactedFileStreamAccess);
            clonedOptions.NumericRoundAbortOn = options.GetProperty<bool>(DatabaseOptions.NumericRoundAbortOn);
            clonedOptions.PageVerifyMode = options.GetProperty<PageVerifyMode>(DatabaseOptions.PageVerifyMode);
            clonedOptions.ParameterizationOption = options.GetProperty<ParameterizationOption>(DatabaseOptions.ParameterizationOption);
            clonedOptions.QuotedIdentifierOn = options.GetProperty<bool>(DatabaseOptions.QuotedIdentifierOn);
            clonedOptions.ReadOnly = options.GetProperty<bool>(DatabaseOptions.ReadOnly);
            clonedOptions.RecoveryMode = options.GetProperty<RecoveryMode>(DatabaseOptions.RecoveryMode);
            clonedOptions.RecursiveTriggersOn = options.GetProperty<bool>(DatabaseOptions.RecursiveTriggersOn);
            clonedOptions.ServiceBrokerOption = options.GetProperty<ServiceBrokerOption>(DatabaseOptions.ServiceBrokerOption);
            clonedOptions.SupplementalLoggingOn = options.GetProperty<bool>(DatabaseOptions.SupplementalLoggingOn);
            clonedOptions.TargetRecoveryTimePeriod = options.GetProperty<int>(DatabaseOptions.TargetRecoveryTimePeriod);
            clonedOptions.TargetRecoveryTimeUnit = options.GetProperty<TimeUnit>(DatabaseOptions.TargetRecoveryTimeUnit);
            clonedOptions.TornPageProtectionOn = options.GetProperty<bool>(DatabaseOptions.TornPageProtectionOn);
            clonedOptions.TransformNoiseWords = options.GetProperty<bool>(DatabaseOptions.TransformNoiseWords);
            clonedOptions.Trustworthy = options.GetProperty<bool>(DatabaseOptions.Trustworthy);
            clonedOptions.TwoDigitYearCutoff = options.GetProperty<short>(DatabaseOptions.TwoDigitYearCutoff);
            clonedOptions.VardecimalStorageFormatOn = options.GetProperty<bool>(DatabaseOptions.VardecimalStorageFormatOn);
            clonedOptions.UserAccessOption = options.GetProperty<UserAccessOption>(DatabaseOptions.UserAccessOption);
            clonedOptions.WithEncryption = options.GetProperty<bool>(DatabaseOptions.WithEncryption);

            return clonedOptions;
        }