/// <summary> /// Get all taxon categories that could be used for a taxon. /// </summary> /// <param name="taxonManager">The taxon manager.</param> /// <param name="userContext">The user context.</param> /// <param name="taxon">Taxon.</param> /// <returns>All taxon categories that could be used for a taxon.</returns> public static IList <ITaxonCategory> GetPossibleTaxonCategories( this ITaxonManager taxonManager, IUserContext userContext, ITaxon taxon) { IList <ITaxonCategory> possibleCategories = taxonManager.GetTaxonCategories(userContext); IList <ITaxonCategory> originalList = new List <ITaxonCategory>(possibleCategories); // The taxon that we will search categories for ITaxon currentTaxon = taxon; // If taxon.Category = RANKLESS // Find nearest parent that is not RANKLESS and set the currentTaxon object to the parent taxon we found. while (currentTaxon.Category.Id == 52) { foreach (ITaxonRelation parent in currentTaxon.GetNearestParentTaxonRelations(userContext)) { if (parent.IsMainRelation == true) { currentTaxon = parent.ParentTaxon; } } } foreach (ITaxonRelation parent in currentTaxon.GetNearestParentTaxonRelations(userContext)) { possibleCategories = (from category in possibleCategories where category.SortOrder > parent.ChildTaxon.GetCheckedOutChangesTaxonProperties(userContext).TaxonCategory.SortOrder select category).ToList(); var genusCategory = taxonManager.GetTaxonCategory(userContext, 14); if (parent.ChildTaxon.GetCheckedOutChangesTaxonProperties(userContext).TaxonCategory.SortOrder < genusCategory.SortOrder) { // remove all with SortOrder higher than Genus.SortOrder possibleCategories = (from category in possibleCategories where category.SortOrder <= genusCategory.SortOrder select category).ToList(); } } foreach (var possibleCategory in originalList) { if (!possibleCategory.IsTaxonomic && !possibleCategories.Contains(possibleCategory)) { possibleCategories.Add(possibleCategory); } // Add category RANKLESS if (possibleCategory.Id == RANKLESS && !possibleCategories.Contains(possibleCategory)) { possibleCategories.Add(possibleCategory); } } return(possibleCategories); }
public ITaxon GetTaxon(IUserContext userContext, int taxonId) { if (taxonId == DyntaxaTestSettings.Default.TestTaxonId) { return(GetReferenceTaxon(userContext, taxonId)); } if (taxonId == DyntaxaTestSettings.Default.TestParentTaxonId) { ITaxon parentTaxon = GetReferenceParentTaxon(userContext, taxonId); foreach (ITaxonRelation parent in parentTaxon.GetNearestParentTaxonRelations(userContext)) { TaxonRelationList relations = new TaxonRelationList(); ITaxon grandParentTaxon = GetReferenceGrandParentTaxon(userContext, DyntaxaTestSettings.Default.TestParentTaxonId + 10); ITaxonRelation rel = new TaxonRelation() { ParentTaxon = grandParentTaxon, ValidFromDate = DateTime.Now, ValidToDate = new DateTime(2022, 1, 30), IsMainRelation = true, ReplacedInTaxonRevisionEventId = null }; relations.Add(rel); parent.ChildTaxon = grandParentTaxon; parent.ChildTaxon.SetParentTaxa(relations); } return(parentTaxon); } if (taxonId == DyntaxaTestSettings.Default.PsophusStridulusTaxonId) { return(GetReferenceTaxon(userContext, taxonId)); } if (taxonId == DyntaxaTestSettings.Default.ParnassiusApolloId) { return(GetReferenceTaxon(userContext, taxonId)); } return(null); }
public void DropParentPostTest() { using (ShimsContext.Create()) { // Arrange LoginApplicationUserAndSetSessionVariables(); // TODO this does not work; how do we set transactions to a user and shim them in code? Transaction = new ShimTransaction() { Commit = () => { return; }, }; TaxonController controller = new TaxonController(); string controllerName = "Taxon"; string actionName = "DropParent"; controller.ControllerContext = GetShimControllerContext(actionName, controllerName); ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString()); ITaxon refTaxon = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId); TaxonIdTuple taxonIdentifier = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id); SessionRevision = refTaxonRevision; SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId; SessionTaxonId = taxonIdentifier; refTaxon.GetNearestParentTaxonRelations(UserContextData).Add(new TaxonRelation() { ReplacedInTaxonRevisionEventId = null, CreatedBy = 1, CreatedDate = new DateTime(2011), ValidToDate = new DateTime(2022), IsMainRelation = false, Id = 55555 }); // Mock Controller // builder.InitializeController(controller); // Create model.... TaxonDropParentViewModel model = new TaxonDropParentViewModel(); model.TaxonId = DyntaxaTestSettings.Default.TestTaxonId.ToString(); model.RevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId.ToString(); model.SelectedTaxonList = new List <string>() { "55555" }; var addParentResult = controller.DropParent(model) as RedirectToRouteResult; // Test 1: Test Save button pressed // Assert Assert.IsNotNull(addParentResult); // Test that AddParent action is returned. Assert.AreEqual(refTaxon.Id.ToString(), addParentResult.RouteValues["TaxonId"]); Assert.AreEqual("DropParent", addParentResult.RouteValues["action"]); // Test 2: No new parent seleceted reload view // Act model.SelectedTaxonList = null; var addParentResult2 = controller.DropParent(model) as RedirectToRouteResult; // Assert Assert.IsNotNull(addParentResult2); // Test that AddParent action is returned. Assert.AreEqual(refTaxon.Id.ToString(), addParentResult2.RouteValues["taxonId"]); Assert.AreEqual("DropParent", addParentResult.RouteValues["action"]); } }