public void TestEncryptedPasswordHostArgumentType()
        {
            LoadMetadata        lmd = null;
            ProcessTaskArgument pta = null;

            try
            {
                pta = CreateNewProcessTaskArgumentInDatabase(out lmd);
                pta.SetType(typeof(EncryptedString));
                pta.SetValue(new EncryptedString(CatalogueRepository)
                {
                    Value = "test123"
                });
                pta.SaveToDatabase();

                var loadedPta = CatalogueRepository.GetObjectByID <ProcessTaskArgument>(pta.ID);
                var value     = loadedPta.GetValueAsSystemType() as EncryptedString;
                Assert.NotNull(value);
                Assert.AreEqual("test123", value.GetDecryptedValue());
            }
            finally
            {
                if (pta != null)
                {
                    var processTask = CatalogueRepository.GetObjectByID <ProcessTask>(pta.ProcessTask_ID);
                    processTask.DeleteInDatabase();
                }

                if (lmd != null)
                {
                    lmd.DeleteInDatabase();
                }
            }
        }
        public void TypeOfPreLoadDiscardedColumn()
        {
            string methodName    = new StackTrace().GetFrame(0).GetMethod().Name;
            string tableInfoName = "TableInfoFor_" + methodName;
            string preLoadDiscardedColumnName = "PreLoadDiscardedColumnFor_" + methodName;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));
            PreLoadDiscardedColumn toCleanupCol = CatalogueRepository.GetAllObjects <PreLoadDiscardedColumn>()
                                                  .SingleOrDefault(c => c.RuntimeColumnName.Equals(preLoadDiscardedColumnName));

            //must delete pre load discarded first
            if (toCleanupCol != null)
            {
                toCleanupCol.DeleteInDatabase();
            }

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var lmd = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt  = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustStaging);
                var pta = new ProcessTaskArgument(CatalogueRepository, pt);

                pta.SetType(typeof(PreLoadDiscardedColumn));

                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);

                PreLoadDiscardedColumn preloadDiscardedColumn = new PreLoadDiscardedColumn(CatalogueRepository, tableInfo, preLoadDiscardedColumnName);
                try
                {
                    pta.SetValue(preloadDiscardedColumn);
                    pta.SaveToDatabase();

                    var newInstanceOfPTA = CatalogueRepository.GetObjectByID <ProcessTaskArgument>(pta.ID);
                    Assert.AreEqual(newInstanceOfPTA.Value, pta.Value);

                    PreLoadDiscardedColumn p1 = (PreLoadDiscardedColumn)pta.GetValueAsSystemType();
                    PreLoadDiscardedColumn p2 = (PreLoadDiscardedColumn)newInstanceOfPTA.GetValueAsSystemType();

                    Assert.AreEqual(p1.ID, p2.ID);
                }
                finally
                {
                    preloadDiscardedColumn.DeleteInDatabase();
                    tableInfo.DeleteInDatabase();
                }
            }
            finally
            {
                lmd.DeleteInDatabase();
            }
        }
        public void TypeOfTableInfo(bool declareAsInterface)
        {
            string tableInfoName = "TableInfoFor_" + new StackTrace().GetFrame(0).GetMethod().Name;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var loadMetadata = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt  = new ProcessTask(CatalogueRepository, loadMetadata, LoadStage.AdjustStaging);
                var pta = new ProcessTaskArgument(CatalogueRepository, pt);

                if (declareAsInterface)
                {
                    pta.SetType(typeof(ITableInfo));
                }
                else
                {
                    pta.SetType(typeof(TableInfo));
                }

                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);
                try
                {
                    pta.SetValue(tableInfo);
                    pta.SaveToDatabase();

                    var newInstanceOfPTA = CatalogueRepository.GetObjectByID <ProcessTaskArgument>(pta.ID);

                    Assert.AreEqual(newInstanceOfPTA.Value, pta.Value);

                    TableInfo t1 = (TableInfo)pta.GetValueAsSystemType();
                    TableInfo t2 = (TableInfo)newInstanceOfPTA.GetValueAsSystemType();

                    Assert.AreEqual(t1.ID, t2.ID);
                }
                finally
                {
                    tableInfo.DeleteInDatabase();
                }
            }
            finally
            {
                loadMetadata.DeleteInDatabase();
            }
        }
        public void MEFCompatibleType_Passes()
        {
            var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "DelMeProjDir", true);

            try
            {
                _lmd.LocationOfFlatFiles = projDir.RootPath.FullName;
                _task.ProcessTaskType    = ProcessTaskType.Attacher;
                _task.LoadStage          = LoadStage.Mounting;
                _task.Path = typeof(AnySeparatorFileAttacher).FullName;
                _task.SaveToDatabase();

                //create the arguments
                var args = ProcessTaskArgument.CreateArgumentsForClassIfNotExists <AnySeparatorFileAttacher>(_task);

                var tblName = (ProcessTaskArgument)args.Single(a => a.Name.Equals("TableName"));
                tblName.Value = "MyExcitingTable";
                tblName.SaveToDatabase();

                var filePattern = (ProcessTaskArgument)args.Single(a => a.Name.Equals("FilePattern"));
                filePattern.Value = "*.csv";
                filePattern.SaveToDatabase();

                var separator = (ProcessTaskArgument)args.Single(a => a.Name.Equals("Separator"));
                separator.Value = ",";
                separator.SaveToDatabase();

                var results = new ToMemoryCheckNotifier();
                _checker.Check(results);

                foreach (var msg in results.Messages)
                {
                    Console.WriteLine("(" + msg.Result + ")" + msg.Message);

                    if (msg.Ex != null)
                    {
                        Console.WriteLine(ExceptionHelper.ExceptionToListOfInnerMessages(msg.Ex));
                    }
                }

                Assert.AreEqual(CheckResult.Success, results.GetWorst());
            }
            finally
            {
                //delete everything for real
                projDir.RootPath.Delete(true);
            }
        }
Exemple #5
0
            private void SetupLoadProcessTasks(ICatalogueRepository catalogueRepository)
            {
                var attacherTask = new ProcessTask(catalogueRepository, LoadMetadata, LoadStage.Mounting)
                {
                    Name            = "Attach CSV file",
                    Order           = 1,
                    Path            = "Rdmp.Core.DataLoad.Modules.Attachers.AnySeparatorFileAttacher",
                    ProcessTaskType = ProcessTaskType.Attacher
                };

                attacherTask.SaveToDatabase();

                // Not assigned to a variable as they will be magically available through the repository
                var processTaskArgs = new List <Tuple <string, string, Type> >
                {
                    new Tuple <string, string, Type>("FilePattern", "1.csv", typeof(string)),
                    new Tuple <string, string, Type>("TableName", "TestData", typeof(string)),
                    new Tuple <string, string, Type>("ForceHeaders", null, typeof(string)),
                    new Tuple <string, string, Type>("IgnoreQuotes", null, typeof(bool)),
                    new Tuple <string, string, Type>("IgnoreBlankLines", null, typeof(bool)),
                    new Tuple <string, string, Type>("ForceHeadersReplacesFirstLineInFile", null, typeof(bool)),
                    new Tuple <string, string, Type>("SendLoadNotRequiredIfFileNotFound", "false", typeof(bool)),
                    new Tuple <string, string, Type>("Separator", ",", typeof(string)),
                    new Tuple <string, string, Type>("TableToLoad", null, typeof(TableInfo)),
                    new Tuple <string, string, Type>("BadDataHandlingStrategy", BadDataHandlingStrategy.ThrowException.ToString(), typeof(BadDataHandlingStrategy)),
                    new Tuple <string, string, Type>("ThrowOnEmptyFiles", "true", typeof(bool)),
                    new Tuple <string, string, Type>("AttemptToResolveNewLinesInRecords", "true", typeof(bool)),
                    new Tuple <string, string, Type>("MaximumErrorsToReport", "0", typeof(int)),
                    new Tuple <string, string, Type>("IgnoreColumns", null, typeof(string)),
                    new Tuple <string, string, Type>("IgnoreBadReads", "false", typeof(bool)),
                    new Tuple <string, string, Type>("AddFilenameColumnNamed", null, typeof(string)),
                };


                foreach (var tuple in processTaskArgs)
                {
                    var pta = new ProcessTaskArgument(catalogueRepository, attacherTask)
                    {
                        Name  = tuple.Item1,
                        Value = tuple.Item2
                    };
                    pta.SetType(tuple.Item3);
                    pta.SaveToDatabase();
                }
            }
        public void TableInfoType_FetchAfterDelete_ReturnsNull()
        {
            string tableInfoName = "TableInfoFor_" + new StackTrace().GetFrame(0).GetMethod().Name;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var lmd = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt  = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustStaging);
                var pta = new ProcessTaskArgument(CatalogueRepository, pt);

                //Prepare to receive a TableInfo object
                pta.SetType(typeof(TableInfo));

                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);

                //Heres the TableInfo object
                pta.SetValue(tableInfo);
                pta.SaveToDatabase();

                //Lolz I just deleted it out of the database
                tableInfo.DeleteInDatabase();

                //give the object back now please? - returns null because it's gone (new behaviour)
                Assert.IsNull(pta.GetValueAsSystemType());

                //old behaviour

                /*var ex = Assert.Throws<KeyNotFoundException>(()=>pta.GetValueAsSystemType());
                 * StringAssert.Contains("Could not find TableInfo with ID",ex.Message);*/
            }
            finally
            {
                lmd.DeleteInDatabase();
            }
        }
        public void TestConstructionFromProcessTaskUsingDatabase()
        {
            const string expectedPath = @"\\a\fake\path.exe";

            var loadMetadata = new LoadMetadata(CatalogueRepository);
            var processTask  = new ProcessTask(CatalogueRepository, loadMetadata, LoadStage.Mounting)
            {
                Name = "Test process task",
                Path = expectedPath
            };

            processTask.SaveToDatabase();

            var argument = new ProcessTaskArgument(CatalogueRepository, processTask)
            {
                Name  = "DatabaseName",
                Value = @"Foo_STAGING"
            };

            argument.SaveToDatabase();

            try
            {
                var args =
                    new RuntimeArgumentCollection(processTask.ProcessTaskArguments.Cast <IArgument>().ToArray(), null);

                var runtimeTask = new ExecutableRuntimeTask(processTask, args);
                Assert.AreEqual(expectedPath, runtimeTask.ExeFilepath);

                Assert.AreEqual(1, runtimeTask.RuntimeArguments.GetAllArgumentsOfType <string>().Count());

                var dictionaryOfStringArguments = runtimeTask.RuntimeArguments.GetAllArgumentsOfType <string>().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                Assert.IsNotNull(dictionaryOfStringArguments["DatabaseName"]);
                Assert.AreEqual("Foo_STAGING", dictionaryOfStringArguments["DatabaseName"]);
            }
            finally
            {
                loadMetadata.DeleteInDatabase();
            }
        }
        public void LieToProcessTaskArgumentAboutWhatTypeIs_Throws()
        {
            string tableInfoName = "TableInfoFor_" + new StackTrace().GetFrame(0).GetMethod().Name;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var lmd = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt        = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustStaging);
                var pta       = new ProcessTaskArgument(CatalogueRepository, pt);
                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);
                try
                {
                    //tell it that we are going to give it a PreLoadDiscardedColumn
                    pta.SetType(typeof(PreLoadDiscardedColumn));
                    //then surprise! heres a TableInfo!
                    var ex = Assert.Throws <Exception>(() => pta.SetValue(tableInfo));
                    StringAssert.Contains("has an incompatible Type specified (Rdmp.Core.Curation.Data.DataLoad.PreLoadDiscardedColumn)", ex.Message);
                }
                finally
                {
                    tableInfo.DeleteInDatabase();
                }
            }
            finally
            {
                lmd.DeleteInDatabase();
            }
        }
Exemple #9
0
        public void CloneProcessTask_ToNewLoadMetadataWithArguments()
        {
            //setup parents
            LoadMetadata parent1 = new LoadMetadata(CatalogueRepository);
            LoadMetadata parent2 = new LoadMetadata(CatalogueRepository);

            //make sure we didn't magically create the same ID somehow
            Assert.AreNotEqual(parent1.ID, parent2.ID);

            //setup things to clone in parent1
            ProcessTask         processTask1 = new ProcessTask(CatalogueRepository, parent1, LoadStage.AdjustRaw);
            ProcessTaskArgument arg          = new ProcessTaskArgument(CatalogueRepository, processTask1);

            arg.Name = "TestArg";
            arg.SetType(typeof(System.String));
            arg.SetValue("TestValue");
            arg.SaveToDatabase();

            processTask1.Name  = "Franky";
            processTask1.Order = 999;
            processTask1.SaveToDatabase();

            try
            {
                //clone to parent 2
                var clone = processTask1.CloneToNewLoadMetadataStage(parent2, LoadStage.GetFiles);
                Assert.AreNotSame(clone.ID, processTask1.ID);
                Assert.IsFalse(clone.ID == processTask1.ID);

                //////////////////////////////////////////////////////////////////CHECK CLONAGE OF PROCESS TASK ////////////////////////////////////////////////////////////
                //get fresh copy out of database to ensure it is still there
                ProcessTask orig = CatalogueRepository.GetObjectByID <ProcessTask>(processTask1.ID);
                clone = CatalogueRepository.GetObjectByID <ProcessTask>(clone.ID);

                //ids must have changed
                Assert.IsFalse(orig.ID == clone.ID);

                //load stages must be correct per what we requested
                Assert.AreEqual(LoadStage.AdjustRaw, orig.LoadStage);
                Assert.AreEqual(LoadStage.GetFiles, clone.LoadStage);

                //all regular values must have been cloned successfully
                Assert.AreEqual(orig.Order, clone.Order);
                Assert.AreEqual(orig.Path, clone.Path);
                Assert.AreEqual(orig.ProcessTaskType, clone.ProcessTaskType);

                Assert.AreEqual(parent1.ID, orig.LoadMetadata_ID);
                Assert.AreEqual(parent2.ID, clone.LoadMetadata_ID);
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                //////////////////////////////////////////////////////////////////CHECK CLONAGE OF ARGUMENTS ////////////////////////////////////////////////////////////

                ProcessTaskArgument clonearg = clone.ProcessTaskArguments.SingleOrDefault();
                Assert.NotNull(clonearg);

                Assert.AreNotEqual(clonearg.ID, arg.ID);
                Assert.AreEqual(clonearg.GetType(), arg.GetType());
                Assert.AreEqual(clonearg.Name, arg.Name);
                Assert.AreEqual(clonearg.Value, arg.Value);

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                clone.DeleteInDatabase();
            }
            finally
            {
                processTask1.DeleteInDatabase();

                parent1.DeleteInDatabase();
                parent2.DeleteInDatabase();
            }
        }