public void ScriptProviderHelper_GetSqlScriptOptions_ShouldSetGroupOrderToValidValue()
        {
            var batch   = new ScriptBatch("", runAlways: true, false, 5, "");
            var options = ScriptProviderHelper.GetSqlScriptOptions(batch);

            options.RunGroupOrder.Should().Be(5);
        }
        public void CalculateBuildPackageSHA1SignatureFromBatchCollectionTest_BatchOrder()
        {
            ScriptBatch batch1 = new ScriptBatch(
                "File1.sql",
                new string[] { "Line one goes here", "Line 2 goes there" },
                Guid.NewGuid().ToString());

            ScriptBatch batch2 = new ScriptBatch(
                "File2.sql",
                new string[] { "My Batch Line one goes here", "Second batch Line 2 goes there" },
                Guid.NewGuid().ToString());


            ScriptBatchCollection scriptBatchColl = new ScriptBatchCollection();

            scriptBatchColl.Add(batch1);
            scriptBatchColl.Add(batch2);

            string order12 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(scriptBatchColl);

            scriptBatchColl = new ScriptBatchCollection();
            scriptBatchColl.Add(batch2);
            scriptBatchColl.Add(batch1);

            string order21 = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(scriptBatchColl);

            Assert.AreNotEqual(order12, order21);
        }
        public ScriptBatchCollection GetScriptBatchCollectionForProcessBuild()
        {
            ScriptBatchCollection sbc = new ScriptBatchCollection();

            string[] scripts = new string[2];
            scripts[0] = "INSERT INTO dbo.TransactionTest VALUES ('PROCESS BUILD1', newid(), getdate())";
            scripts[1] = "INSERT INTO dbo.TransactionTest VALUES ('PROCESS BUILD2', newid(), getdate())";

            string      scriptName = "Transaction Test Insert.sql";
            string      scriptId   = "59F8CBCA-3FE5-4142-ACB0-3D1D2C25184D"; //Must match GUID from AddScriptForProcessBuild()
            ScriptBatch sb         = new ScriptBatch(scriptName, scripts, scriptId);

            sbc.Add(sb);

            string[] scripts2 = new string[2];
            scripts2[0] = "SELECT top 1 * FROM INFORMATION_SCHEMA.tables";
            scripts2[1] = "SELECT top 1 * FROM INFORMATION_SCHEMA.routines";

            scriptName = "Select InfoSchema.sql";
            scriptId   = "8A9CC6E9-D0D3-4525-AAF4-5ACCECEF4D25";

            ScriptBatch sb2 = new ScriptBatch(scriptName, scripts2, scriptId);

            sbc.Add(sb2);

            return(sbc);
        }
        public void ScriptProviderHelper_GetSqlScriptOptions_ShouldSetScriptTypeToRunAlways_IfRunAlwaysIsSetToTrue()
        {
            var batch   = new ScriptBatch("", runAlways: true, false, 1, "");
            var options = ScriptProviderHelper.GetSqlScriptOptions(batch);

            options.ScriptType.Should().Be(Support.ScriptType.RunAlways);
        }
        public void GetScriptBatchTest()
        {
            string scriptfileName = "MyFileName";

            string[]    scriptBatchContents = new string[] { "batch1", "batch2", "batch3" };
            string      scriptId            = System.Guid.NewGuid().ToString();
            ScriptBatch batch1 = new ScriptBatch(scriptfileName, scriptBatchContents, scriptId);

            string scriptfileName2 = "Batch2Name";

            string[]    scriptBatchContents2 = new string[] { "batch4", "batch5", "batch5" };
            string      scriptId2            = System.Guid.NewGuid().ToString();
            ScriptBatch batch2 = new ScriptBatch(scriptfileName2, scriptBatchContents2, scriptId2);

            ScriptBatchCollection target = new ScriptBatchCollection();

            target.Add(batch1);
            target.Add(batch2);

            ScriptBatch actual;

            actual = target.GetScriptBatch(scriptId);
            Assert.AreEqual(batch1, actual);
            actual = target.GetScriptBatch(scriptId2);
            Assert.AreEqual(batch2, actual);
            actual = target.GetScriptBatch("Can'tFindMe");
            Assert.IsNull(actual);
        }
Example #6
0
        public void ConfigurationHelper_GetSqlScriptOptions_ShouldSetScriptTypeToRunOnce_IfRunAlwaysIsSetToFalse()
        {
            var batch   = new ScriptBatch("", runAlways: false, false, 1, "");
            var options = ScriptProviderHelper.GetSqlScriptOptions(batch);

            options.ScriptType.Should().Be(Support.ScriptType.RunOnce);
        }
 protected internal override void Reinitialize()
 {
     base.Reinitialize();
     lastBatch = null;
     Strategy.Reinitialize(this);
     ClearCache();
     uid = Guid.NewGuid().ToString();
 }
        public void ScriptProviderHelper_GetFileSystemScriptOptions_ShouldSetIncludeSubDirectoriesToFalse_IfSubFoldersIsSetToFalse()
        {
            var batch = new ScriptBatch("", true, subFolders: false, 5, Constants.Default.Encoding);

            ScriptProviderHelper.GetFileSystemScriptOptions(batch, NamingOptions.Default).Match(
                some: options => options.IncludeSubDirectories.Should().BeFalse(),
                none: error => Assert.Fail(error.Message)
                );
        }
Example #9
0
        public void ScriptProviderHelper_WhenOptionIsSpecified_ShouldReturnValid_Prefix_Option()
        {
            var batch = new ScriptBatch("", true, subFolders: true, 5, Constants.Default.Encoding);

            var naminOptions = new NamingOptions(false, false, "customprefix");

            ScriptProviderHelper.GetFileSystemScriptOptions(batch, naminOptions).Match(
                some: options => options.Prefix.Should().Be("customprefix"),
                none: error => Assert.Fail(error.Message)
                );
        }
Example #10
0
        public void ScriptProviderHelper_WhenOptionIsSpecified_ShouldReturnValid_PrefixScriptNameWithBaseFolderName_Option()
        {
            var batch = new ScriptBatch("", true, subFolders: true, 5, Constants.Default.Encoding);

            var naminOptions = new NamingOptions(false, includeBaseFolderName: true, null);

            ScriptProviderHelper.GetFileSystemScriptOptions(batch, naminOptions).Match(
                some: options => options.PrefixScriptNameWithBaseFolderName.Should().BeTrue(),
                none: error => Assert.Fail(error.Message)
                );
        }
Example #11
0
        public void ScriptBatchTest_All()
        {
            string scriptfileName = "MyFileName";

            string[]    scriptBatchContents = new string[] { "batch1", "batch2", "batch3" };
            string      scriptId            = System.Guid.NewGuid().ToString();
            ScriptBatch target = new ScriptBatch(scriptfileName, scriptBatchContents, scriptId);

            Assert.AreEqual(scriptfileName, target.ScriptfileName);
            Assert.AreEqual(scriptBatchContents, target.ScriptBatchContents);
            Assert.AreEqual(scriptId, target.ScriptId);

            target.ScriptfileName = "ChangedName";
            string[] newBatch = new string[] { "batch4", "batch5" };
            target.ScriptBatchContents = newBatch;
            string newId = System.Guid.NewGuid().ToString();

            target.ScriptId = newId;
            Assert.AreEqual("ChangedName", target.ScriptfileName);
            Assert.AreEqual(newBatch, target.ScriptBatchContents);
            Assert.AreEqual(newId, target.ScriptId);
        }
        public void CalculateBuildPackageSHA1SignatureFromBatchCollectionTest()
        {
            ScriptBatch batch1 = new ScriptBatch(
                "File1.sql",
                new string[] { "Line one goes here", "Line 2 goes there" },
                Guid.NewGuid().ToString());

            ScriptBatch batch2 = new ScriptBatch(
                "File2.sql",
                new string[] { "My Batch Line one goes here", "Second batch Line 2 goes there" },
                Guid.NewGuid().ToString());


            ScriptBatchCollection scriptBatchColl = new ScriptBatchCollection();

            scriptBatchColl.Add(batch1);
            scriptBatchColl.Add(batch2);
            string expected = "E00B044F80A5F40EDAFC53BE8B559BD4DB5229A0";
            string actual;

            actual = SqlBuildFileHelper.CalculateBuildPackageSHA1SignatureFromBatchCollection(scriptBatchColl);
            Assert.AreEqual(expected, actual);
        }
 protected override ScriptBatch GetNextBatch()
 {
     var indexes = Strategy.GetNextIndexes();
     if (indexes.IsNullOrEmpty())
     {
         if (lastBatch == null)
         {
             throw new InvalidOperationException(Strategy + " has returned null or empty index collection.");
         }
     }
     else
     {
         var cache = ScriptCache.Cache;
         if (cache != null)
         {
             lastBatch = GetNextBatchCached(indexes, cache);
         }
         else
         {
             lastBatch = GetNextBatchUncached(indexes);
         }
     }
     return lastBatch;
 }
Example #14
0
        // Batch:
        protected override double ExecuteBatch(ScriptBatch scriptBatch, double[] resultErrors)
        {
            EnsureScriptRun();

            // Begin of batch:
            isNewBatchState = true;

            // Reset backward values:
            ResetBackwardValues();

            double error = base.ExecuteBatch(scriptBatch, resultErrors);

            // Batch done, iterate algos:
            foreach (var bwa in backwardLearningAlgos) bwa.BackwardIteration(true, error);

            // Batch done. Yeah.
            return error;
        }
Example #15
0
 protected override ScriptBatchExecutionResult BatchExecution(ScriptBatch scriptBatch, Action<ScriptBatchExecutionResult> iterationCallback)
 {
     InitializeNewAlgoRun(AlgoInitializationMode.BatchStart);
     var result = base.BatchExecution(scriptBatch, iterationCallback);
     return result;
 }