/// <summary>
        /// Loads extra SiteVisit objects to improve testing
        /// </summary>
        /// <returns>
        /// List of <see cref="SiteVisit_ado"/> objects
        /// </returns>
        public static List <SiteVisit_ado> LoadExtraneousSiteVisits()
        {
            List <SiteVisit_ado> siteVisitlist = new List <SiteVisit_ado>();

            SiteVisit_ado extra1 = SiteVisit_ado.CreateSiteVisit_ado(TestHelper.TestGuid2, true, TestHelper.TestGuid2,
                                                                     DateTime.Now, DateTime.Now.AddHours(2), TestHelper.TestGuid3);

            extra1.ObserverId     = TestHelper.TestGuid4;
            extra1.RecorderId     = TestHelper.TestGuid3;
            extra1.EndConditionId = TestHelper.TestGuid4;
            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToSiteVisit_ado1(extra1);
            });
            siteVisitlist.Add(extra1);

            SiteVisit_ado extra2 = SiteVisit_ado.CreateSiteVisit_ado(TestHelper.TestGuid3, true, TestHelper.TestGuid1,
                                                                     DateTime.Now, DateTime.Now.AddHours(2), TestHelper.TestGuid3);

            extra1.ObserverId     = TestHelper.TestGuid4;
            extra1.RecorderId     = TestHelper.TestGuid3;
            extra2.EndConditionId = TestHelper.TestGuid4;
            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToSiteVisit_ado1(extra2);
            });
            siteVisitlist.Add(extra2);

            return(siteVisitlist);
        }
示例#2
0
        public void t_SiteVisit_Delete()
        {
            SiteVisit_ado setupObject = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = SiteVisit_ado.CreateSiteVisit_ado(TestHelper.TestGuid1, true, TestHelper.TestGuid2,
                                                                DateTime.Now, DateTime.Now.AddHours(2), TestHelper.TestGuid3);
                setupObject.ObserverId = TestHelper.TestGuid4;
                setupObject.RecorderId = TestHelper.TestGuid3;
                setupObject.Comments   = "asdf asdfasdf";
                iba.AddToSiteVisit_ado1(setupObject);
            });
            List <SiteVisit_ado> SiteVisitAdolist = DbTestHelper.LoadExtraneousSiteVisits();

            SiteVisitMapper.Delete(new SiteVisit()
            {
                Id = setupObject.EventId
            });

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var SiteVisitQuery = from SiteVisits in iba.SiteVisit_ado1 select SiteVisits;
                Assert.IsNotNull(SiteVisitQuery, "Query result is null");
                Assert.AreEqual(SiteVisitAdolist.Count(), SiteVisitQuery.Count(), "Wrong number of results in query");
                validateExtraSiteVisitAdos(SiteVisitAdolist, SiteVisitQuery);
            }
        }
        /// <summary>
        /// Loads a single PointSurvey to the database
        /// </summary>
        /// <param name="startDateTime"></param>
        /// <param name="locationId"></param>
        /// <param name="pointSurveyId">Guid</param>
        public static SiteVisit_ado LoadSingleSiteVisit(Guid siteVisitid, Guid locationId, DateTime startDateTime)
        {
            SiteVisit_ado ado = null;

            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                DateTime startDateTimeme = DateTime.Now;
                ado = SiteVisit_ado.CreateSiteVisit_ado(siteVisitid, true, locationId, startDateTime,
                                                        startDateTime.AddHours(1), TestHelper.TestGuid1);
                iba.AddToSiteVisit_ado1(ado);
            });
            return(ado);
        }
示例#4
0
        public void t_SiteVisit_Save_Update()
        {
            SiteVisit_ado setupObject = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = SiteVisit_ado.CreateSiteVisit_ado(TestHelper.TestGuid1, true, TestHelper.TestGuid2,
                                                                DateTime.Now, DateTime.Now.AddHours(2), TestHelper.TestGuid3);
                setupObject.ObserverId = TestHelper.TestGuid4;
                setupObject.RecorderId = TestHelper.TestGuid3;
                setupObject.Comments   = "asdf asdfasdf";
                iba.AddToSiteVisit_ado1(setupObject);
            });
            List <SiteVisit_ado> extraList = DbTestHelper.LoadExtraneousSiteVisits();

            // Setup object to be saved. Change everything except the Id.
            SiteVisit toSave = new SiteVisit()
            {
                Id                  = setupObject.EventId,
                EndTimeStamp        = setupObject.EndTime.AddHours(1),
                IsDataEntryComplete = false,
                LocationId          = TestHelper.TestGuid4,
                ObserverId          = TestHelper.TestGuid3,
                RecorderId          = TestHelper.TestGuid2,
                StartTimeStamp      = setupObject.StartTime.AddHours(0.5),
                Comments            = "asdf asdfa sdf asdfasdfasdf"
            };

            // Execute the test
            SiteVisitMapper.Update(toSave);

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var SiteVisitQuery = from SiteVisits in iba.SiteVisit_ado1 select SiteVisits;
                Assert.IsNotNull(SiteVisitQuery, "Query result is null");
                Assert.AreEqual(extraList.Count() + 1, SiteVisitQuery.Count(), "Wrong number of results in query");
                SiteVisit_ado adoSiteVisit = SiteVisitQuery.First(x => x.EventId == TestHelper.TestGuid1);
                validateObjectEquality(toSave, adoSiteVisit);

                validateExtraSiteVisitAdos(extraList, SiteVisitQuery);
            }
        }
示例#5
0
        public void t_SiteVisit_Select_ByGuid()
        {
            SiteVisit_ado setupObject = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = SiteVisit_ado.CreateSiteVisit_ado(TestHelper.TestGuid1, true, TestHelper.TestGuid2,
                                                                DateTime.Now, DateTime.Now.AddHours(2), TestHelper.TestGuid3);
                setupObject.ObserverId = TestHelper.TestGuid4;
                setupObject.RecorderId = TestHelper.TestGuid3;
                setupObject.Comments   = "asdf asdfasdf";
                iba.AddToSiteVisit_ado1(setupObject);
            });
            List <SiteVisit_ado> extraList = DbTestHelper.LoadExtraneousSiteVisits();

            // Exercise the test
            SiteVisit resultObject = SiteVisitMapper.Select(setupObject.EventId);

            validateObjectEquality(resultObject, setupObject);
        }
示例#6
0
        public void t_BMDE_IncompleteSurvey()
        {
            DbTestHelper.LoadSinglePerson(PersonFirstName, PersonLastName, PersonGuid);
            List <Location_ado> locations = DbTestHelper.LoadExtraneousLocations();

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                DateTime startDateTimeme = DateTime.Now;
                SiteVisit_ado ado        = SiteVisit_ado.CreateSiteVisit_ado(SiteVisitGuid, true, locations[0].LocationId, DateTime.Now.AddHours(-1),
                                                                             DateTime.Now, TestHelper.TestGuid1);
                ado.IsDataEntryComplete = false;    // force incompletion
                iba.AddToSiteVisit_ado1(ado);
            });

            Location_ado point = locations.First(x => x.ParentLocationId != null);

            DbTestHelper.LoadSinglePointSurvey(PointSurveyGuid, SiteVisitGuid, point.LocationId, DateTime.Now, DateTime.Now.AddHours(1));

            DbTestHelper.LoadExtraneousObservations(PointSurveyGuid);

            string bmde = ResultsMapper.GetBMDE();

            Assert.AreEqual(string.Empty, bmde);
        }
示例#7
0
        [Ignore] // this is getting an XML error and it is not worth trying to fix it right now. 2014-12-26.
        public void t_BMDE_CompleteSurvey_TwoObservations()
        {
            DbTestHelper.LoadSinglePerson(PersonFirstName, PersonLastName, PersonGuid);
            List <Location_ado> locations = DbTestHelper.LoadExtraneousLocations();

            DateTime startDate   = DateTime.Now.AddHours(-2);
            DateTime endDate     = DateTime.Now;
            DateTime surveyDate  = endDate.AddMinutes(-5);
            DateTime surveyDate2 = surveyDate.AddMinutes(-5);

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                DateTime startDateTimeme = DateTime.Now;
                SiteVisit_ado ado        = SiteVisit_ado.CreateSiteVisit_ado(SiteVisitGuid, true, locations[0].LocationId, startDate,
                                                                             endDate, TestHelper.TestGuid1);
                ado.IsDataEntryComplete = true;
                ado.RecorderId          = PersonGuid;
                ado.ObserverId          = PersonGuid;
                iba.SiteVisit_ado1.AddObject(ado);
            });

            Location_ado point  = locations.First(x => x.ParentLocationId != null);
            Location_ado point2 = locations.Last();

            DbTestHelper.LoadSinglePointSurvey(PointSurveyGuid, SiteVisitGuid, point.LocationId, surveyDate, endDate);
            DbTestHelper.LoadSinglePointSurvey(PointSurveyGuid2, SiteVisitGuid, point2.LocationId, surveyDate2, surveyDate);

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                Observation_ado observation  = Observation_ado.CreateObservation_ado(0, PointSurveyGuid, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid);
                Observation_ado observation2 = Observation_ado.CreateObservation_ado(0, PointSurveyGuid, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid);
                Observation_ado observation3 = Observation_ado.CreateObservation_ado(0, PointSurveyGuid2, new Guid(TestHelper.SPECIES_2_ID), PointCountWithin50.ObservationTypeGuid);
                iba.Observation_ado.AddObject(observation);
                iba.Observation_ado.AddObject(observation2);
                iba.Observation_ado.AddObject(observation3);
            });

            string        bmde     = ResultsMapper.GetBMDE();
            ASCIIEncoding encoding = new ASCIIEncoding();

            using (MemoryStream stream = new MemoryStream(encoding.GetBytes(bmde)))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ObservationList));
                serializer.UnknownAttribute   += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                serializer.UnknownElement     += new XmlElementEventHandler(serializer_UnknownElement);
                serializer.UnknownNode        += new XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnreferencedObject += new UnreferencedObjectEventHandler(serializer_UnreferencedObject);
                ObservationList obslist = (ObservationList)serializer.Deserialize(stream);

                Assert.AreEqual(2, obslist.Observation.Count(), "wrong Observation count");
                ObservationListObservation actual = obslist.Observation[0];
                Assert.AreEqual("Yes", actual.AllIndividualsReported, "AllIndividualsReported");
                Assert.AreEqual("observation", actual.BasisOfRecord, "BasisOfRecord");
                Assert.IsTrue(!string.IsNullOrEmpty(actual.CatalogNumber), "CatalogNumber");
                Assert.AreEqual(PersonFirstName + " " + PersonLastName, actual.Collector, "Collector");
                Assert.AreEqual(TestHelper.SPECIES_1_COMMON, actual.CommonName, "CommonName");
                Assert.AreEqual("North America", actual.Continent, "Continent");
                Assert.AreEqual("null", actual.CoordinateUncertainty, "CoordinateUncertainty");
                Assert.AreEqual("United States of America", actual.Country, "Country");
                Assert.AreEqual(startDate.Day, actual.DayCollected, "DayCollected");
                Assert.AreEqual(point.Latitude.Value, actual.DecimalLatitude, "DecimalLatitude");
                Assert.AreEqual(point.Longitude, actual.DecimalLongitude, "DecimalLongitude");
                Assert.AreEqual("Unlimited", actual.DistanceFromObserverMax, "DistanceFromObserverMax");
                Assert.AreEqual("50 m", actual.DistanceFromObserverMin, "DistanceFromObserverMin");
                Assert.AreEqual((endDate - surveyDate).TotalHours.ToString("00.00"), actual.DurationInHours.ToString("00.00"), "DurationInHours");
                string genus   = TestHelper.SPECIES_1_SCIENTIFIC.Split(' ')[0];
                string species = TestHelper.SPECIES_1_SCIENTIFIC.Split(' ')[1];
                Assert.AreEqual(genus, actual.Genus, "Genus");
                Assert.AreEqual(startDate.DayOfYear, actual.JulianDay, "JulianDay");
                Assert.AreEqual(point.LocationName, actual.Locality, "Locality");
                Assert.AreEqual(startDate.Month, actual.MonthCollected, "MonthCollected");
                Assert.AreEqual(1, actual.NumberOfObservers, "NumberOfObservers");
                Assert.AreEqual(2, actual.ObservationCount, "ObservationCount");
                Assert.AreEqual(startDate.ToString("MM/dd/yyyy"), actual.ObservationDate, "ObservationDate");
                Assert.AreEqual("decimal degrees", actual.OriginalCoordinateSystem, "OriginalCoordinateSystem");
                Assert.AreEqual("Homayoun, T. Z. and R. B. Blair. 2009. Citizen-Science Monitoring of Landbirds in the Mississippi River Twin Cities Important Bird Area. Pages 607-616 in T.D., Rich, C. Arizmendi, D. Demarest and C. Thompson, editors. Tundra to Tropics: Connecting Birds, Habitats and People. Proceedings of the 4th International Partners in Flight Conference, 13-16 February 2008, McAllen, TX. Partners in Flight.", actual.ProtocolReference, "ProtocolReference");
                Assert.AreEqual("Point Count", actual.ProtocolType, "ProtocolType");
                Assert.AreEqual("http://www.partnersinflight.org/pubs/McAllenProc/articles/PIF09_Monitoring/Homayoun_PIF09.pdf", actual.ProtocolURL, "ProtocolURL");
                Assert.AreEqual("Restricted", actual.RecordPermissions, "RecordPermissions");
                Assert.AreEqual(locations[0].LocationId.ToString().ToUpper(), actual.RouteIdentifier, "RouteIdentifier");
                Assert.AreEqual(PointSurveyGuid.ToString().ToUpper(), actual.SamplingEventIdentifier, "SamplingEventIdentifier");
                Assert.AreEqual(TestHelper.SPECIES_1_SCIENTIFIC, actual.ScientificName, "ScientificName");
                Assert.AreEqual(TestHelper.SPECIES_1_CODE, actual.SpeciesCode, "SpeciesCode");
                Assert.AreEqual(species, actual.SpecificEpithet, "SpecificEpithet");
                Assert.AreEqual("Minnesota", actual.StateProvince, "StateProvince");
                Assert.AreEqual(point.LocationId.ToString().ToUpper(), actual.SurveyAreaIdentifier, "SurveyAreaIdentifier");
                Assert.AreEqual((surveyDate.TimeOfDay.Hours + surveyDate.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeCollected.ToString("00.00"), "TimeCollected");
                Assert.AreEqual((endDate.TimeOfDay.Hours + endDate.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeObservationsEnded.ToString("00.00"), "TimeObservationsEnded");
                Assert.AreEqual(surveyDate.TimeOfDay.TotalHours.ToString("00.00"), actual.TimeObservationsStarted.ToString("00.00"), "TimeObservationsStarted");
                Assert.AreEqual(startDate.Year.ToString(), actual.YearCollected.ToString(), "YearCollected");

                actual = obslist.Observation[1];
                Assert.AreEqual("Yes", actual.AllIndividualsReported, "AllIndividualsReported");
                Assert.AreEqual("observation", actual.BasisOfRecord, "BasisOfRecord");
                Assert.IsTrue(!string.IsNullOrEmpty(actual.CatalogNumber), "CatalogNumber");
                Assert.AreEqual(PersonFirstName + " " + PersonLastName, actual.Collector, "Collector");
                Assert.AreEqual(TestHelper.SPECIES_2_COMMON, actual.CommonName, "CommonName");
                Assert.AreEqual("North America", actual.Continent, "Continent");
                Assert.AreEqual("null", actual.CoordinateUncertainty, "CoordinateUncertainty");
                Assert.AreEqual("United States of America", actual.Country, "Country");
                Assert.AreEqual(startDate.Day, actual.DayCollected, "DayCollected");
                Assert.AreEqual(point2.Latitude.Value, actual.DecimalLatitude, "DecimalLatitude");
                Assert.AreEqual(point2.Longitude, actual.DecimalLongitude, "DecimalLongitude");
                Assert.AreEqual("50 m", actual.DistanceFromObserverMax, "DistanceFromObserverMax");
                Assert.AreEqual("0 m", actual.DistanceFromObserverMin, "DistanceFromObserverMin");
                Assert.AreEqual((surveyDate - surveyDate2).TotalHours.ToString("00.00"), actual.DurationInHours.ToString("00.00"), "DurationInHours");
                genus   = TestHelper.SPECIES_2_SCIENTIFIC.Split(' ')[0];
                species = TestHelper.SPECIES_2_SCIENTIFIC.Split(' ')[1];
                Assert.AreEqual(genus, actual.Genus, "Genus");
                Assert.AreEqual(startDate.DayOfYear, actual.JulianDay, "JulianDay");
                Assert.AreEqual(point.LocationName, actual.Locality, "Locality");
                Assert.AreEqual(startDate.Month, actual.MonthCollected, "MonthCollected");
                Assert.AreEqual(1, actual.NumberOfObservers, "NumberOfObservers");
                Assert.AreEqual(1, actual.ObservationCount, "ObservationCount");
                Assert.AreEqual(startDate.ToString("MM/dd/yyyy"), actual.ObservationDate, "ObservationDate");
                Assert.AreEqual("decimal degrees", actual.OriginalCoordinateSystem, "OriginalCoordinateSystem");
                Assert.AreEqual("Homayoun, T. Z. and R. B. Blair. 2009. Citizen-Science Monitoring of Landbirds in the Mississippi River Twin Cities Important Bird Area. Pages 607-616 in T.D., Rich, C. Arizmendi, D. Demarest and C. Thompson, editors. Tundra to Tropics: Connecting Birds, Habitats and People. Proceedings of the 4th International Partners in Flight Conference, 13-16 February 2008, McAllen, TX. Partners in Flight.", actual.ProtocolReference, "ProtocolReference");
                Assert.AreEqual("Point Count", actual.ProtocolType, "ProtocolType");
                Assert.AreEqual("http://www.partnersinflight.org/pubs/McAllenProc/articles/PIF09_Monitoring/Homayoun_PIF09.pdf", actual.ProtocolURL, "ProtocolURL");
                Assert.AreEqual("Restricted", actual.RecordPermissions, "RecordPermissions");
                Assert.AreEqual(locations[0].LocationId.ToString().ToUpper(), actual.RouteIdentifier, "RouteIdentifier");
                Assert.AreEqual(PointSurveyGuid2.ToString().ToUpper(), actual.SamplingEventIdentifier, "SamplingEventIdentifier");
                Assert.AreEqual(TestHelper.SPECIES_2_SCIENTIFIC, actual.ScientificName, "ScientificName");
                Assert.AreEqual(TestHelper.SPECIES_2_CODE, actual.SpeciesCode, "SpeciesCode");
                Assert.AreEqual(species, actual.SpecificEpithet, "SpecificEpithet");
                Assert.AreEqual("Minnesota", actual.StateProvince, "StateProvince");
                Assert.AreEqual(point.LocationId.ToString().ToUpper(), actual.SurveyAreaIdentifier, "SurveyAreaIdentifier");
                Assert.AreEqual((surveyDate2.TimeOfDay.Hours + surveyDate2.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeCollected.ToString("00.00"), "TimeCollected");
                Assert.AreEqual((surveyDate.TimeOfDay.Hours + surveyDate.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeObservationsEnded.ToString("00.00"), "TimeObservationsEnded");
                Assert.AreEqual(surveyDate2.TimeOfDay.TotalHours.ToString("00.00"), actual.TimeObservationsStarted.ToString("00.00"), "TimeObservationsStarted");
                Assert.AreEqual(startDate.Year.ToString(), actual.YearCollected.ToString(), "YearCollected");
            }
        }