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); }
private void AuditParenthood(IMapsDirectlyToDatabaseTable parent, IMapsDirectlyToDatabaseTable child) { //make it shareable var export = _shareManager.GetNewOrExistingExportFor(parent); //share it to yourself where the child is the realisation of the share (this creates relationship in database) _shareManager.GetImportAs(export.SharingUID, child); //record in memory dictionary _parenthoodDictionary.Add(parent, child); }