public void DeleteAReferencedValidationXML()
        {
            ColumnInfo    l2ColumnInfo;
            BulkTestsData testData = SetupTestData(out l2ColumnInfo);

            try
            {
                Validator.LocatorForXMLDeserialization = RepositoryLocator;

                var worked = Validator.LoadFromXml(testData.catalogue.ValidatorXML);

                //notice that it is the ID of the referenced column that is maintained not the name of it! that is because we need to use a data access portal to get the contents of the column which might be in a different table (and normally would be)
                Assert.IsFalse(testData.catalogue.ValidatorXML.Contains("previous_address_L2"));
                Assert.IsTrue(testData.catalogue.ValidatorXML.Contains(l2ColumnInfo.ID.ToString()));

                Assert.IsTrue(testData.catalogue.ValidatorXML.Contains("previous_address_L1"));

                //we expect the validation XML to find the reference
                ValidationXMLObscureDependencyFinder finder = new ValidationXMLObscureDependencyFinder(RepositoryLocator);

                //and explode
                Assert.Throws <ValidationXmlDependencyException>(() => finder.ThrowIfDeleteDisallowed(l2ColumnInfo));

                Assert.AreEqual(0, finder.BlackList.Count);

                //now clear the validation XML
                testData.catalogue.ValidatorXML = testData.catalogue.ValidatorXML.Insert(100, "I've got a lovely bunch of coconuts!");
                testData.catalogue.SaveToDatabase();

                //column info should be deleteable but only because we got ourselves onto the blacklist
                Assert.DoesNotThrow(() => finder.ThrowIfDeleteDisallowed(l2ColumnInfo));
                Assert.AreEqual(1, finder.BlackList.Count);

                testData.catalogue.ValidatorXML = "";
                testData.catalogue.SaveToDatabase();

                //column info should be deleteable now that we cleared the XML
                Assert.DoesNotThrow(() => finder.ThrowIfDeleteDisallowed(l2ColumnInfo));
            }
            finally
            {
                testData.DeleteCatalogue();
            }
        }
        public void TestGettingTheUsualSuspects()
        {
            ValidationXMLObscureDependencyFinder finder = new ValidationXMLObscureDependencyFinder(RepositoryLocator);

            //forces call to initialize
            finder.ThrowIfDeleteDisallowed(null);

            //this guy should be a usual suspect!
            Assert.IsTrue(finder.TheUsualSuspects.Any(s => s.Type == typeof(ReferentialIntegrityConstraint)));

            var testXML =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Validator xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
  <ItemValidators>
    <ItemValidator>
      <TargetProperty>previous_address_L1</TargetProperty>
      <SecondaryConstraints>
        <SecondaryConstraint xsi:type=""ReferentialIntegrityConstraint"">
          <Consequence xsi:nil=""true"" />
          <InvertLogic>true</InvertLogic>
          <OtherColumnInfoID>10029</OtherColumnInfoID>
        </SecondaryConstraint>
      </SecondaryConstraints>
    </ItemValidator>
  </ItemValidators>
</Validator>";

            bool kaizerSoze = false;

            foreach (Suspect suspect in finder.TheUsualSuspects)
            {
                string pattern = string.Format(suspect.Pattern, 10029);

                kaizerSoze = Regex.IsMatch(testXML, pattern, RegexOptions.Singleline);

                if (kaizerSoze)
                {
                    break;
                }
            }

            Assert.IsTrue(kaizerSoze);
        }