public void GetDyntaxaRevisionSpeciesFact_WhenDyntaxaRevisionSpeciesFactCreatedWithSpeciesFactExistsData_ThenCreatedRevisionSpeciesFactIsReturned()
        {
            WebDyntaxaRevisionSpeciesFact dyntaxaRevisionSpeciesFact, newDyntaxaRevisionSpeciesFact, getDyntaxaRevisionSpeciesFact;

            // Create test Dyntaxa revision species fact.
            dyntaxaRevisionSpeciesFact = WebDyntaxaSpeciesFactTestFactory.Create((Int32)TaxonId.Bear);
            const int STATUS_ID = 400;

            dyntaxaRevisionSpeciesFact.StatusId            = STATUS_ID;
            dyntaxaRevisionSpeciesFact.SpeciesFactExists   = true;
            dyntaxaRevisionSpeciesFact.OriginalStatusId    = 380;
            dyntaxaRevisionSpeciesFact.OriginalQualityId   = 150;
            dyntaxaRevisionSpeciesFact.OriginalReferenceId = 250;
            dyntaxaRevisionSpeciesFact.OriginalDescription = "test";

            newDyntaxaRevisionSpeciesFact = DyntaxaManager.CreateDyntaxaRevisionSpeciesFact(GetRevisionContext(), dyntaxaRevisionSpeciesFact);

            getDyntaxaRevisionSpeciesFact = DyntaxaManager.GetDyntaxaRevisionSpeciesFact(GetRevisionContext(), dyntaxaRevisionSpeciesFact.FactorId, dyntaxaRevisionSpeciesFact.TaxonId, dyntaxaRevisionSpeciesFact.RevisionId);
            Assert.IsNotNull(getDyntaxaRevisionSpeciesFact);
            Assert.AreEqual(STATUS_ID, getDyntaxaRevisionSpeciesFact.StatusId);
            Assert.IsTrue(dyntaxaRevisionSpeciesFact.SpeciesFactExists);
            Assert.AreEqual(380, dyntaxaRevisionSpeciesFact.OriginalStatusId);
            Assert.AreEqual(150, dyntaxaRevisionSpeciesFact.OriginalQualityId);
            Assert.AreEqual(250, dyntaxaRevisionSpeciesFact.OriginalReferenceId);
            Assert.AreEqual("test", dyntaxaRevisionSpeciesFact.OriginalDescription);
        }
        public void GetDyntaxaRevisionSpeciesFact_WhenWrongFactorId_ThenNullIsReturned()
        {
            WebDyntaxaRevisionSpeciesFact dyntaxaRevisionSpeciesFact, newDyntaxaRevisionSpeciesFact, getDyntaxaRevisionSpeciesFact;
            const int STATUS_ID = 400;

            // Create test Dyntaxa revision species fact.
            dyntaxaRevisionSpeciesFact             = WebDyntaxaSpeciesFactTestFactory.Create((Int32)TaxonId.Bear);
            dyntaxaRevisionSpeciesFact.FactorId    = (Int32)FactorId.SwedishHistory;
            dyntaxaRevisionSpeciesFact.RevisionId  = 24;
            dyntaxaRevisionSpeciesFact.IsPublished = false;
            dyntaxaRevisionSpeciesFact.StatusId    = STATUS_ID;
            newDyntaxaRevisionSpeciesFact          = DyntaxaManager.CreateDyntaxaRevisionSpeciesFact(GetRevisionContext(), dyntaxaRevisionSpeciesFact);

            getDyntaxaRevisionSpeciesFact = DyntaxaManager.GetDyntaxaRevisionSpeciesFact(
                GetRevisionContext(), (Int32)FactorId.SwedishOccurrence, (Int32)TaxonId.Bear, 24);
            Assert.IsNull(getDyntaxaRevisionSpeciesFact);
        }
 /// <summary>
 /// Gets dyntaxa revision species fact latest change for specific <paramref name="factorId" /> and
 /// <paramref name="taxonId" />  if any changes have been made in <paramref name="taxonRevisionId" />.
 /// </summary>
 /// <param name="clientInformation">The client information.</param>
 /// <param name="factorId">The factor id.</param>
 /// <param name="taxonId">The taxon id.</param>
 /// <param name="taxonRevisionId">The taxon revision.</param>
 /// <returns>
 /// Species fact information if it has changed during the revision; otherwise null.
 /// </returns>
 public WebDyntaxaRevisionSpeciesFact GetDyntaxaRevisionSpeciesFact(
     WebClientInformation clientInformation,
     Int32 factorId,
     Int32 taxonId,
     Int32 taxonRevisionId)
 {
     using (WebServiceContext context = new WebServiceContext(clientInformation))
     {
         try
         {
             return(DyntaxaManager.GetDyntaxaRevisionSpeciesFact(context, factorId, taxonId, taxonRevisionId));
         }
         catch (Exception exception)
         {
             WebServiceData.LogManager.LogError(context, exception);
             throw;
         }
     }
 }
        public void GetDyntaxaRevisionSpeciesFact_WhenRevisionSpeciesFactIsCreatedAndLaterChanged_ThenLastChangedRevisionSpeciesFactIsReturned()
        {
            WebDyntaxaRevisionSpeciesFact dyntaxaRevisionSpeciesFact1, getDyntaxaRevisionSpeciesFact1, dyntaxaRevisionSpeciesFact2, getDyntaxaRevisionSpeciesFact2, currentDyntaxaRevisionSpeciesFact;
            WebTaxonRevisionEvent         revisionEvent1, revisionEvent2;
            Int32 revisionId = 1;

            //-------------------------------------------------------------------
            // Create first dyntaxa revision species fact and revision event.
            dyntaxaRevisionSpeciesFact1             = WebDyntaxaSpeciesFactTestFactory.Create((Int32)TaxonId.Bear);
            dyntaxaRevisionSpeciesFact1.FactorId    = (Int32)FactorId.SwedishHistory;
            dyntaxaRevisionSpeciesFact1.RevisionId  = revisionId;
            dyntaxaRevisionSpeciesFact1.IsPublished = false;
            dyntaxaRevisionSpeciesFact1.StatusId    = 400;

            revisionEvent1 = new WebTaxonRevisionEvent()
            {
                CreatedBy    = 2,
                CreatedDate  = DateTime.Now,
                TypeId       = 1,
                RevisionId   = revisionId,
                AffectedTaxa = "Bear",
                OldValue     = "StatusId=Unknown",
                NewValue     = "StatusId=400"
            };
            revisionEvent1 = DyntaxaManager.CreateCompleteRevisionEvent(GetRevisionContext(), revisionEvent1);
            dyntaxaRevisionSpeciesFact1.RevisionEventId = revisionEvent1.Id;
            dyntaxaRevisionSpeciesFact1       = DyntaxaManager.CreateDyntaxaRevisionSpeciesFact(GetRevisionContext(), dyntaxaRevisionSpeciesFact1);
            currentDyntaxaRevisionSpeciesFact = DyntaxaManager.GetDyntaxaRevisionSpeciesFact(
                GetRevisionContext(), (Int32)FactorId.SwedishHistory, (Int32)TaxonId.Bear, revisionId);

            //Assert first Insert
            Assert.AreEqual(revisionEvent1.Id, dyntaxaRevisionSpeciesFact1.RevisionEventId);
            Assert.IsFalse(currentDyntaxaRevisionSpeciesFact.IsChangedInRevisionEventIdSpecified);
            Assert.AreEqual(400, currentDyntaxaRevisionSpeciesFact.StatusId);
            Assert.AreEqual(dyntaxaRevisionSpeciesFact1.StatusId, currentDyntaxaRevisionSpeciesFact.StatusId);

            //---------------------------------------------------------------------
            // Create second dyntaxa revision species fact and revision event.
            dyntaxaRevisionSpeciesFact2             = WebDyntaxaSpeciesFactTestFactory.Create((Int32)TaxonId.Bear);
            dyntaxaRevisionSpeciesFact2.FactorId    = (Int32)FactorId.SwedishHistory;
            dyntaxaRevisionSpeciesFact2.RevisionId  = revisionId;
            dyntaxaRevisionSpeciesFact2.IsPublished = false;
            dyntaxaRevisionSpeciesFact2.StatusId    = 450; // changed from 400 to 450.

            revisionEvent2 = new WebTaxonRevisionEvent()
            {
                CreatedBy    = 3, //Changed
                CreatedDate  = DateTime.Now,
                TypeId       = 1,
                RevisionId   = revisionId,
                AffectedTaxa = "Bear",
                OldValue     = "StatusId=400", //Changed
                NewValue     = "StatusId=450"  //Changed
            };
            revisionEvent2 = DyntaxaManager.CreateCompleteRevisionEvent(GetRevisionContext(), revisionEvent2);
            dyntaxaRevisionSpeciesFact2.RevisionEventId = revisionEvent2.Id;
            dyntaxaRevisionSpeciesFact2       = DyntaxaManager.CreateDyntaxaRevisionSpeciesFact(GetRevisionContext(), dyntaxaRevisionSpeciesFact2);
            currentDyntaxaRevisionSpeciesFact = DyntaxaManager.GetDyntaxaRevisionSpeciesFact(
                GetRevisionContext(), (Int32)FactorId.SwedishHistory, (Int32)TaxonId.Bear, revisionId);
            getDyntaxaRevisionSpeciesFact1 = DyntaxaManager.GetDyntaxaRevisionSpeciesFactById(GetRevisionContext(), dyntaxaRevisionSpeciesFact1.Id);
            getDyntaxaRevisionSpeciesFact2 = DyntaxaManager.GetDyntaxaRevisionSpeciesFactById(GetRevisionContext(), dyntaxaRevisionSpeciesFact2.Id);

            // Check values.
            Assert.AreEqual(450, currentDyntaxaRevisionSpeciesFact.StatusId);
            Assert.AreEqual(getDyntaxaRevisionSpeciesFact2.StatusId, currentDyntaxaRevisionSpeciesFact.StatusId);
            Assert.AreEqual(400, getDyntaxaRevisionSpeciesFact1.StatusId);
            Assert.AreNotEqual(getDyntaxaRevisionSpeciesFact1.StatusId, currentDyntaxaRevisionSpeciesFact.StatusId);

            Assert.AreEqual(revisionEvent1.Id, getDyntaxaRevisionSpeciesFact1.RevisionEventId);
            Assert.AreEqual(revisionEvent2.Id, getDyntaxaRevisionSpeciesFact1.ChangedInRevisionEventId);
            Assert.AreEqual(revisionEvent2.Id, currentDyntaxaRevisionSpeciesFact.RevisionEventId);
            Assert.IsFalse(currentDyntaxaRevisionSpeciesFact.IsChangedInRevisionEventIdSpecified);
        }