public void GetSpeciesFactsBySearchCriteriaFactFieldSearchCriteria()
        {
            // Test String species fact field condition in combination with Enum String.

            List <WebSpeciesFact>        speciesFacts1;
            WebSpeciesFactSearchCriteria searchCriteria;

            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(1001);
            searchCriteria.FieldLogicalOperator = LogicalOperator.Or;

            // Test List of Enums as String species fact field condition.
            searchCriteria.FieldSearchCriteria = new List <WebSpeciesFactFieldSearchCriteria>();
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = GetFactorField(52, "tal1");
            Assert.IsTrue(searchCriteria.FieldSearchCriteria[0].FactorField.IsEnumField, "Choose other factor field that has enum fields. I.e. tal1.");
            searchCriteria.FieldSearchCriteria[0].IsEnumAsString = false;
            searchCriteria.FieldSearchCriteria[0].Operator       = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].Values         = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add("1");
            searchCriteria.FieldSearchCriteria[0].Values.Add("2");

            // Test String species fact field condition.
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[1].FactorField = GetFactorField(52, "text2");
            searchCriteria.FieldSearchCriteria[1].Operator    = CompareOperator.Like;
            searchCriteria.FieldSearchCriteria[1].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[1].Values.Add("bedömd för adulter");

            // Test Double species fact field condition.
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[2].FactorField = GetFactorField(52, "tal2");
            searchCriteria.FieldSearchCriteria[2].Operator    = CompareOperator.GreaterOrEqual;
            searchCriteria.FieldSearchCriteria[2].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[2].Values.Add("11");

            // Test Double species fact field condition.
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[3].FactorField = GetFactorField(52, "tal3");
            searchCriteria.FieldSearchCriteria[3].Operator    = CompareOperator.LessOrEqual;
            searchCriteria.FieldSearchCriteria[3].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[3].Values.Add("22");

            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());
        }
        public void GetSpeciesFactsBySearchCriteria()
        {
            List <WebSpeciesFact>        speciesFacts1, speciesFacts2;
            WebSpeciesFactSearchCriteria searchCriteria;

            // Test factor data types.
            searchCriteria = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorDataTypeIds = new List <Int32>();
            searchCriteria.FactorDataTypeIds.Add(106); // SA_KvalitativaKaraktärer.
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(2547); // 2:e gångbenparet lång relativt kroppslängden, ben/kroppslängd kvot = 2-8
            speciesFacts2 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts1.Count > speciesFacts2.Count);

            // Test factors.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add((Int32)(FactorId.RedlistCategory));
            searchCriteria.PeriodIds = new List <Int32>();
            searchCriteria.PeriodIds.Add(2); // 2010
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test hosts.
            searchCriteria         = new WebSpeciesFactSearchCriteria();
            searchCriteria.HostIds = new List <Int32>();
            searchCriteria.HostIds.Add(102656); // Hedsidenbi.
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test include not valid hosts.
            // Hard to test since there are no host values
            // in database that belongs to not valid taxa.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(5);
            searchCriteria.IncludeNotValidHosts = false;
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(5);
            searchCriteria.IncludeNotValidHosts = true;
            speciesFacts2 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts2.Count >= speciesFacts1.Count);

            // Test include not valid taxa.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(5);
            searchCriteria.IncludeNotValidTaxa = false;
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(5);
            searchCriteria.IncludeNotValidTaxa = true;
            speciesFacts2 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts2.Count > speciesFacts1.Count);

            // Test individual categories.
            searchCriteria = new WebSpeciesFactSearchCriteria();
            searchCriteria.IndividualCategoryIds = new List <Int32>();
            searchCriteria.IndividualCategoryIds.Add(9); // Ungar (juveniler)
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());
            searchCriteria.IndividualCategoryIds.Add(10); // Vuxna (imago).
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test periods.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add((Int32)(FactorId.RedlistCategory));
            searchCriteria.PeriodIds = new List <Int32>();
            searchCriteria.PeriodIds.Add(1); // 2000
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());
            searchCriteria.PeriodIds.Add(2); // 2005
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test periods and individual categories.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.PeriodIds = new List <Int32>();
            searchCriteria.PeriodIds.Add(3);              // 2010
            searchCriteria.IndividualCategoryIds = new List <Int32>();
            searchCriteria.IndividualCategoryIds.Add(10); // Vuxna (imago).
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test taxa.
            searchCriteria          = new WebSpeciesFactSearchCriteria();
            searchCriteria.TaxonIds = new List <Int32>();
            searchCriteria.TaxonIds.Add((Int32)(TaxonId.DrumGrasshopper));
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test Boolean species fact field condition.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add((Int32)(FactorId.RedlistCategory));
            searchCriteria.FieldSearchCriteria = new List <WebSpeciesFactFieldSearchCriteria>();
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = GetFactorField(30, "tal2");
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add(Boolean.TrueString);
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test Float64 species fact field condition.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add(2547); // 2:e gångbenparet lång relativt kroppslängden, ben/kroppslängd kvot = 2-8
            searchCriteria.FieldSearchCriteria = new List <WebSpeciesFactFieldSearchCriteria>();
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = GetFactorField(106, "tal1");
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Greater;
            searchCriteria.FieldSearchCriteria[0].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add("0");
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria.FieldSearchCriteria[0].Operator = CompareOperator.Greater;
            searchCriteria.FieldSearchCriteria[0].Values   = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add("2");
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsEmpty());

            // Test Int32 species fact field condition.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add((Int32)(FactorId.RedlistCategory));
            searchCriteria.FieldSearchCriteria = new List <WebSpeciesFactFieldSearchCriteria>();
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = GetFactorField(30, "tal1");
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add(2.WebToString()); // CR
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[1].FactorField = GetFactorField(30, "tal1");
            searchCriteria.FieldSearchCriteria[1].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[1].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[1].Values.Add(3.WebToString()); // EN
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[2].FactorField = GetFactorField(30, "tal1");
            searchCriteria.FieldSearchCriteria[2].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[2].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[2].Values.Add(4.WebToString()); // VU
            searchCriteria.FieldLogicalOperator = LogicalOperator.Or;
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test String species fact field condition.
            searchCriteria           = new WebSpeciesFactSearchCriteria();
            searchCriteria.FactorIds = new List <Int32>();
            searchCriteria.FactorIds.Add((Int32)(FactorId.RedlistCategory));
            searchCriteria.FieldSearchCriteria = new List <WebSpeciesFactFieldSearchCriteria>();
            searchCriteria.FieldSearchCriteria.Add(new WebSpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = GetFactorField(30, "text1");
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].Values      = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add("VU");
            speciesFacts1 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria.FieldSearchCriteria[0].Operator = CompareOperator.Like;
            searchCriteria.FieldSearchCriteria[0].Values   = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add("%VU%");
            speciesFacts2 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts1.Count < speciesFacts2.Count);

            searchCriteria.FieldSearchCriteria[0].Operator = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].Values   = new List <String>();
            searchCriteria.FieldSearchCriteria[0].Values.Add("V'U");
            speciesFacts2 = SpeciesFactManager.GetSpeciesFactsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsEmpty());
        }