public void TestOrphanCic() { var memory = new MemoryDataExportRepository(); var cic = new CohortIdentificationConfiguration(memory, "Mycic"); var p = new Project(memory, "my proj"); p.AssociateWithCohortIdentification(cic); //fetch the instance var cicAssoc = memory.GetAllObjects <ProjectCohortIdentificationConfigurationAssociation>().Single(); //relationship from p should resolve to the association link Assert.AreEqual(cicAssoc, p.ProjectCohortIdentificationConfigurationAssociations[0]); //relationship from p should resolve to the cic Assert.AreEqual(cic, p.GetAssociatedCohortIdentificationConfigurations()[0]); //in order to make it an orphan we have to suppress the system default behaviour of cascading across the deletion var obscure = memory.ObscureDependencyFinder as CatalogueObscureDependencyFinder; if (obscure != null) { obscure.OtherDependencyFinders.Clear(); } //make the assoc an orphan cic.DeleteInDatabase(); cicAssoc.ClearAllInjections(); //assoc should still exist Assert.AreEqual(cicAssoc, p.ProjectCohortIdentificationConfigurationAssociations[0]); Assert.IsNull(p.ProjectCohortIdentificationConfigurationAssociations[0].CohortIdentificationConfiguration); //relationship from p should resolve to the cic Assert.IsEmpty(p.GetAssociatedCohortIdentificationConfigurations()); //error should be reported in top right of program var ex = Assert.Throws <Exception>(() => new DataExportChildProvider(new RepositoryProvider(memory), null, new ThrowImmediatelyCheckNotifier(), null)); StringAssert.IsMatch(@"Failed to find Associated Cohort Identification Configuration with ID \d+ which was supposed to be associated with my proj", ex.Message); //but UI should still respond var childProvider = new DataExportChildProvider(new RepositoryProvider(memory), null, new IgnoreAllErrorsCheckNotifier(), null); //the orphan cic should not appear in the tree view under Project=>Cohorts=>Associated Cics var cohorts = childProvider.GetChildren(p).OfType <ProjectCohortsNode>().Single(); var cics = childProvider.GetChildren(cohorts).OfType <ProjectCohortIdentificationConfigurationAssociationsNode>().First(); Assert.IsEmpty(childProvider.GetChildren(cics)); }
private IEnumerable ChildrenGetter(object model) { var p = model as Project; var ec = model as ExtractionConfiguration; if (p != null) { return(_configurations = _childProvider.GetActiveConfigurationsOnly(p)); } if (ec != null) { return(_selectedDataSets = _childProvider.GetChildren(ec).OfType <ISelectedDataSets>()); } if (Equals(model, _globalsNode)) { return(_globals); } return(null); }