示例#1
0
        public void CreateNew_UseConstraint()
        {
            // Clean up any existing regexes
            CatalogueRepository.GetAllObjects <StandardRegex>("WHERE ConceptName = 'Fish'").ToList().ForEach(r => r.DeleteInDatabase());

            var regex = new StandardRegex(CatalogueRepository);

            try
            {
                Assert.IsNotNull(regex.ConceptName);
                Assert.IsTrue(string.IsNullOrEmpty(regex.Description));

                regex.ConceptName = "Fish";
                regex.Regex       = "^(Fish)$";
                regex.SaveToDatabase();

                StandardRegexConstraint constraint = new StandardRegexConstraint(CatalogueRepository);

                constraint.CatalogueStandardRegex = regex;

                Assert.IsNull(constraint.Validate("Fish", null, null));
                ValidationFailure failure = constraint.Validate("FishFingers", null, null);
                Assert.IsNotNull(failure);
            }
            finally
            {
                regex.DeleteInDatabase();
            }
        }
示例#2
0
        public void GetAllTableInfos_moreThan1_pass()
        {
            var tableInfo = new TableInfo(CatalogueRepository, "AMAGAD!!!");

            Assert.IsTrue(CatalogueRepository.GetAllObjects <TableInfo>().Any());
            tableInfo.DeleteInDatabase();
        }
示例#3
0
        public void MultiEncryptingShouldntBreakIt()
        {
            //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

                //set the password to the encrypted password
                creds.Password = creds.Password;

                //should still work
                Assert.AreNotEqual("fish", creds.Password);
                Assert.AreEqual("fish", creds.GetDecryptedPassword()); //but we should still be able to decrypt it
            }
            finally
            {
                creds.DeleteInDatabase();
            }
        }
示例#4
0
        private void SetupLowPrivilegeUserRightsFor(DiscoveredDatabase db, TestLowPrivilegePermissions permissions, ITableInfo ti)
        {
            var dbType = db.Server.DatabaseType;

            //get access to the database using the current credentials
            var username = TestDatabaseSettings.GetLowPrivilegeUsername(dbType);
            var password = TestDatabaseSettings.GetLowPrivilegePassword(dbType);

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                Assert.Inconclusive();
            }

            //give the user access to the table
            var sql = GrantAccessSql(username, dbType, permissions);

            using (var con = db.Server.GetConnection())
                UsefulStuff.ExecuteBatchNonQuery(sql, con);

            if (ti != null)
            {
                //remove any existing credentials
                foreach (DataAccessCredentials cred in CatalogueRepository.GetAllObjects <DataAccessCredentials>())
                {
                    CatalogueRepository.TableInfoCredentialsManager.BreakAllLinksBetween(cred, ti);
                }

                //set the new ones
                DataAccessCredentialsFactory credentialsFactory = new DataAccessCredentialsFactory(CatalogueRepository);
                credentialsFactory.Create(ti, username, password, DataAccessContext.Any);
            }
        }
示例#5
0
        public void CreateNewCredentialsThenGetByUsernamePasswordCombo()
        {
            var newCredentials = new DataAccessCredentials(CatalogueRepository, "bob");

            newCredentials.Username = "******";
            newCredentials.Password = "******";
            newCredentials.SaveToDatabase();

            var newCopy = CatalogueRepository.GetAllObjects <DataAccessCredentials>("WHERE Username='******'").SingleOrDefault();

            Assert.IsNotNull(newCopy);

            try
            {
                Assert.NotNull(newCopy);
                Assert.AreEqual(newCredentials.ID, newCopy.ID);
                Assert.AreEqual(newCredentials.Username, newCopy.Username);
                Assert.AreEqual(newCredentials.GetDecryptedPassword(), newCopy.GetDecryptedPassword());
                Assert.AreEqual(newCredentials.Password, newCopy.Password);
            }
            finally
            {
                newCredentials.DeleteInDatabase();
            }
        }
示例#6
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();
            }
        }
 public ForwardEngineerANOCatalogueEngine(IRDMPPlatformRepositoryServiceLocator repositoryLocator, ForwardEngineerANOCataloguePlanManager planManager)
 {
     _catalogueRepository = (CatalogueRepository)repositoryLocator.CatalogueRepository;
     _shareManager        = new ShareManager(repositoryLocator);
     _planManager         = planManager;
     _allColumnsInfos     = _catalogueRepository.GetAllObjects <ColumnInfo>();
 }
示例#8
0
        private void RemovePreExistingReference()
        {
            //There will likely be an old reference to the external database server
            var preExisting = CatalogueRepository.GetAllObjects <ExternalDatabaseServer>().SingleOrDefault(e => e.Name.Equals(ANOStore_DatabaseName));

            if (preExisting == null)
            {
                return;
            }

            //Some child tests will likely create ANOTables that reference this server so we need to cleanup those for them so that we can cleanup the old server reference too
            foreach (var lingeringTablesReferencingServer in CatalogueRepository.GetAllObjects <ANOTable>().Where(a => a.Server_ID == preExisting.ID))
            {
                //unhook the anonymisation transform from any ColumnInfos using it
                foreach (ColumnInfo colWithANOTransform in CatalogueRepository.GetAllObjects <ColumnInfo>().Where(c => c.ANOTable_ID == lingeringTablesReferencingServer.ID))
                {
                    Console.WriteLine("Unhooked ColumnInfo " + colWithANOTransform + " from ANOTable " + lingeringTablesReferencingServer);
                    colWithANOTransform.ANOTable_ID = null;
                    colWithANOTransform.SaveToDatabase();
                }

                TruncateANOTable(lingeringTablesReferencingServer);
                lingeringTablesReferencingServer.DeleteInDatabase();
            }

            //now delete the old server reference
            preExisting.DeleteInDatabase();
        }
        public void Test_ExampleDatasetsCreation()
        {
            //Should be empty RDMP metadata database
            Assert.AreEqual(0, CatalogueRepository.GetAllObjects <Catalogue>().Length);
            Assert.AreEqual(0, CatalogueRepository.GetAllObjects <AggregateConfiguration>().Length);

            //create the pipelines
            var pipes = new CataloguePipelinesAndReferencesCreation(RepositoryLocator, null, null);

            pipes.CreatePipelines();

            //create all the stuff
            var db      = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer);
            var creator = new ExampleDatasetsCreation(new ThrowImmediatelyActivator(RepositoryLocator), RepositoryLocator);

            creator.Create(db, new ThrowImmediatelyCheckNotifier(), new PlatformDatabaseCreationOptions()
            {
                Seed = 500, DropDatabases = true
            });

            //should be at least 2 views (marked as view)
            var views = CatalogueRepository.GetAllObjects <TableInfo>().Count(ti => ti.IsView);

            Assert.GreaterOrEqual(views, 2);

            //should have at least created some catalogues, graphs etc
            Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects <Catalogue>().Length, 4);
            Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects <AggregateConfiguration>().Length, 4);
        }
示例#10
0
        /// <inheritdoc/>
        public DataAccessCredentials GetCredentialByUsernameAndPasswordIfExists(string username, string password)
        {
            //see if we already have a record of this user
            DataAccessCredentials[] existingCredentials = _repository.GetAllObjects <DataAccessCredentials>().Where(c => c.Username.Equals(username)).ToArray();

            //found an existing credential that matched on username
            if (existingCredentials.Any())
            {
                //there is one or more existing credential with this username
                var matchingOnPassword = existingCredentials.Where(c => c.PasswordIs(password)).ToArray();

                if (matchingOnPassword.Length == 1)
                {
                    return(matchingOnPassword.Single());
                }

                if (matchingOnPassword.Length > 1)
                {
                    throw new Exception("Found " + matchingOnPassword.Length + " DataAccessCredentials that matched the supplied username/password - does your database have massive duplication in it?");
                }

                //there are 0 that match on password
                return(null);
            }
            else
            {
                //did not find an existing credential that matched on username
                return(null);
            }
        }
示例#11
0
        private void CleanCatalogueDatabase()
        {
            if (_catalogue != null)
            {
                _catalogue.DeleteInDatabase();
            }

            // ensure the database is cleared of test remnants
            foreach (var ji in CatalogueRepository.GetAllObjects <JoinInfo>())
            {
                ji.DeleteInDatabase();
            }

            // column infos don't appear to delete
            foreach (var ci in CatalogueRepository.GetAllObjects <ColumnInfo>())
            {
                ci.DeleteInDatabase();
            }

            foreach (var ti in CatalogueRepository.GetAllObjects <TableInfo>())
            {
                ti.DeleteInDatabase();
            }

            foreach (var credentials in CatalogueRepository.GetAllObjects <DataAccessCredentials>())
            {
                credentials.DeleteInDatabase();
            }
        }
示例#12
0
        public void TestGenerateSqlForThreeLevelJoinPath_TimePeriodIsGrandparent()
        {
            ThreeTableSetupWhereTimePeriodIsGrandparent();

            var ciTimePeriodicity = CatalogueRepository.GetAllObjects <ColumnInfo>().SingleOrDefault(c => c.GetRuntimeName().Equals("HeaderDate"));

            if (ciTimePeriodicity == null)
            {
                throw new InvalidOperationException("Could not find TimePeriodicity column");
            }

            var sqlHelper = new BackfillSqlHelper(ciTimePeriodicity, From, To);

            var tiHeader  = CatalogueRepository.GetAllObjects <TableInfo>().Single(t => t.GetRuntimeName().Equals("Headers"));
            var tiSamples = CatalogueRepository.GetAllObjects <TableInfo>().Single(t => t.GetRuntimeName().Equals("Samples"));
            var tiResults = CatalogueRepository.GetAllObjects <TableInfo>().Single(t => t.GetRuntimeName().Equals("Results"));

            var joinInfos = CatalogueRepository.GetAllObjects <JoinInfo>();
            var joinPath  = new List <JoinInfo>
            {
                joinInfos.Single(info => info.PrimaryKey.TableInfo_ID == tiHeader.ID),
                joinInfos.Single(info => info.PrimaryKey.TableInfo_ID == tiSamples.ID)
            };

            var sql = sqlHelper.CreateSqlForJoinToTimePeriodicityTable("CurrentTable", tiResults, "TimePeriodicityTable", From, joinPath);



            Assert.AreEqual(string.Format(@"SELECT CurrentTable.*, TimePeriodicityTable.HeaderDate AS TimePeriodicityField 
FROM [{0}]..[Results] CurrentTable
LEFT JOIN [{0}]..[Samples] j1 ON j1.ID = CurrentTable.SampleID
LEFT JOIN [{0}]..[Headers] TimePeriodicityTable ON TimePeriodicityTable.ID = j1.HeaderID",
                                          From.GetRuntimeName()), sql);
        }
示例#13
0
        public void TestGettingConnectionStrings()
        {
            foreach (TableInfo tbl in CatalogueRepository.GetAllObjects <TableInfo>().Where(table => table.Name.ToLower().Equals("bob")))
            {
                tbl.DeleteInDatabase();
            }

            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(cred => cred.Name.ToLower().Equals("bob")))
            {
                c.DeleteInDatabase();
            }

            //test it with TableInfos
            TableInfo t = new TableInfo(CatalogueRepository, "Bob");

            try
            {
                t.Server   = "fish";
                t.Database = "bobsDatabase";
                t.SaveToDatabase();

                //t has no credentials
                var server = DataAccessPortal.GetInstance().ExpectServer(t, DataAccessContext.InternalDataProcessing);

                Assert.AreEqual(typeof(SqlConnectionStringBuilder), server.Builder.GetType());
                Assert.AreEqual("fish", ((SqlConnectionStringBuilder)server.Builder).DataSource);
                Assert.AreEqual("bobsDatabase", ((SqlConnectionStringBuilder)server.Builder).InitialCatalog);
                Assert.AreEqual(true, ((SqlConnectionStringBuilder)server.Builder).IntegratedSecurity);

                var creds = new DataAccessCredentials(CatalogueRepository, "Bob");
                try
                {
                    t.SetCredentials(creds, DataAccessContext.InternalDataProcessing, true);
                    creds.Username = "******";
                    creds.Password = "******";
                    creds.SaveToDatabase();


                    ////t has some credentials now
                    server = DataAccessPortal.GetInstance().ExpectServer(t, DataAccessContext.InternalDataProcessing);

                    Assert.AreEqual(typeof(SqlConnectionStringBuilder), server.Builder.GetType());
                    Assert.AreEqual("fish", ((SqlConnectionStringBuilder)server.Builder).DataSource);
                    Assert.AreEqual("bobsDatabase", ((SqlConnectionStringBuilder)server.Builder).InitialCatalog);
                    Assert.AreEqual("frank", ((SqlConnectionStringBuilder)server.Builder).UserID);
                    Assert.AreEqual("bobsPassword", ((SqlConnectionStringBuilder)server.Builder).Password);
                    Assert.AreEqual(false, ((SqlConnectionStringBuilder)server.Builder).IntegratedSecurity);
                }
                finally
                {
                    var linker = new TableInfoCredentialsManager(CatalogueRepository);
                    linker.BreakAllLinksBetween(creds, t);
                    creds.DeleteInDatabase();
                }
            }
            finally
            {
                t.DeleteInDatabase();
            }
        }
        public void TestPruning()
        {
            Catalogue c  = new Catalogue(CatalogueRepository, "Catapault");
            var       ci = new CatalogueItem(CatalogueRepository, c, "string");

            Catalogue c2  = new Catalogue(CatalogueRepository, "Catapault (Import)");
            var       ci2 = new CatalogueItem(CatalogueRepository, c2, "string (Import)");

            Assert.AreEqual(CatalogueRepository.GetAllObjects <ObjectExport>().Count(), 0);
            var ec  = _share.GetNewOrExistingExportFor(c);
            var eci = _share.GetNewOrExistingExportFor(ci);

            _share.GetImportAs(ec.SharingUID, c2);
            _share.GetImportAs(eci.SharingUID, ci2);

            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectExport>().Count());
            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectImport>().Count());
            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectImport>().Count());//successive calls shouldhn't generate extra entries since they are same obj
            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectImport>().Count());

            //cannot delete the shared object
            Assert.Throws <Exception>(c.DeleteInDatabase);

            //can delete the import because that's ok
            Assert.DoesNotThrow(c2.DeleteInDatabase);

            //now that we deleted the import it should have deleted everything else including the CatalogueItem import which magically disapeared when we deleted the Catalogue via database level cascade events
            Assert.AreEqual(0, CatalogueRepository.GetAllObjects <ObjectImport>().Count());

            _share.GetImportAs(eci.SharingUID, ci2);
        }
示例#15
0
        public void TearDown()
        {
            //delete all joins
            foreach (JoinInfo j in CatalogueRepository.GetAllObjects <JoinInfo>())
            {
                j.DeleteInDatabase();
            }

            //delete everything from data export
            foreach (var t in new Type[] { typeof(ExtractionConfiguration), typeof(ExternalCohortTable), typeof(ExtractableDataSet) })
            {
                foreach (IDeleteable o in DataExportRepository.GetAllObjects(t))
                {
                    o.DeleteInDatabase();
                }
            }

            //delete everything from catalogue
            foreach (var t in new Type[] { typeof(Catalogue), typeof(TableInfo), typeof(LoadMetadata), typeof(Pipeline) })
            {
                foreach (IDeleteable o in CatalogueRepository.GetAllObjects(t))
                {
                    o.DeleteInDatabase();
                }
            }
        }
示例#16
0
        public void TestLargeImageDatasets(DatabaseType databaseType, int numberOfImages)
        {
            foreach (Pipeline p in CatalogueRepository.GetAllObjects <Pipeline>())
            {
                p.DeleteInDatabase();
            }

            var db = GetCleanedServer(databaseType);

            var d = CatalogueRepository.GetServerDefaults();

            d.ClearDefault(PermissableDefaults.RAWDataLoadServer);

            var template = ImageTableTemplateCollection.LoadFrom(_templateXml);

            _globals = new GlobalOptionsFactory().Load();

            _globals.DicomRelationalMapperOptions.DatabaseNamerType            = typeof(MyFixedStagingDatabaseNamer).FullName;
            _globals.DicomRelationalMapperOptions.QoSPrefetchCount             = ushort.MaxValue;
            _globals.DicomRelationalMapperOptions.MinimumBatchSize             = numberOfImages;
            _globals.DicomRelationalMapperOptions.UseInsertIntoForRAWMigration = true;

            _helper = new DicomRelationalMapperTestHelper();
            _helper.SetupSuite(db, RepositoryLocator, _globals, typeof(DicomDatasetCollectionSource), root: null, template: template, persistentRaw: true);

            //do not use an explicit RAW data load server
            d.ClearDefault(PermissableDefaults.RAWDataLoadServer);

            Random r = new Random(123);

            List <DicomDataset> allImages;

            using (var generator = new DicomDataGenerator(r, null, "CT"))
                allImages = generator.GenerateImages(numberOfImages, r);

            Assert.AreEqual(numberOfImages, allImages.Count);

            using (var tester = new MicroserviceTester(_globals.RabbitOptions, _globals.DicomRelationalMapperOptions))
            {
                using (var host = new DicomRelationalMapperHost(_globals))
                {
                    tester.SendMessages(_globals.DicomRelationalMapperOptions, allImages.Select(GetFileMessageForDataset), true);

                    Console.WriteLine("Starting Host");
                    host.Start();

                    Stopwatch sw = Stopwatch.StartNew();
                    new TestTimelineAwaiter().Await(() => host.Consumer.AckCount == numberOfImages, null, 20 * 60 * 100); //1 minute

                    Console.Write("Time For DLE:" + sw.Elapsed.TotalSeconds + "s");
                    host.Stop("Test finished");
                }
            }

            foreach (Pipeline allObject in CatalogueRepository.GetAllObjects <Pipeline>())
            {
                allObject.DeleteInDatabase();
            }
        }
示例#17
0
        public void CreateANOVersionTest_IntIdentity()
        {
            var dbName = TestDatabaseNames.GetConsistentName("CreateANOVersionTest");

            //setup the anonymisation database (destination)
            var db = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(dbName);

            db.Create(true);

            //Create this table in the scratch database
            var tbl = DiscoveredDatabaseICanCreateRandomTablesIn.CreateTable("MyTable", new[]
            {
                new DatabaseColumnRequest("id", "int identity(1,1)", false)
                {
                    IsPrimaryKey = true
                },
                new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string), 10), false)
            });

            TableInfo ti;

            ColumnInfo[] cols;
            var          cata = Import(tbl, out ti, out cols);

            var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, cata);

            planManager.TargetDatabase = db;

            var nameCol = cols.Single(c => c.GetRuntimeName().Equals("Name"));

            //setup test rules for migrator
            planManager.Plans[nameCol].Plan = Plan.Drop;

            //rules should pass checks
            planManager.Check(new ThrowImmediatelyCheckNotifier());

            var engine = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, planManager);

            engine.Execute();

            var anoCatalogue = CatalogueRepository.GetAllObjects <Catalogue>().Single(c => c.Folder.Path.StartsWith("\\ano"));

            Assert.IsTrue(anoCatalogue.Exists());

            //should only be one (the id column
            Assert.AreEqual(1, anoCatalogue.CatalogueItems.Length);
            var idColInAnoDatabase = anoCatalogue.CatalogueItems[0].ColumnInfo;

            Assert.AreEqual("int", idColInAnoDatabase.Data_type);

            db.Drop();

            var exports = CatalogueRepository.GetAllObjects <ObjectExport>().Count();
            var imports = CatalogueRepository.GetAllObjects <ObjectImport>().Count();

            Assert.AreEqual(exports, imports);
            Assert.IsTrue(exports > 0);
        }
        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();
            }
        }
示例#19
0
        public void TestSimpleMerge()
        {
            var merger = new CohortIdentificationConfigurationMerger(CatalogueRepository);

            var cic1 = new CohortIdentificationConfiguration(CatalogueRepository, "cic1");
            var cic2 = new CohortIdentificationConfiguration(CatalogueRepository, "cic2");

            cic1.CreateRootContainerIfNotExists();
            var root1 = cic1.RootCohortAggregateContainer;

            root1.Name = "Root1";
            root1.SaveToDatabase();
            root1.AddChild(aggregate1, 1);

            cic2.CreateRootContainerIfNotExists();
            var root2 = cic2.RootCohortAggregateContainer;

            root2.Name = "Root2";
            root2.SaveToDatabase();
            root2.AddChild(aggregate2, 2);

            Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);
            Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            int numberOfCicsBefore = CatalogueRepository.GetAllObjects <CohortIdentificationConfiguration>().Count();

            var result = merger.Merge(new [] { cic1, cic2 }, SetOperation.UNION);

            //original should still be intact
            Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);
            Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            //the new merged set should contain both
            Assert.AreEqual(2, result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            Assert.IsFalse(result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Any(c => c.Equals(aggregate1)), "Expected the merge to include clone aggregates not the originals! (aggregate1)");
            Assert.IsFalse(result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Any(c => c.Equals(aggregate2)), "Expected the merge to include clone aggregates not the originals! (aggregate2)");

            // Now should be a new one
            Assert.AreEqual(numberOfCicsBefore + 1, CatalogueRepository.GetAllObjects <CohortIdentificationConfiguration>().Count());

            var newCicId = result.ID;

            // Should have the root containers of the old configs
            Assert.AreEqual("Root2", result.RootCohortAggregateContainer.GetSubContainers()[0].Name);
            Assert.AreEqual("Root1", result.RootCohortAggregateContainer.GetSubContainers()[1].Name);

            // And should have
            Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate2", result.RootCohortAggregateContainer.GetSubContainers()[0].GetAggregateConfigurations()[0].Name);
            Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate1", result.RootCohortAggregateContainer.GetSubContainers()[1].GetAggregateConfigurations()[0].Name);

            Assert.AreEqual($"Merged cics (IDs {cic1.ID},{cic2.ID})", result.Name);

            Assert.IsTrue(cic1.Exists());
            Assert.IsTrue(cic2.Exists());
        }
示例#20
0
 private void DeleteRemants()
 {
     foreach (
         Catalogue catalogue in
         CatalogueRepository.GetAllObjects <Catalogue>()
         .Where(c => c.Name.StartsWith("SuperMultiThreadedTestCatalogue")))
     {
         catalogue.DeleteInDatabase();
     }
 }
示例#21
0
        public void Test_RowVer()
        {
            var cata = new Catalogue(CatalogueRepository, "FFFF");

            //When we get all the Catalogues we should include cata
            Assert.Contains(cata, CatalogueRepository.GetAllObjects <Catalogue>());
            Assert.AreEqual(cata, CatalogueRepository.GetAllObjects <Catalogue>()[0]);
            Assert.AreNotSame(cata, CatalogueRepository.GetAllObjects <Catalogue>()[0]);

            //create a cache
            var rowVerCache = new RowVerCache <Catalogue>(CatalogueRepository);

            //should fill the cache
            cata = rowVerCache.GetAllObjects()[0];

            //should return the same instance
            Assert.AreSame(cata, rowVerCache.GetAllObjects()[0]);

            cata.DeleteInDatabase();
            Assert.IsEmpty(rowVerCache.GetAllObjects());

            //create some catalogues
            new Catalogue(CatalogueRepository, "1");
            new Catalogue(CatalogueRepository, "2");
            new Catalogue(CatalogueRepository, "3");

            //fill up the cache
            rowVerCache.GetAllObjects();

            //give it a fresh object
            var cata2 = new Catalogue(CatalogueRepository, "dddd");

            //fresh fetch for this
            Assert.Contains(cata2, rowVerCache.GetAllObjects());
            Assert.IsFalse(rowVerCache.GetAllObjects().Contains(cata));

            //change a value in the background but first make sure that what the cache has is a Equal but not reference to cata2
            Assert.IsFalse(rowVerCache.GetAllObjects().Any(o => ReferenceEquals(o, cata2)));
            Assert.IsTrue(rowVerCache.GetAllObjects().Any(o => Equals(o, cata2)));

            cata2.Name = "boom";
            cata2.SaveToDatabase();

            Assert.AreEqual(1, rowVerCache.GetAllObjects().Count(c => c.Name.Equals("boom")));

            cata2.Name = "vroom";
            cata2.SaveToDatabase();

            Assert.AreEqual(1, rowVerCache.GetAllObjects().Count(c => c.Name.Equals("vroom")));

            Assert.AreEqual(1, rowVerCache.GetAllObjects().Count(c => c.Name.Equals("vroom")));

            Assert.IsFalse(rowVerCache.Broken);
        }
        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();
            }
        }
示例#23
0
        /// <summary>
        /// Creates a new ANOTable called ANOMyTable in the Data Catalogue (and cleans SetUp any old copy kicking around), you will need to set it's properties and
        /// call PushToANOServerAsNewTable if you want to use it with an ANOTransformer
        /// </summary>
        /// <returns></returns>
        protected ANOTable GetANOTable()
        {
            const string name = "ANOMyTable";

            var toCleanup = CatalogueRepository.GetAllObjects <ANOTable>().SingleOrDefault(a => a.TableName.Equals(name));

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

            return(new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, name, "A"));
        }
示例#24
0
文件: Pipeline.cs 项目: 24418863/rdm
        private string GetUniqueCloneName()
        {
            var otherPipelines = CatalogueRepository.GetAllObjects <Pipeline>();

            string proposedName = $"{Name} (Clone)";
            int    suffix       = 1;

            while (otherPipelines.Any(p => proposedName.Equals(p.Name, StringComparison.CurrentCultureIgnoreCase)))
            {
                suffix++;
                proposedName = $"{Name} (Clone{suffix})";
            }

            return(proposedName);
        }
示例#25
0
        public void TestSimpleUnMerge()
        {
            var merger = new CohortIdentificationConfigurationMerger(CatalogueRepository);

            var cicInput = new CohortIdentificationConfiguration(CatalogueRepository, "cic99");

            cicInput.CreateRootContainerIfNotExists();
            var root = cicInput.RootCohortAggregateContainer;

            root.Name = "Root";
            root.SaveToDatabase();

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

            sub1.Order = 1;
            sub1.SaveToDatabase();

            var sub2 = new CohortAggregateContainer(CatalogueRepository, SetOperation.EXCEPT);

            sub2.Order = 2;
            sub2.SaveToDatabase();

            root.AddChild(sub1);
            root.AddChild(sub2);

            sub1.AddChild(aggregate1, 0);
            sub2.AddChild(aggregate2, 0);
            sub2.AddChild(aggregate3, 1);

            int numberOfCicsBefore = CatalogueRepository.GetAllObjects <CohortIdentificationConfiguration>().Count();

            var results = merger.UnMerge(root);

            // Now should be two new ones
            Assert.AreEqual(numberOfCicsBefore + 2, CatalogueRepository.GetAllObjects <CohortIdentificationConfiguration>().Count());
            Assert.AreEqual(2, results.Length);

            Assert.AreEqual(SetOperation.INTERSECT, results[0].RootCohortAggregateContainer.Operation);
            Assert.AreEqual(1, results[0].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            Assert.IsFalse(results[0].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Intersect(new [] { aggregate1, aggregate2, aggregate3 }).Any(), "Expected new aggregates to be new!");

            Assert.AreEqual(SetOperation.EXCEPT, results[1].RootCohortAggregateContainer.Operation);
            Assert.AreEqual(2, results[1].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            Assert.IsFalse(results[1].RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Intersect(new [] { aggregate1, aggregate2, aggregate3 }).Any(), "Expected new aggregates to be new!");
        }
示例#26
0
        public void DitaExtractorConstructor_ExtractTestCatalogue_FilesExist()
        {
            var testDir = _directoryHelper.Directory;

            //get rid of any old copies lying around
            Catalogue oldCatalogueVersion = CatalogueRepository.GetAllObjects <Catalogue>().SingleOrDefault(c => c.Name.Equals("DitaExtractorConstructor_ExtractTestCatalogue_FilesExist"));

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

            Catalogue ditaTestCatalogue = new Catalogue(CatalogueRepository, "DitaExtractorConstructor_ExtractTestCatalogue_FilesExist");//name of Catalogue

            ditaTestCatalogue.Acronym     = "DITA_TEST";
            ditaTestCatalogue.Description =
                "Test catalogue for the unit test DitaExtractorConstructor_ExtractTestCatalogue_FilesExist in file " +
                typeof(DitaExtractorTests).FullName + ".cs";
            ditaTestCatalogue.SaveToDatabase();


            try
            {
                DitaCatalogueExtractor extractor = new DitaCatalogueExtractor(CatalogueRepository, testDir);

                extractor.Extract(new ThrowImmediatelyDataLoadEventListener());

                //make sure the root mapping files exist for navigating around
                Assert.IsTrue(File.Exists(Path.Combine(testDir.FullName, "hic_data_catalogue.ditamap")));
                Assert.IsTrue(File.Exists(Path.Combine(testDir.FullName, "introduction.dita")));
                Assert.IsTrue(File.Exists(Path.Combine(testDir.FullName, "dataset.dita")));

                //make sure the catalogue we created is there
                FileInfo ditaCatalogueAsDotDitaFile = new FileInfo(Path.Combine(testDir.FullName, "ditaextractorconstructor_extracttestcatalogue_filesexist.dita"));//name of Dita file (for the Catalogue we just created)
                Assert.IsTrue(ditaCatalogueAsDotDitaFile.Exists);
                Assert.IsTrue(File.ReadAllText(ditaCatalogueAsDotDitaFile.FullName).Contains(ditaTestCatalogue.Description));
            }
            finally
            {
                ditaTestCatalogue.DeleteInDatabase();
                foreach (var file in testDir.GetFiles())
                {
                    file.Delete();
                }
            }
        }
示例#27
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();
            }
        }
示例#28
0
        public void ClearRemnants()
        {
            foreach (var e in CatalogueRepository.GetAllObjects <ObjectExport>())
            {
                e.DeleteInDatabase();
            }

            foreach (var i in CatalogueRepository.GetAllObjects <ObjectImport>())
            {
                i.DeleteInDatabase();
            }

            foreach (var j in CatalogueRepository.GetAllObjects <JoinInfo>())
            {
                j.DeleteInDatabase();
            }

            foreach (var p in CatalogueRepository.GetAllObjects <PreLoadDiscardedColumn>())
            {
                p.DeleteInDatabase();
            }

            foreach (var l in CatalogueRepository.GetAllObjects <Lookup>())
            {
                l.DeleteInDatabase();
            }

            //cleanup
            foreach (var t in CatalogueRepository.GetAllObjects <TableInfo>())
            {
                t.DeleteInDatabase();
            }

            foreach (var c in CatalogueRepository.GetAllObjects <Catalogue>())
            {
                c.DeleteInDatabase();
            }

            foreach (var a in CatalogueRepository.GetAllObjects <ANOTable>())
            {
                a.DeleteInDatabase();
            }
        }
        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();
            }
        }
示例#30
0
        protected override void OneTimeSetUp()
        {
            base.OneTimeSetUp();

            try
            {
                _directoryHelper = new TestDirectoryHelper(GetType());

                _directoryHelper.SetUp();

                Random random = new Random();

                //delete all catalogues with duplicate names
                Catalogue[] catalogues = CatalogueRepository.GetAllObjects <Catalogue>().ToArray();

                foreach (var cata in catalogues)
                {
                    if (catalogues.Count(c => c.Name.Equals(cata.Name)) > 1)
                    {
                        Console.WriteLine("Deleteing Catalogue Called " + cata.Name + " (because there are multiple Catalogues with this name) in database at end of ConnectionString:" + CatalogueRepository.ConnectionString);
                        cata.DeleteInDatabase();
                    }
                }

                //make sure all Catalogues have acroynms, if they dont then assign them a super random one
                foreach (Catalogue cata in CatalogueRepository.GetAllObjects <Catalogue>())
                {
                    if (string.IsNullOrWhiteSpace(cata.Acronym))
                    {
                        cata.Acronym = "RANDOMACRONYM_" + random.Next(10000);
                        cata.SaveToDatabase();
                    }
                }
            }
            catch (Exception e)
            {
                _setupException = e;
            }
        }