public void DumpAllIdentifiersInTable_Passes()
        {
            var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "surname")
            {
                Destination = DiscardedColumnDestination.StoreInIdentifiersDump,
                SqlDataType = "varchar(20)"
            };

            preDiscardedColumn1.SaveToDatabase();

            //give it the correct server
            tableInfoCreated.IdentifierDumpServer_ID = IdentifierDump_ExternalDatabaseServer.ID;
            tableInfoCreated.SaveToDatabase();

            IdentifierDumper dumper = new IdentifierDumper(tableInfoCreated);

            var chiToSurnameDictionary = new Dictionary <string, HashSet <string> >();

            try
            {
                dumper.Check(new AcceptAllCheckNotifier());

                DataTable dt = _bulkData.GetDataTable(1000);

                Assert.AreEqual(1000, dt.Rows.Count);
                Assert.IsTrue(dt.Columns.Contains("surname"));

                //for checking the final ID table has the correct values in
                foreach (DataRow row in dt.Rows)
                {
                    var chi = row["chi"].ToString();

                    if (!chiToSurnameDictionary.ContainsKey(chi))
                    {
                        chiToSurnameDictionary.Add(chi, new HashSet <string>());
                    }

                    chiToSurnameDictionary[chi].Add(row["surname"] as string);
                }

                dumper.CreateSTAGINGTable();
                dumper.DumpAllIdentifiersInTable(dt);
                dumper.DropStaging();

                //confirm that the surname column is no longer in the pipeline
                Assert.IsFalse(dt.Columns.Contains("surname"));

                //now look at the ids in the identifier dump and make sure they match what was in the pipeline before we sent it
                var server = IdentifierDump_Database.Server;
                using (var con = server.GetConnection())
                {
                    con.Open();

                    var cmd = server.GetCommand("Select * from " + "ID_" + BulkTestsData.BulkDataTable, con);
                    var r   = cmd.ExecuteReader();

                    //make sure the values in the ID table match the ones we originally had in the pipeline
                    while (r.Read())
                    {
                        if (!chiToSurnameDictionary[r["chi"].ToString()].Any())
                        {
                            Assert.IsTrue(r["surname"] == DBNull.Value);
                        }
                        else
                        {
                            Assert.IsTrue(chiToSurnameDictionary[r["chi"].ToString()].Contains(r["surname"] as string), "Dictionary did not contain expected surname:" + r["surname"]);
                        }
                    }
                    r.Close();

                    //leave the identifier dump in the way we found it (empty)
                    var tbl = IdentifierDump_Database.ExpectTable("ID_" + BulkTestsData.BulkDataTable);

                    if (tbl.Exists())
                    {
                        tbl.Drop();
                    }

                    tbl = IdentifierDump_Database.ExpectTable("ID_" + BulkTestsData.BulkDataTable + "_Archive");

                    if (tbl.Exists())
                    {
                        tbl.Drop();
                    }
                }
            }
            finally
            {
                preDiscardedColumn1.DeleteInDatabase();
                tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it
                tableInfoCreated.SaveToDatabase();
            }
        }
        public void DumpAllIdentifiersInTable_UnexpectedColumnFoundInIdentifierDumpTable()
        {
            var preDiscardedColumn1 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "surname");

            preDiscardedColumn1.Destination = DiscardedColumnDestination.StoreInIdentifiersDump;
            preDiscardedColumn1.SqlDataType = "varchar(20)";
            preDiscardedColumn1.SaveToDatabase();

            var preDiscardedColumn2 = new PreLoadDiscardedColumn(CatalogueRepository, tableInfoCreated, "forename");

            preDiscardedColumn2.Destination = DiscardedColumnDestination.StoreInIdentifiersDump;
            preDiscardedColumn2.SqlDataType = "varchar(50)";
            preDiscardedColumn2.SaveToDatabase();

            //give it the correct server
            tableInfoCreated.IdentifierDumpServer_ID = IdentifierDump_ExternalDatabaseServer.ID;
            tableInfoCreated.SaveToDatabase();

            IdentifierDumper dumper = new IdentifierDumper(tableInfoCreated);

            dumper.Check(new AcceptAllCheckNotifier());

            DiscoveredTable tableInDump = IdentifierDump_Database.ExpectTable("ID_" + BulkTestsData.BulkDataTable);

            Assert.IsTrue(tableInDump.Exists(), "ID table did not exist");


            var columnsInDump = tableInDump.DiscoverColumns().Select(c => c.GetRuntimeName()).ToArray();

            //works and creates table on server
            Assert.Contains("hic_validFrom", columnsInDump);
            Assert.Contains("forename", columnsInDump);
            Assert.Contains("chi", columnsInDump);
            Assert.Contains("surname", columnsInDump);

            //now delete it!
            preDiscardedColumn2.DeleteInDatabase();

            //now create a new dumper and watch it go crazy
            IdentifierDumper dumper2 = new IdentifierDumper(tableInfoCreated);

            var thrower = new ThrowImmediatelyCheckNotifier();

            thrower.ThrowOnWarning = true;

            try
            {
                var ex = Assert.Throws <Exception>(() => dumper2.Check(thrower));
                Assert.AreEqual("Column forename was found in the IdentifierDump table ID_BulkData but was not one of the primary keys or a PreLoadDiscardedColumn", ex.Message);
            }
            finally
            {
                //Drop all this stuff
                var server = IdentifierDump_Database.Server;
                using (var con = server.GetConnection())
                {
                    con.Open();

                    //leave the identifier dump in the way we found it (empty)
                    var cmdDrop = server.GetCommand("DROP TABLE ID_" + BulkTestsData.BulkDataTable, con);
                    cmdDrop.ExecuteNonQuery();

                    var cmdDropArchive = server.GetCommand("DROP TABLE ID_" + BulkTestsData.BulkDataTable + "_Archive", con);
                    cmdDropArchive.ExecuteNonQuery();
                }

                preDiscardedColumn1.DeleteInDatabase();
                tableInfoCreated.IdentifierDumpServer_ID = null;//reset it back to how it was when we found it
                tableInfoCreated.SaveToDatabase();
            }
        }