public void PreventDeletingCatalogueBecauseOfLinkedDatasetTest() { var obscura = new BetweenCatalogueAndDataExportObscureDependencyFinder(RepositoryLocator); var cata = new Catalogue(CatalogueRepository, "MyCata"); //catalogue exists in isolation so is deletable Assert.DoesNotThrow(()=>obscura.ThrowIfDeleteDisallowed(cata)); //there is a new dataset which is linked to Catalogue var dataset = new ExtractableDataSet(DataExportRepository,cata); //and suddenly we cannot delete the catalogue var ex = Assert.Throws<Exception>(() => obscura.ThrowIfDeleteDisallowed(cata)); Assert.IsTrue(ex.Message.Contains("Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); //also if we try to force through a delete it should behave in identical manner var ex2 = Assert.Throws<Exception>(cata.DeleteInDatabase); Assert.IsTrue(ex2.Message.Contains("Cannot delete Catalogue MyCata because there are ExtractableDataSets which depend on them ")); //now we delete the linked dataset dataset.DeleteInDatabase(); //and because there is now no longer a dataset dependency on the catalogue we can delete it Assert.DoesNotThrow(() => obscura.ThrowIfDeleteDisallowed(cata)); //and the delete works too cata.DeleteInDatabase(); //both objects still exist in memory of course but we should be able to see they have disapeared Assert.IsTrue(dataset.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyWasDeleted); Assert.IsTrue(cata.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyWasDeleted); }