public void TestSearchForUsage() { //Get a Taxon that has usage details. BO.Taxonomy.BOTaxon AnimalKingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon UsageTaxon = GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Species, new CustomConditionDelegate(CustomConditionGetTaxonHavingUsage)); Assert.IsNotNull(UsageTaxon); BO.Taxonomy.BOUsage TaxonUsage = UsageTaxon.GetUsage() [0]; //Search using usage details to retreive the taxon first thought of. BO.Taxonomy.BOTaxonSearchResults AnimalSearchResults = null; mCommonCriteria.SearchForKingdomType = BO.SearchTaxonomy.SearchKingdomTypeEnum.Animal; mCommonCriteria.SearchForComponentType = BO.SearchTaxonomy.SearchableTaxonomyComponentEnum.Usage; BO.SearchTaxonomy.BOUsageCriteria UsageCriteria = new uk.gov.defra.Phoenix.BO.SearchTaxonomy.BOUsageCriteria(); UsageCriteria.LevelOfUseID = TaxonUsage.LevelID; UsageCriteria.PartID = TaxonUsage.PartID; UsageCriteria.UsageTypeID = TaxonUsage.TypeID; AnimalSearchResults = BO.Taxonomy.TaxonomySearch.SearchUsage(mCommonCriteria, UsageCriteria); Assert.IsTrue(AnimalSearchResults.Taxa.Length > 0); bool UsageTaxonMatchesSearchedTaxon = false; foreach (BO.Taxonomy.BOTaxon FoundTaxon in AnimalSearchResults.Taxa) { UsageTaxonMatchesSearchedTaxon = UsageTaxonMatchesSearchedTaxon | (UsageTaxon.Id == FoundTaxon.Id); } Assert.IsTrue(UsageTaxonMatchesSearchedTaxon); }
protected static BO.Taxonomy.BOTaxon[] GetTaxonDescendants(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant, CustomConditionTaxaDelegate CustomCondition) { System.Collections.ArrayList BadParents = new System.Collections.ArrayList(); BO.Taxonomy.BOTaxon[] Descendants = new BO.Taxonomy.BOTaxon [0]; BO.Taxonomy.BOTaxon Descendant = GetTaxonDescendant(Taxon, RequiredDescendant); //Get the parent of the found required type. BO.Taxonomy.BOTaxon DescendantParent = Descendant.GetParentTaxon(); bool DescendantsFound = false; while (DescendantParent != null & !DescendantsFound) { //Get the children of the parent. Descendants = DescendantParent.GetLowerTaxa(); if ((CustomCondition != null && CustomCondition(Descendants).Length == 0) & Descendants.Length == 0) { //This parent is no good so get another. BadParents.Add(DescendantParent); BO.Taxonomy.BOTaxon [] BadParentsArray = new BO.Taxonomy.BOTaxon [BadParents.Count]; BadParents.CopyTo(BadParentsArray); DescendantParent = GetTaxonDescendant(Taxon, DescendantParent.TaxonType, new CustomConditionDelegate(CustomConditionGetTaxonNotIn), BadParentsArray); } else { DescendantsFound = true; } } return(Descendants); }
public void TestRetrieveSummaryQuotaAllIsCallable() { //Get a Taxon that has Quotas. BO.Taxonomy.BOTaxon AnimalKingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon TaxonWithQuotas = GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Species, new CustomConditionDelegate(CustomConditionGetTaxonHavingSummaryQuotaAll)); Assert.IsNotNull(TaxonWithQuotas); }
public void TestCustomConditionGetTaxonNotIn() { BO.Taxonomy.BOTaxon Taxon = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon FirstChild = GetTaxonDescendant(Taxon, BO.Taxonomy.TaxonTypeEnum.Genus); Assert.IsNotNull(FirstChild); BO.Taxonomy.BOTaxon SecondChild = GetTaxonDescendant(Taxon, BO.Taxonomy.TaxonTypeEnum.Genus, new CustomConditionDelegate(CustomConditionGetTaxonNotIn), new object[] { FirstChild }); Assert.IsNotNull(SecondChild); Assert.AreNotSame(FirstChild.Id, SecondChild.Id, "Child taxa are the same. Expected different taxa."); }
public void TestStockNameParents() { //Only species can have stock names. BO.Taxonomy.BOTaxon AnimalKingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); Assert.IsNull(GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Phylum, new CustomConditionDelegate(CustomConditionGetTaxonHavingStock))); Assert.IsNull(GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Class, new CustomConditionDelegate(CustomConditionGetTaxonHavingStock))); Assert.IsNull(GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Order, new CustomConditionDelegate(CustomConditionGetTaxonHavingStock))); Assert.IsNull(GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Family, new CustomConditionDelegate(CustomConditionGetTaxonHavingStock))); Assert.IsNull(GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Genus, new CustomConditionDelegate(CustomConditionGetTaxonHavingStock))); }
protected static BO.Taxonomy.BOTaxon CustomConditionGetTaxonHavingStock(BO.Taxonomy.BOTaxon Taxon, object[] Taxa) { BO.Taxonomy.BOTaxon [] Stocks = Taxon.GetStockNames(); if (Stocks.Length > 0) { return(Taxon); } else { return(null); } }
public void TestGetTaxonDescendant() { BO.Taxonomy.BOTaxon Kingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Phylum).TaxonType, BO.Taxonomy.TaxonTypeEnum.Phylum, "Phylum requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Class).TaxonType, BO.Taxonomy.TaxonTypeEnum.Class, "Class requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Order).TaxonType, BO.Taxonomy.TaxonTypeEnum.Order, "Order requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Family).TaxonType, BO.Taxonomy.TaxonTypeEnum.Family, "Family requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Genus).TaxonType, BO.Taxonomy.TaxonTypeEnum.Genus, "Genus requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Species).TaxonType, BO.Taxonomy.TaxonTypeEnum.Species, "Species requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Epithet).TaxonType, BO.Taxonomy.TaxonTypeEnum.Epithet, "Epithet requested but not returned."); Assert.AreEqual(GetTaxonDescendant(Kingdom, BO.Taxonomy.TaxonTypeEnum.Stock).TaxonType, BO.Taxonomy.TaxonTypeEnum.Stock, "Stock requested but not returned."); }
public void TestPhylaBelongToKingdom() { //Get the child taxa. BO.Taxonomy.BOTaxon Kingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon[] LowerTaxa = Kingdom.GetLowerTaxa(); foreach (BO.Taxonomy.BOTaxon Taxon in LowerTaxa) { Assert.AreEqual(Taxon.ParentKingdomID, Kingdom.KingdomID, "Phylum does not belong to Kingdom."); Assert.AreEqual(Taxon.ParentTaxonID, Kingdom.TaxonId, "Phylum does not belong to Kingdom."); Assert.AreEqual(Taxon.ParentTaxonTypeID, Kingdom.TaxonTypeID, "Phylum does not belong to Kingdom."); } }
public void TestRetriveStockNames() { //Get a Taxon that has stock names. BO.Taxonomy.BOTaxon AnimalKingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon Parent = GetTaxonDescendant(AnimalKingdom, BO.Taxonomy.TaxonTypeEnum.Species, new CustomConditionDelegate(CustomConditionGetTaxonHavingStock)); BO.Taxonomy.BOTaxon [] StockTaxa = Parent.GetStockNames(); Assert.IsTrue(StockTaxa.Length > 0); foreach (BO.Taxonomy.BOTaxon Stock in StockTaxa) { Assert.IsTrue(Stock.TaxonType == BO.Taxonomy.TaxonTypeEnum.Stock); } }
protected static BO.Taxonomy.BOTaxon CustomConditionGetTaxonHavingUsage(BO.Taxonomy.BOTaxon Taxon, object[] Taxa) { BO.Taxonomy.BOUsage [] Usages = Taxon.GetUsage(); if (Usages.Length > 0) { return(Taxon); } else { return(null); } }
public void TestPhylaInAlphabeticalOrder() { //Get the child taxa. BO.Taxonomy.BOTaxon AnimalKingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon[] LowerTaxa = AnimalKingdom.GetLowerTaxa(); string PreviousName = string.Empty; foreach (BO.Taxonomy.BOTaxon Taxon in LowerTaxa) { Assert.GreaterThan(Taxon.LongScientificNameUnformatted, PreviousName); PreviousName = Taxon.LongScientificNameUnformatted; } }
public void TestSearchingForSpeciesReturnsSpecies() { BO.Taxonomy.BOTaxon Kingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxonSearchResults AnimalSearchResults = null; mCommonCriteria.SearchForKingdomType = BO.SearchTaxonomy.SearchKingdomTypeEnum.Animal; mCommonCriteria.SearchForComponentType = BO.SearchTaxonomy.SearchableTaxonomyComponentEnum.SpeciesTaxon; mStringCriteria.SearchString = "Accipiter"; //Narrow the search results so that there are fewer than the maximum allowed. AnimalSearchResults = BO.Taxonomy.TaxonomySearch.SearchTaxa(mCommonCriteria, mStringCriteria); foreach (BO.Taxonomy.BOTaxon Taxon in AnimalSearchResults.Taxa) { Assert.IsTrue(Taxon.TaxonType == BO.Taxonomy.TaxonTypeEnum.Species | Taxon.TaxonType == BO.Taxonomy.TaxonTypeEnum.Epithet | Taxon.TaxonType == BO.Taxonomy.TaxonTypeEnum.Stock); Assert.IsTrue(Taxon.KingdomID == Kingdom.KingdomID); } }
protected static BO.Taxonomy.BOTaxon GetTaxonDescendant(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant, CustomConditionDelegate CustomCondition, object[] CustomConditionArgs) { if (RequiredDescendant != BO.Taxonomy.TaxonTypeEnum.Stock) { //Check if the supplied Taxon is the one required. if (Taxon.TaxonType == RequiredDescendant) { //Check if there are any custom tests to run. if (CustomCondition != null) { return(CustomCondition(Taxon, CustomConditionArgs)); } else { return(Taxon); } } else //The supplied taxon is not the one required. { BO.Taxonomy.BOTaxon[] LowerTaxa = Taxon.GetLowerTaxa(); BO.Taxonomy.BOTaxon GotTaxon = null; //Check that there are children. if (LowerTaxa.Length > 0) { System.Int32 x = 0; //Loop all the child taxon until one is returned. while (GotTaxon == null & x < LowerTaxa.Length) { GotTaxon = GetTaxonDescendant(LowerTaxa[x], RequiredDescendant, CustomCondition, CustomConditionArgs); x++; } return(GotTaxon); } else //The supplied taxon does not have any children. { return(null); } } } else { throw new ApplicationException("Cannot search for Stock name as these do not form part of the hierarchy"); } }
public void TestKingdomGetChildrenEqualSearchedChildren() { //Get the child taxa. BO.Taxonomy.BOTaxon AnimalKingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon[] LowerTaxa = AnimalKingdom.GetLowerTaxa(); Assert.GreaterThan(LowerTaxa.Length, 1); //Search for the child taxa. BO.Taxonomy.BOTaxonSearchResults SearchResults = null; mCommonCriteria.SearchForKingdomType = BO.SearchTaxonomy.SearchKingdomTypeEnum.Animal; mCommonCriteria.SearchForComponentType = BO.SearchTaxonomy.SearchableTaxonomyComponentEnum.PhylumTaxon; mStringCriteria.SearchString = string.Empty; SearchResults = BO.Taxonomy.TaxonomySearch.SearchTaxa(mCommonCriteria, mStringCriteria); Assert.GreaterThan(SearchResults.Taxa.Length, 1); //Test the 2 sets of results. Assert.AreSame(LowerTaxa.Length, SearchResults.Taxa.Length, "The get results are different to the search results"); for (System.Int32 x = 0; x < LowerTaxa.Length; x++) { Assert.AreSame(LowerTaxa[x].LongScientificNameUnformatted, SearchResults.Taxa[x].LongScientificNameUnformatted, "The get results are different to the search results"); } }
/// <summary> /// This is a custom condition function that allows you to specify a not-in list of taxa when retrieving taxa using the GetTaxonDescendant function. /// </summary> /// <param name="Taxon"></param> /// <param name="TaxonListNotIn"></param> /// <returns>BOTaxon on succcess or null on failure.</returns> protected static BO.Taxonomy.BOTaxon CustomConditionGetTaxonNotIn(BO.Taxonomy.BOTaxon Taxon, object[] TaxonListNotIn) { bool TaxonInList = false; foreach (object CustomArg in TaxonListNotIn) { BO.Taxonomy.BOTaxon TaxonNotAllowed = (BO.Taxonomy.BOTaxon)CustomArg; if (TaxonNotAllowed.Id == Taxon.Id) { TaxonInList = true; } } if (TaxonInList == false) { return(Taxon); } else { return(null); } }
public void TestGetTaxonDescendants() { BO.Taxonomy.BOTaxon Kingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); Assert.IsTrue(GetTaxonDescendants(Kingdom, BO.Taxonomy.TaxonTypeEnum.Class, null).Length > 0); }
public void TestCustomConditionTaxaMultiple() { BO.Taxonomy.BOTaxon Kingdom = BO.Taxonomy.TaxonomySearch.GetAnimalKingdom(); BO.Taxonomy.BOTaxon [] Taxa = GetTaxonDescendants(Kingdom, BO.Taxonomy.TaxonTypeEnum.Class, new CustomConditionTaxaDelegate(CustomConditionTaxaMultiple)); Assert.IsTrue(Taxa.Length > 1); }
protected static BO.Taxonomy.BOTaxon CustomConditionGetTaxonHavingSummaryQuotaAll(BO.Taxonomy.BOTaxon Taxon, object[] Taxa) { if (Taxon.GetSummaryQuotaAll().Length > 0) { return(Taxon); } else { return(null); } }
/// <summary> /// This gets a taxon of the type specified that is a descendant of the supplied Taxon For example, supply a Kingdom Taxon and specify you want a species - if one exists a species from within the Kingdom will be returned. /// </summary> /// <param name="Taxon"></param> /// <param name="RequiredDescendant"></param> /// <returns>A Taxon or null</returns> protected static BO.Taxonomy.BOTaxon GetTaxonDescendant(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant) { return(GetTaxonDescendant(Taxon, RequiredDescendant, null)); }
protected static BO.Taxonomy.BOTaxon GetTaxonDescendant(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant, CustomConditionDelegate CustomCondition) { return(GetTaxonDescendant(Taxon, RequiredDescendant, CustomCondition, null)); }