public void References()
        {
            UserParameterSelection userParameterSelection = GetUserParameterSelection();

            Assert.AreEqual(userParameterSelection.References.IsNotEmpty(), userParameterSelection.HasReferences);

            userParameterSelection.References.Merge(ReferenceManagerTest.GetSomeReferences());
            Assert.IsTrue(userParameterSelection.References.IsNotEmpty());
            Assert.IsTrue(userParameterSelection.References.Count > 6);
            Assert.IsTrue(userParameterSelection.HasReferences);
        }
Ejemplo n.º 2
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private Data.ArtDatabankenService.Reference GetReference()
        {
            return(ReferenceManagerTest.GetSomeReferences()[0]);
        }
        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 UpdateSpeciesFactsNullSpeciesFactsError()
 {
     Data.ArtDatabankenService.SpeciesFactManager.UpdateSpeciesFacts(null, ReferenceManagerTest.GetAReference());
 }
        public void GetSpeciesFactByUserParameterSelection()
        {
            FactorList factors;

            Data.ArtDatabankenService.IndividualCategoryList individualCategories;
            Int32 count;

            Data.ArtDatabankenService.PeriodList periods;
            ReferenceList references;

            Data.ArtDatabankenService.SpeciesFactList speciesFacts;
            Data.ArtDatabankenService.TaxonList       hosts, taxa;
            UserParameterSelection userParmeterSelection;

            userParmeterSelection = new UserParameterSelection();
            factors = FactorManagerTest.GetSomeFactors();
            hosts   = TaxonManagerTest.GetSomeTaxa();
            individualCategories = IndividualCategoryManagerTest.GetSomeIndividualCategories();
            periods    = PeriodManagerTest.GetSomePeriods();
            references = ReferenceManagerTest.GetSomeReferences();
            taxa       = hosts;

            userParmeterSelection.Taxa.Merge(taxa);
            speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParmeterSelection);
            Assert.IsTrue(speciesFacts.IsNotEmpty());
            count = speciesFacts.Count;

            userParmeterSelection.Factors.Merge(factors);
            speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParmeterSelection);
            if (speciesFacts.IsNotEmpty())
            {
                Assert.IsTrue(count > speciesFacts.Count);
            }
            userParmeterSelection.Factors.Clear();

            userParmeterSelection.Hosts.Merge(hosts);
            speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParmeterSelection);
            if (speciesFacts.IsNotEmpty())
            {
                Assert.IsTrue(count > speciesFacts.Count);
            }
            userParmeterSelection.Hosts.Clear();

            userParmeterSelection.IndividualCategories.Merge(individualCategories);
            speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParmeterSelection);
            if (speciesFacts.IsNotEmpty())
            {
                Assert.IsTrue(count > speciesFacts.Count);
            }
            userParmeterSelection.IndividualCategories.Clear();

            userParmeterSelection.Periods.Merge(periods);
            speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParmeterSelection);
            if (speciesFacts.IsNotEmpty())
            {
                Assert.IsTrue(count > speciesFacts.Count);
            }
            userParmeterSelection.Periods.Clear();

            userParmeterSelection.References.Merge(references);
            speciesFacts = Data.ArtDatabankenService.SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(userParmeterSelection);
            if (speciesFacts.IsNotEmpty())
            {
                Assert.IsTrue(count > speciesFacts.Count);
            }
            userParmeterSelection.References.Clear();
        }