/// <inheritdoc/>
        public DataAccessCredentials GetCredentialsIfExistsFor(TableInfo tableInfo, DataAccessContext context)
        {
            int toReturn = -1;

            using (var con = _repository.GetConnection())
            {
                var cmd = DatabaseCommandHelper.GetCommand("SELECT DataAccessCredentials_ID,Context FROM DataAccessCredentials_TableInfo WHERE TableInfo_ID = @tid and (Context =@context OR Context=" + ((int)DataAccessContext.Any) + ") ", con.Connection, con.Transaction);
                cmd.Parameters.Add(DatabaseCommandHelper.GetParameter("@tid", cmd));
                cmd.Parameters["@tid"].Value = tableInfo.ID;
                cmd.Parameters.Add(DatabaseCommandHelper.GetParameter("@context", cmd));
                cmd.Parameters["@context"].Value = context;

                var r = cmd.ExecuteReader();

                //gets the first liscenced usage
                if (r.Read())
                {
                    //there is one
                    //get it by it's id
                    toReturn = Convert.ToInt32(r["DataAccessCredentials_ID"]);

                    //if the first record is liscenced for Any
                    if (Convert.ToInt32(r["Context"]) == ((int)DataAccessContext.Any))
                    {
                        //see if there is a more specific second record (e.g. DataLoad)
                        if (r.Read())
                        {
                            toReturn = Convert.ToInt32(r["DataAccessCredentials_ID"]);
                        }
                    }
                }
            }

            return(toReturn != -1 ?_repository.GetObjectByID <DataAccessCredentials>(toReturn):null);
        }
示例#2
0
        public void update_changeAllProperties_pass()
        {
            TableInfo  parent = new TableInfo(CatalogueRepository, "Rokkits");
            ColumnInfo column = new ColumnInfo(CatalogueRepository, "ExplosiveVol", "varchar(1000)", parent)
            {
                Digitisation_specs = "Highly digitizable",
                Format             = "Jpeg",
                Name      = "mycol",
                Source    = "Bazooka",
                Data_type = "Whatever"
            };

            column.SaveToDatabase();

            ColumnInfo columnAfter = CatalogueRepository.GetObjectByID <ColumnInfo>(column.ID);

            Assert.IsTrue(columnAfter.Digitisation_specs == "Highly digitizable");
            Assert.IsTrue(columnAfter.Format == "Jpeg");
            Assert.IsTrue(columnAfter.Name == "mycol");
            Assert.IsTrue(columnAfter.Source == "Bazooka");
            Assert.IsTrue(columnAfter.Data_type == "Whatever");

            columnAfter.DeleteInDatabase();
            parent.DeleteInDatabase();
        }
示例#3
0
        /// <inheritdoc/>
        public IExternalDatabaseServer GetDefaultFor(PermissableDefaults field)
        {
            if (field == PermissableDefaults.None)
            {
                return(null);
            }

            using (var con = _repository.GetConnection())
            {
                var cmd = DatabaseCommandHelper.GetCommand("SELECT ExternalDatabaseServer_ID FROM ServerDefaults WHERE DefaultType = @type", con.Connection, con.Transaction);
                var p   = cmd.CreateParameter();
                p.ParameterName = "@type";
                p.Value         = StringExpansionDictionary[field];
                cmd.Parameters.Add(p);

                var executeScalar = cmd.ExecuteScalar();

                if (executeScalar == DBNull.Value)
                {
                    return(null);
                }

                return(_repository.GetObjectByID <ExternalDatabaseServer>(Convert.ToInt32(executeScalar)));
            }
        }
示例#4
0
        public void update_changeAllPropertiesOfCatalogueItem_passes()
        {
            Catalogue     parent = new Catalogue(CatalogueRepository, "KONGOR");
            CatalogueItem child  = new CatalogueItem(CatalogueRepository, parent, "KONGOR_SUPERKING")
            {
                Agg_method  = "Adding SetUp",
                Comments    = "do not change amagad super secret!",
                Limitations = "Extreme limitaitons",
                Description =
                    "Exciting things are going down in the streets of new your this time of year it would be a great idea if you were to go there",
                Name               = "KONGOR_MINIMAN",
                Periodicity        = Catalogue.CataloguePeriodicity.Monthly,
                Research_relevance = "Highly relevant to all fields of subatomic particle study",
                Statistical_cons   = "Dangerous cons frequent the areas that this stats is happening, be afraid",
                Topic              = "nothing much, lots of stuff"
            };

            child.SaveToDatabase();

            CatalogueItem childAfter = CatalogueRepository.GetObjectByID <CatalogueItem>(child.ID);

            Assert.IsTrue(child.Name == childAfter.Name);
            Assert.IsTrue(child.Agg_method == childAfter.Agg_method);
            Assert.IsTrue(child.Comments == childAfter.Comments);
            Assert.IsTrue(child.Limitations == childAfter.Limitations);
            Assert.IsTrue(child.Description == childAfter.Description);
            Assert.IsTrue(child.Periodicity == childAfter.Periodicity);
            Assert.IsTrue(child.Research_relevance == childAfter.Research_relevance);
            Assert.IsTrue(child.Statistical_cons == childAfter.Statistical_cons);
            Assert.IsTrue(child.Topic == childAfter.Topic);

            child.DeleteInDatabase();
            parent.DeleteInDatabase();
        }
        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();
                }
            }
        }
示例#6
0
        public void CreateNewColumnInfoInDatabase_NewColumns_NewColumnsAreEqualAfterSave()
        {
            TableInfo  parent = null;
            ColumnInfo child  = null;

            try
            {
                parent = new TableInfo(CatalogueRepository, "CHI");
                child  = new ColumnInfo(CatalogueRepository, "chi", "varchar(10)", parent)
                {
                    Description     = "The community health index, 10 digits of which the first 6 are date of birth",
                    Status          = ColumnInfo.ColumnStatus.Active,
                    RegexPattern    = "\\d*",
                    ValidationRules = "Last digit must be odd for gents and even for ladies"
                };

                child.SaveToDatabase();

                ColumnInfo childAfter = CatalogueRepository.GetObjectByID <ColumnInfo>(child.ID);

                Assert.AreEqual(child.Name, childAfter.Name);
                Assert.AreEqual(child.Description, childAfter.Description);
                Assert.AreEqual(child.Status, childAfter.Status);
                Assert.AreEqual(child.RegexPattern, childAfter.RegexPattern);
                Assert.AreEqual(child.ValidationRules, childAfter.ValidationRules);
            }
            finally
            {
                child.DeleteInDatabase();
                parent.DeleteInDatabase();
            }
        }
示例#7
0
        public void Container_Subcontainering()
        {
            var container = new CohortAggregateContainer(CatalogueRepository, SetOperation.UNION);

            var container2 = new CohortAggregateContainer(CatalogueRepository, SetOperation.INTERSECT);

            try
            {
                Assert.AreEqual(0, container.GetSubContainers().Length);


                Assert.AreEqual(0, container.GetSubContainers().Length);

                //set container to parent
                container.AddChild(container2);

                //container 1 should now contain container 2
                Assert.AreEqual(1, container.GetSubContainers().Length);
                Assert.Contains(container2, container.GetSubContainers());

                //container 2 should not have any children
                Assert.AreEqual(0, container2.GetSubContainers().Length);
            }
            finally
            {
                container.DeleteInDatabase();

                //container 2 was contained within container 1 so should have also been deleted
                Assert.Throws <KeyNotFoundException>(
                    () => CatalogueRepository.GetObjectByID <CohortAggregateContainer>(container2.ID));
            }
        }
示例#8
0
        public void MigrationOfOldPasswordsTest()
        {
            //cleanup
            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(c => c.Name.Equals("frankieFran")))
            {
                c.DeleteInDatabase();
            }

            //create a new credentials
            DataAccessCredentials creds = new DataAccessCredentials(CatalogueRepository, "frankieFran");

            try
            {
                //update the database to an unencrypted password (like would be the case before software patch)
                using (var con = CatalogueRepository.GetConnection())
                {
                    var cmd = DatabaseCommandHelper.GetCommand("UPDATE DataAccessCredentials set Password = '******' where Name='frankieFran'", con.Connection, con.Transaction);
                    Assert.AreEqual(1, cmd.ExecuteNonQuery());
                }

                DataAccessCredentials newCopy = CatalogueRepository.GetObjectByID <DataAccessCredentials>(creds.ID);

                Assert.AreEqual("fish", newCopy.GetDecryptedPassword());
                Assert.AreNotEqual("fish", newCopy.Password);
            }
            finally
            {
                creds.DeleteInDatabase();
            }
        }
示例#9
0
        public void LoadProgress_Equals()
        {
            var loadMetadata = new LoadMetadata(CatalogueRepository);


            LoadProgress progress     = new LoadProgress(CatalogueRepository, loadMetadata);
            LoadProgress progressCopy = CatalogueRepository.GetObjectByID <LoadProgress>(progress.ID);

            progressCopy.Name       = "fish";
            progressCopy.OriginDate = new DateTime(2001, 01, 01);

            try
            {
                //values are different
                Assert.AreNotEqual(progressCopy.OriginDate, progress.OriginDate);
                Assert.AreNotEqual(progressCopy.Name, progress.Name);

                //IDs are the same
                Assert.AreEqual(progressCopy.ID, progress.ID);

                //therefore objects are the same
                Assert.IsTrue(progressCopy.Equals(progress));
            }
            finally
            {
                progress.DeleteInDatabase();
                loadMetadata.DeleteInDatabase();
            }
        }
示例#10
0
        public void SaveAndReloadCredentials()
        {
            var originalCredentials = new DataAccessCredentials(CatalogueRepository, "bob");

            try
            {
                originalCredentials.Name     = "bob1";
                originalCredentials.Username = "******";
                originalCredentials.Password = "******";
                originalCredentials.SaveToDatabase();

                var newCopy = CatalogueRepository.GetObjectByID <DataAccessCredentials>(originalCredentials.ID);
                Assert.AreEqual(originalCredentials.Name, newCopy.Name);
                Assert.AreEqual(originalCredentials.Username, newCopy.Username);
                Assert.AreEqual(originalCredentials.Password, newCopy.Password);

                //test overridden Equals
                Assert.AreEqual(originalCredentials, newCopy);
                originalCredentials.Password = "******";
                Assert.AreEqual(originalCredentials, newCopy);//they are still equal because IDs are the same
            }
            finally
            {
                originalCredentials.DeleteInDatabase();
            }
        }
示例#11
0
        public void test_creating_ExtractionFilter()
        {
            ExtractionInformation     extractInfo      = null;
            ExtractionFilter          filterFastThings = null;
            ExtractionFilterParameter parameter        = null;

            try
            {
                //define extraction information
                extractInfo = new ExtractionInformation(CatalogueRepository, cataItem, columnInfo, "ROUND(VelocityOfMatter,2) VelocityOfMatterRounded");

                //define filter and parameter
                filterFastThings = new ExtractionFilter(CatalogueRepository, "FastThings", extractInfo)
                {
                    WhereSQL    = "VelocityOfMatter > @X",
                    Description = "Query to identify things that travel faster than X miles per hour!"
                };
                filterFastThings.SaveToDatabase();
                Assert.AreEqual(filterFastThings.Name, "FastThings");

                parameter = new ExtractionFilterParameter(CatalogueRepository, "DECLARE @X INT", filterFastThings);

                Assert.IsNotNull(parameter);
                Assert.AreEqual(parameter.ParameterName, "@X");

                parameter.Value = "500";
                parameter.SaveToDatabase();

                ExtractionFilterParameter afterSave = CatalogueRepository.GetObjectByID <ExtractionFilterParameter>(parameter.ID);
                Assert.AreEqual(afterSave.Value, "500");


                ExtractionFilter filterFastThings_NewCopyFromDB = CatalogueRepository.GetObjectByID <ExtractionFilter>(filterFastThings.ID);

                Assert.AreEqual(filterFastThings.ID, filterFastThings_NewCopyFromDB.ID);
                Assert.AreEqual(filterFastThings.Description, filterFastThings_NewCopyFromDB.Description);
                Assert.AreEqual(filterFastThings.Name, filterFastThings_NewCopyFromDB.Name);
                Assert.AreEqual(filterFastThings.WhereSQL, filterFastThings_NewCopyFromDB.WhereSQL);
            }
            finally
            {
                if (parameter != null)
                {
                    parameter.DeleteInDatabase();
                }

                //filters are children of extraction info with CASCADE DELETE so have to delete this one first if we want to test it programatically (although we could just skip deleting it since SQL will handle it anyway)
                if (filterFastThings != null)
                {
                    filterFastThings.DeleteInDatabase();
                }

                if (extractInfo != null)
                {
                    extractInfo.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();
            }
        }
示例#13
0
        public void CreateNewTableInfoInDatabase_valid_pass()
        {
            TableInfo table = new TableInfo(CatalogueRepository, "TestDB..TestTableName");

            Assert.NotNull(table);

            table.DeleteInDatabase();

            var ex = Assert.Throws <KeyNotFoundException>(() => CatalogueRepository.GetObjectByID <TableInfo>(table.ID));

            Assert.AreEqual(ex.Message, "Could not find TableInfo with ID " + table.ID);
        }
        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();
            }
        }
示例#15
0
        public void SetupAndSaveAPipeline()
        {
            Pipeline pipeline = new Pipeline(CatalogueRepository, "Bob");

            try
            {
                Assert.AreEqual(pipeline.Name, "Bob");

                PipelineComponent pipelineComponent = new PipelineComponent(CatalogueRepository, pipeline, typeof(BasicAnonymisationEngine), 0);

                try
                {
                    Assert.AreEqual(pipelineComponent.Class, typeof(BasicAnonymisationEngine).FullName);

                    PipelineComponentArgument argument1 = (PipelineComponentArgument)pipelineComponent.CreateNewArgument();
                    PipelineComponentArgument argument2 = new PipelineComponentArgument(CatalogueRepository, pipelineComponent);

                    try
                    {
                        argument1.SetType(typeof(string));
                        argument1.SetValue("bob");
                        argument1.SaveToDatabase();

                        var dt = DateTime.Now;
                        dt = new DateTime(dt.Ticks - (dt.Ticks % TimeSpan.TicksPerSecond), dt.Kind);//get rid of the milliseconds

                        argument2.SetType(typeof(DateTime));
                        argument2.SetValue(dt);
                        argument2.SaveToDatabase();

                        PipelineComponentArgument argument2Copy = CatalogueRepository.GetObjectByID <PipelineComponentArgument>(argument2.ID);
                        Assert.AreEqual(dt, argument2Copy.GetValueAsSystemType());
                    }
                    finally
                    {
                        argument1.DeleteInDatabase();
                        argument2.DeleteInDatabase();
                    }
                }
                finally
                {
                    pipelineComponent.DeleteInDatabase();
                }
            }
            finally
            {
                pipeline.DeleteInDatabase();
            }
        }
示例#16
0
        public void CreateNewColumnInfoInDatabase_valid_pass()
        {
            TableInfo  parent     = new TableInfo(CatalogueRepository, "Lazors");
            ColumnInfo columnInfo = new ColumnInfo(CatalogueRepository, "Lazor Reflection Vol", "varchar(1000)", parent);

            Assert.NotNull(columnInfo);

            columnInfo.DeleteInDatabase();

            var ex = Assert.Throws <KeyNotFoundException>(() => CatalogueRepository.GetObjectByID <ColumnInfo>(columnInfo.ID));

            Assert.IsTrue(ex.Message.StartsWith("Could not find ColumnInfo with ID " + columnInfo.ID), ex.Message);

            parent.DeleteInDatabase();
        }
示例#17
0
        public void CreateNewAndGetBackFromDatabase()
        {
            var loadMetadata = new LoadMetadata(CatalogueRepository);

            try
            {
                loadMetadata.LocationOfFlatFiles = "C:\\temp";
                loadMetadata.SaveToDatabase();

                var loadMetadataWithIdAfterwards = CatalogueRepository.GetObjectByID <LoadMetadata>(loadMetadata.ID);
                Assert.AreEqual(loadMetadataWithIdAfterwards.LocationOfFlatFiles, "C:\\temp");
            }
            finally
            {
                loadMetadata.DeleteInDatabase();
            }
        }
示例#18
0
        public void DataAccessCredentialsEncryption()
        {
            //cleanup
            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(c => c.Name.Equals("frankieFran")))
            {
                c.DeleteInDatabase();
            }

            DataAccessCredentials creds = new DataAccessCredentials(CatalogueRepository, "frankieFran");

            try
            {
                //as soon as you set a password it should be encrypted by the credentials class in memory
                creds.Password = "******";
                Assert.AreNotEqual("fish", creds.Password);
                Assert.AreEqual("fish", creds.GetDecryptedPassword());//but we should still be able to decrypt it

                //save it
                creds.SaveToDatabase();
                using (var con = CatalogueRepository.GetConnection())
                {
                    string value;
                    using (var cmd = DatabaseCommandHelper.GetCommand("Select Password from DataAccessCredentials where Name='frankieFran'", con.Connection, con.Transaction))
                        value = (string)cmd.ExecuteScalar();

                    //ensure password in database is encrypted
                    Assert.AreNotEqual("fish", value);
                    Assert.AreEqual(creds.Password, value);//does value in database match value in memory (encrypted)
                }

                //get a new copy out of the database
                DataAccessCredentials newCopy = CatalogueRepository.GetObjectByID <DataAccessCredentials>(creds.ID);
                Assert.AreEqual(creds.Password, newCopy.Password); //passwords should match
                Assert.AreNotEqual("fish", creds.Password);        //neither should be fish
                Assert.AreNotEqual("fish", newCopy.Password);

                //both should decrypt to the same value (fish
                Assert.AreEqual("fish", creds.GetDecryptedPassword());
                Assert.AreEqual("fish", newCopy.GetDecryptedPassword());
            }
            finally
            {
                creds.DeleteInDatabase();
            }
        }
示例#19
0
        public void test_SupportingDocument_CreateChangeSaveDestroy()
        {
            Catalogue          cata = new Catalogue(CatalogueRepository, "deleteme");
            SupportingDocument doc  = new SupportingDocument(CatalogueRepository, cata, "davesFile");

            doc.Description = "some exciting file that dave loves";
            doc.SaveToDatabase();

            Assert.AreEqual(doc.Name, "davesFile");
            Assert.AreEqual(doc.Description, "some exciting file that dave loves");

            SupportingDocument docAfterCommit = CatalogueRepository.GetObjectByID <SupportingDocument>(doc.ID);

            Assert.AreEqual(docAfterCommit.Description, doc.Description);

            doc.DeleteInDatabase();
            cata.DeleteInDatabase();
        }
示例#20
0
        public void AddSameTaskTwice_StaysAtOne()
        {
            CohortCompiler compiler = new CohortCompiler(cohortIdentificationConfiguration);

            container1.AddChild(aggregate1, 0);
            try
            {
                compiler.AddTask(aggregate1, null);

                Assert.AreEqual(1, compiler.Tasks.Count);

                var oldTask = compiler.Tasks.First();

                //adding it again with the same SQL should result in it ignoring it
                compiler.AddTask(aggregate1, null);
                Assert.AreEqual(1, compiler.Tasks.Count);

                //make a change to the SQL
                foreach (var d in aggregate1.AggregateDimensions)
                {
                    d.SelectSQL = "'fish'";
                    d.SaveToDatabase();
                }

                //now add it again
                var newAggregate1 = CatalogueRepository.GetObjectByID <AggregateConfiguration>(aggregate1.ID);

                compiler.AddTask(newAggregate1, null);
                Assert.AreEqual(1, compiler.Tasks.Count); //should still be 1 task

                // TN: Task was never asked to start so was still at NotScheduled so cancellation wouldn't actually happen
                //old task should have been asked to cancel
                //   Assert.IsTrue(oldTask.Key.CancellationToken.IsCancellationRequested);

                Assert.AreNotSame(oldTask, compiler.Tasks.Single()); //new task should not be the same as the old one
                Assert.IsFalse(compiler.Tasks.Single().Key.CancellationToken.IsCancellationRequested);
                //new task should not be cancelled} finally {
            }
            finally
            {
                container1.RemoveChild(aggregate1);
            }
        }
示例#21
0
        public void ContainerCreate()
        {
            var container = new CohortAggregateContainer(CatalogueRepository, SetOperation.UNION);

            try
            {
                Assert.AreEqual(SetOperation.UNION, container.Operation);

                container.Operation = SetOperation.INTERSECT;
                container.SaveToDatabase();

                var container2 = CatalogueRepository.GetObjectByID <CohortAggregateContainer>(container.ID);
                Assert.AreEqual(SetOperation.INTERSECT, container2.Operation);
            }
            finally
            {
                container.DeleteInDatabase();
            }
        }
示例#22
0
        public void TestCreatingGovernance_ChangeName()
        {
            var gov = GetGov();

            gov.Name = "Fish";
            GovernancePeriod freshCopy = CatalogueRepository.GetObjectByID <GovernancePeriod>(gov.ID);

            //local change not applied yet
            Assert.AreNotEqual(gov.Name, freshCopy.Name);

            //comitted change to database
            gov.SaveToDatabase();

            //notice that this fresh copy is still desynced
            Assert.AreNotEqual(gov.Name, freshCopy.Name);

            //sync it
            freshCopy = CatalogueRepository.GetObjectByID <GovernancePeriod>(gov.ID);
            Assert.AreEqual(gov.Name, freshCopy.Name);
        }
示例#23
0
        public void update_changeAllProperties_pass()
        {
            TableInfo table = new TableInfo(CatalogueRepository, "CHI_AMALG..SearchStuff")
            {
                Database     = "CHI_AMALG",
                Server       = "Highly restricted",
                Name         = "Fishmongery!",
                DatabaseType = DatabaseType.Oracle
            };

            table.SaveToDatabase();

            TableInfo tableAfter = CatalogueRepository.GetObjectByID <TableInfo>(table.ID);

            Assert.IsTrue(tableAfter.Database == "CHI_AMALG");
            Assert.IsTrue(tableAfter.Server == "Highly restricted");
            Assert.IsTrue(tableAfter.Name == "Fishmongery!");
            Assert.IsTrue(tableAfter.DatabaseType == DatabaseType.Oracle);

            tableAfter.DeleteInDatabase();
        }
示例#24
0
        public void CreateNewCohortIdentificationConfiguration_SaveAndReload()
        {
            var config = new CohortIdentificationConfiguration(CatalogueRepository, "franky");

            try
            {
                Assert.IsTrue(config.Exists());
                Assert.AreEqual("franky", config.Name);

                config.Description = "Hi there";
                config.SaveToDatabase();


                CohortIdentificationConfiguration config2 = CatalogueRepository.GetObjectByID <CohortIdentificationConfiguration>(config.ID);
                Assert.AreEqual("Hi there", config2.Description);
            }
            finally
            {
                config.DeleteInDatabase();
                Assert.IsFalse(config.Exists());
            }
        }
示例#25
0
        public void CloneProcessTask_ToSameLoadMetadataWithoutArguments()
        {
            LoadMetadata test         = new LoadMetadata(CatalogueRepository);
            ProcessTask  processTask1 = new ProcessTask(CatalogueRepository, test, LoadStage.AdjustRaw)
            {
                Name  = "Franky",
                Order = 999
            };

            try
            {
                processTask1.SaveToDatabase();

                var clone = processTask1.CloneToNewLoadMetadataStage(test, LoadStage.GetFiles);
                Assert.AreNotSame(clone.ID, processTask1.ID);
                Assert.IsFalse(clone.ID == processTask1.ID);

                //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);

                Assert.IsFalse(orig.ID == clone.ID);
                Assert.AreEqual(LoadStage.AdjustRaw, orig.LoadStage);
                Assert.AreEqual(LoadStage.GetFiles, clone.LoadStage);

                Assert.AreEqual(orig.Order, clone.Order);
                Assert.AreEqual(orig.Path, clone.Path);
                Assert.AreEqual(orig.ProcessTaskType, clone.ProcessTaskType);
                Assert.AreEqual(orig.LoadMetadata_ID, clone.LoadMetadata_ID);

                clone.DeleteInDatabase();
            }
            finally
            {
                processTask1.DeleteInDatabase();
                test.DeleteInDatabase();
            }
        }
示例#26
0
        public void SingleThreadedBulkCatalogueCreation(bool useTransactions)
        {
            IManagedConnection c = null;

            if (useTransactions)
            {
                c = CatalogueRepository.BeginNewTransactedConnection();
            }

            using (c)
            {
                //create lots of catalogues
                for (int i = 0; i < 30; i++)
                {
                    var cata = new Catalogue(CatalogueRepository, "SuperMultiThreadedTestCatalogue" + Guid.NewGuid());
                    var copy = CatalogueRepository.GetObjectByID <Catalogue>(cata.ID);

                    copy.Description = "fish";
                    Assert.IsTrue(copy.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent);

                    copy.SaveToDatabase();
                    Assert.IsTrue(copy.HasLocalChanges().Evaluation == ChangeDescription.NoChanges);
                }

                //now fetch them out of database lots of times
                for (int i = 0; i < 100; i++)
                {
                    CatalogueRepository.GetAllObjects <Catalogue>();
                }

                if (useTransactions)
                {
                    CatalogueRepository.EndTransactedConnection(false);
                }
            }
        }
示例#27
0
        public void ExtendedProperty_Catalogue()
        {
            var cata = new Catalogue(CatalogueRepository, "My cata");
            var prop = new ExtendedProperty(CatalogueRepository, cata, "Fish", 5);

            Assert.AreEqual(5, prop.GetValueAsSystemType());
            Assert.IsTrue(prop.IsReferenceTo(cata));

            prop.SetValue(10);
            prop.SaveToDatabase();

            Assert.AreEqual(10, prop.GetValueAsSystemType());
            Assert.IsTrue(prop.IsReferenceTo(cata));

            prop.RevertToDatabaseState();

            Assert.AreEqual(10, prop.GetValueAsSystemType());
            Assert.IsTrue(prop.IsReferenceTo(cata));

            var prop2 = CatalogueRepository.GetObjectByID <ExtendedProperty>(prop.ID);

            Assert.AreEqual(10, prop.GetValueAsSystemType());
            Assert.IsTrue(prop.IsReferenceTo(cata));
        }
示例#28
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();
            }
        }