Exemple #1
0
 private ArtDatabanken.Data.ArtDatabankenService.TaxonList GetTaxa()
 {
     if (_taxa.IsNull())
     {
         _taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxa(TaxonManagerTest.GetTaxaIds(), TaxonInformationType.Basic);
     }
     return(_taxa);
 }
 public static ArtDatabanken.Data.ArtDatabankenService.TaxonList GetTaxaList()
 {
     return(ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxa(TaxonManagerTest.GetTaxaIds(), TaxonInformationType.Basic));
 }
        public void UpdateSpeciesFacts()
        {
            DateTime oldUpdateDate;
            Int32    fieldIndex, oldReferenceId, oldQualityId;

            Data.ArtDatabankenService.Reference        reference;
            Data.ArtDatabankenService.SpeciesFact      changedSpeciesFact;
            Data.ArtDatabankenService.SpeciesFactField field;
            Data.ArtDatabankenService.SpeciesFactList  changedSpeciesFacts, speciesFacts;
            String oldUpdateUser;
            String stringValue;
            UserParameterSelection userParameterSelection;

            // Test delete of species fact.
            using (WebTransaction transaction = new WebTransaction(5))
            {
                // Delete some species facts.
                speciesFacts = GetSomeSpeciesFacts();
                foreach (Data.ArtDatabankenService.SpeciesFact speciesFact in speciesFacts)
                {
                    if (speciesFact.AllowManualUpdate)
                    {
                        for (fieldIndex = 0; fieldIndex < speciesFact.Fields.Count; fieldIndex++)
                        {
                            speciesFact.Fields[fieldIndex].Value = null;
                        }
                    }
                }
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(speciesFacts, ReferenceManagerTest.GetAReference());

                // Verify that delete has been done.
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(speciesFacts);
                foreach (Data.ArtDatabankenService.SpeciesFact speciesFact in speciesFacts)
                {
                    if (speciesFact.AllowManualUpdate)
                    {
                        Assert.IsTrue(!speciesFact.HasId ||
                                      (speciesFact.MainField.Type.DataType == FactorFieldDataTypeId.Enum));
                    }
                }
            }
            Thread.Sleep(6000);

            // Test creation of species fact.
            using (WebTransaction transaction = new WebTransaction(5))
            {
                // Create some species facts.
                changedSpeciesFacts    = new Data.ArtDatabankenService.SpeciesFactList();
                userParameterSelection = new UserParameterSelection();
                userParameterSelection.Taxa.Merge(ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxa(TaxonManagerTest.GetTaxaIds(), TaxonInformationType.Basic));
                userParameterSelection.Factors.Merge(Data.ArtDatabankenService.FactorManager.GetFactors(FactorManagerTest.GetFactorIds()));
                speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParameterSelection);
                foreach (Data.ArtDatabankenService.SpeciesFact speciesFact in speciesFacts)
                {
                    if (speciesFact.AllowManualUpdate &&
                        !speciesFact.HasId)
                    {
                        switch (speciesFact.MainField.Type.DataType)
                        {
                        case FactorFieldDataTypeId.Boolean:
                            speciesFact.MainField.Value = true;
                            break;

                        case FactorFieldDataTypeId.Double:
                            speciesFact.MainField.Value = 1;
                            break;

                        case FactorFieldDataTypeId.Int32:
                            speciesFact.MainField.Value = 1;
                            break;

                        case FactorFieldDataTypeId.String:
                            speciesFact.MainField.Value = "1";
                            break;

                        default:
                            continue;
                        }
                        changedSpeciesFacts.Add(speciesFact);
                    }
                }
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(speciesFacts, ReferenceManagerTest.GetAReference());

                // Verify that creation of species facts has been done.
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(speciesFacts);
                foreach (Data.ArtDatabankenService.SpeciesFact speciesFact in speciesFacts)
                {
                    if (changedSpeciesFacts.Exists(speciesFact))
                    {
                        Assert.IsTrue(speciesFact.HasId);
                        Assert.IsTrue(speciesFact.HasUpdateDate);
                        Assert.IsTrue(speciesFact.UpdateUserFullName.IsNotEmpty());
                        Assert.AreEqual(1, Int32.Parse(speciesFact.MainField.Value.ToString()));
                    }
                }
            }
            Thread.Sleep(6000);

            // Test update of data.
            using (WebTransaction transaction = new WebTransaction(5))
            {
                // Get species fact.
                changedSpeciesFacts = new Data.ArtDatabankenService.SpeciesFactList();
                foreach (Data.ArtDatabankenService.SpeciesFact speciesFact in GetSomeSpeciesFacts())
                {
                    if (speciesFact.AllowManualUpdate &&
                        speciesFact.HasId)
                    {
                        changedSpeciesFacts.Add(speciesFact);
                        break;
                    }
                }
                changedSpeciesFact = changedSpeciesFacts[0];

                // Test change of reference id.
                oldReferenceId = changedSpeciesFact.Reference.Id;
                oldUpdateUser  = changedSpeciesFact.UpdateUserFullName;
                reference      = Data.ArtDatabankenService.ReferenceManager.GetReferences()[3];
                changedSpeciesFact.Reference = reference;
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts, ReferenceManagerTest.GetAReference());
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts);
                Assert.AreNotEqual(oldReferenceId, changedSpeciesFact.Reference.Id);
                Assert.AreEqual(reference.Id, changedSpeciesFact.Reference.Id);

                // Test change of update date.
                oldUpdateDate = changedSpeciesFact.UpdateDate;
                changedSpeciesFact.Reference = Data.ArtDatabankenService.ReferenceManager.GetReferences()[4];
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts, ReferenceManagerTest.GetAReference());
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts);
                Assert.IsTrue(oldUpdateDate <= changedSpeciesFact.UpdateDate);

                // Test change of update user.
                Assert.AreNotEqual(oldUpdateUser, changedSpeciesFact.UpdateUserFullName);

                // Test change of field values.
                field       = changedSpeciesFact.Field5;
                stringValue = "4232";
                Assert.AreNotEqual(stringValue, field.Value.ToString());
                field.Value = stringValue;
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts, ReferenceManagerTest.GetAReference());
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts);
                Assert.IsTrue(field.HasValue);
                Assert.AreEqual(stringValue, field.Value.ToString());

                // Test change of quality.
                oldQualityId = changedSpeciesFact.Quality.Id;
                changedSpeciesFact.Quality = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactQualities()[5];
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts, ReferenceManagerTest.GetAReference());
                Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(changedSpeciesFacts);
                Assert.AreNotEqual(oldQualityId, changedSpeciesFact.Quality.Id);
                Assert.AreEqual(Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactQualities()[5].Id, changedSpeciesFact.Quality.Id);
            }
        }
        public void GetUserDataSetByParameterSelection()
        {
            UserDataSet            userDataSet = null, userDataSet2;
            UserParameterSelection userParmeterSelection;

            userParmeterSelection = new UserParameterSelection();

            userParmeterSelection.Taxa.Merge(ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxa(TaxonManagerTest.GetTaxaIds(), TaxonInformationType.Basic));
            Data.ArtDatabankenService.FactorList factors;
            factors = new Data.ArtDatabankenService.FactorList();
            factors.Add(Data.ArtDatabankenService.FactorManager.GetFactor(LANDSCAPE_FACTOR_ID));
            userParmeterSelection.Factors.Merge(factors);

            userDataSet = Data.ArtDatabankenService.SpeciesFactManager.GetUserDataSetByParameterSelection(userParmeterSelection);
            Assert.IsNotNull(userDataSet);
            Assert.IsTrue(userDataSet.SpeciesFacts.IsNotEmpty());
            Assert.IsTrue(userDataSet.SpeciesFacts.Count > 2);

            // Test problem where automatic SpeciesFact is
            // added to the UserDataSet but dependent
            // SpeicesFact is not in the UserDataSet.
            userParmeterSelection = new UserParameterSelection();
            userParmeterSelection.Taxa.Add(TaxonManagerTest.GetOneTaxon());
            userParmeterSelection.Factors.Add(Data.ArtDatabankenService.FactorManager.GetFactor(Data.ArtDatabankenService.FactorId.RedListCategoryAutomatic));
            userDataSet = Data.ArtDatabankenService.SpeciesFactManager.GetUserDataSetByParameterSelection(userParmeterSelection);
            Assert.IsTrue(userDataSet.SpeciesFacts.IsNotEmpty());
            Assert.IsTrue(userDataSet.Factors.Count > 30);

            // Test problem where periodic SpeciesFact are combined
            // with none default IndividualCategory.
            userParmeterSelection = new UserParameterSelection();
            userParmeterSelection.Taxa.Add(TaxonManagerTest.GetOneTaxon());
            userParmeterSelection.Factors.Add(Data.ArtDatabankenService.FactorManager.GetFactor(Data.ArtDatabankenService.FactorId.PopulationSize_Total));
            userDataSet = Data.ArtDatabankenService.SpeciesFactManager.GetUserDataSetByParameterSelection(userParmeterSelection);
            userParmeterSelection.IndividualCategories.Add(IndividualCategoryManager.GetIndividualCategory(INDIVIDUAL_CATEGORY_ID_IMAGO));
            userDataSet2 = Data.ArtDatabankenService.SpeciesFactManager.GetUserDataSetByParameterSelection(userParmeterSelection);
            Assert.AreEqual(userDataSet.SpeciesFacts.Count, userDataSet2.SpeciesFacts.Count);
        }