private static void addABunchOfObservations(List <Observation_ado> obsList, int entries, Guid speciesId, Guid eventId)
 {
     for (int i = 0; i < entries; i++)
     {
         obsList.Add(Observation_ado.CreateObservation_ado(0, eventId, speciesId, LookupConstants.ObservationTypePointLess50m));
     }
 }
        /// <summary>
        /// Loads extra observations to improve testing
        /// </summary>
        /// <returns>List of <see cref="Observation_ado"></see> objects</returns>
        /// <param name="pointSurveyId"></param>
        public static List <Observation_ado> LoadExtraneousObservations(Guid pointSurveyId)
        {
            List <Observation_ado> conditionList = new List <Observation_ado>();

            Guid observationTypeId = SupplementalObservation.ObservationTypeGuid;

            Observation_ado extra1 = Observation_ado.CreateObservation_ado(0, pointSurveyId, new Guid(TestHelper.SPECIES_2_ID), observationTypeId);

            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToObservation_ado(extra1);
            });
            conditionList.Add(extra1);

            observationTypeId = PointCountBeyond50.ObservationTypeGuid;
            Observation_ado extra2 = Observation_ado.CreateObservation_ado(0, pointSurveyId, new Guid(TestHelper.SPECIES_2_ID), observationTypeId);

            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToObservation_ado(extra2);
            });
            conditionList.Add(extra2);

            observationTypeId = PointCountWithin50.ObservationTypeGuid;
            Observation_ado extra3 = Observation_ado.CreateObservation_ado(0, pointSurveyId, new Guid(TestHelper.SPECIES_2_ID), observationTypeId);

            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToObservation_ado(extra3);
            });
            conditionList.Add(extra3);

            return(conditionList);
        }
        public void t_PointCountBeyond50_DeleteTopX()
        {
            Guid   eventId            = TestHelper.TestGuid1;
            Guid   speciesId          = new Guid(TestHelper.SPECIES_2_ID);
            string speciesCode        = TestHelper.SPECIES_2_CODE;
            Guid   observationTypeId1 = LookupConstants.ObservationTypePointLess50m;
            Guid   observationTypeId2 = LookupConstants.ObservationTypeSupplemental;

            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                Observation_ado obs1 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId1);
                iba.AddToObservation_ado(obs1);
                Observation_ado ob2 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId1);
                iba.AddToObservation_ado(ob2);
                Observation_ado obs3 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId1);
                iba.AddToObservation_ado(obs3);
                Observation_ado obs4 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId2);
                iba.AddToObservation_ado(obs4);
            });

            ObservationMapper.DeleteTopX(eventId, observationTypeId1, speciesCode, 2);

            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var observationQuery = from observations in iba.Observation_ado select observations;
                Assert.IsNotNull(observationQuery, "observationQuery is null");
                Assert.AreEqual(2, observationQuery.Count(), "observationQuery has wrong count");
                Assert.AreEqual(1, observationQuery.Count(x => x.ObservationTypeId.Equals(observationTypeId1)), "wrong count for type 1");
                Assert.AreEqual(1, observationQuery.Count(x => x.ObservationTypeId.Equals(observationTypeId2)), "wrong count for type 2");
            }
        }
Exemple #4
0
        private static void multiBackdoorSetup(Guid eventId, Guid speciesId1, Guid speciesId2, string comments1, string comments2)
        {
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                Observation_ado obsSpecies1 = Observation_ado.CreateObservation_ado(0, eventId, speciesId1, PointCountWithin50.ObservationTypeGuid);
                obsSpecies1.Comments = comments1;
                iba.AddToObservation_ado(obsSpecies1);

                Observation_ado obsSpecies2 = Observation_ado.CreateObservation_ado(0, eventId, speciesId2, PointCountWithin50.ObservationTypeGuid);
                obsSpecies2.Comments = comments2;
                iba.AddToObservation_ado(obsSpecies2);

                Observation_ado obsSpecies3 = Observation_ado.CreateObservation_ado(0, eventId, speciesId2, PointCountBeyond50.ObservationTypeGuid);
                obsSpecies3.Comments = comments2;
                iba.AddToObservation_ado(obsSpecies3);

                Observation_ado obsSpecies4 = Observation_ado.CreateObservation_ado(0, eventId, speciesId2, PointCountBeyond50.ObservationTypeGuid);
                obsSpecies4.Comments = comments2;
                iba.AddToObservation_ado(obsSpecies4);
            });
        }
Exemple #5
0
        public void tGetSiteBySpecies_Supplemental()
        {
            Guid siteVisitId1 = TestHelper.TestGuid1;
            Guid surveyId1    = TestHelper.TestGuid4;

            DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Parse("2010-01-01"));
            DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId);
            DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                // Just 1 in week 1 site 1
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, siteVisitId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), SupplementalObservation.ObservationTypeGuid));
            });

            // Finally, can exercise the system under test
            using (IDataReader reader = iba.Data.Mappers.ResultsMapper.GetSiteBySpecies(new Guid(TestHelper.SPECIES_1_ID), 2010))
            {
                Assert.IsFalse(reader.Read());
            }
        }
        public void tGetSpeciesCount_Supplemental()
        {
            Guid siteVisitId1 = TestHelper.TestGuid1;
            Guid surveyId1    = TestHelper.TestGuid4;

            DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Now);
            DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId);
            DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                // Load species 1 into the database
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, siteVisitId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), SupplementalObservation.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid));
            });

            // Finally, can exercise the system under test
            DataSet set = ResultsMapper.GetSpeciesCount(DateTime.Now.Year);

            Assert.IsNotNull(set, "DataSet is null");
            Assert.AreEqual(1, set.Tables.Count, "There is not 1 table in the DataSet");

            DataTable table = set.Tables[0];


            Assert.AreEqual(1, table.Rows.Count, "There are not three rows in the results");

            // Results are supposed to be sorted by common name. That means order of Species1, Species3, Species2.
            DataRow species1 = table.Rows[0];

            Assert.AreEqual(TestHelper.SPECIES_1_COMMON, species1["CommonName"], "CommonName wrong row 1");
            Assert.AreEqual(TestHelper.SPECIES_1_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 1");
            Assert.AreEqual("1", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 1");
            Assert.AreEqual(TestHelper.SPECIES_1_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 1");
        }
        public void tGetSpeciesCount_Full()
        {
            Guid siteVisitId1 = TestHelper.TestGuid1;
            Guid siteVisitId2 = TestHelper.TestGuid2;
            Guid siteVisitId3 = TestHelper.TestGuid3;
            Guid surveyId1    = TestHelper.TestGuid4;
            Guid surveyId2    = TestHelper.TestGuid5;
            Guid surveyId3    = TestHelper.TestGuid6;

            DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Now);
            DbTestHelper.LoadSingleSiteVisit(siteVisitId2, _siteList[1].LocationId, DateTime.Now);
            DbTestHelper.LoadSingleSiteVisit(siteVisitId3, _siteList[2].LocationId, DateTime.Now);
            DbTestHelper.LoadSingleSiteVisit(surveyId1, _siteList[2].LocationId, DateTime.Now.AddYears(-1)); // extra
            DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId);
            DbTestHelper.LoadSamplingPoint(surveyId2, _siteList[1].LocationId);
            DbTestHelper.LoadSamplingPoint(surveyId3, _siteList[2].LocationId);
            DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            DbTestHelper.LoadSinglePointSurvey(surveyId2, siteVisitId2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            DbTestHelper.LoadSinglePointSurvey(surveyId3, siteVisitId3, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            DbTestHelper.LoadSinglePointSurvey(siteVisitId1, surveyId1, TestHelper.TestGuid1, DateTime.Now.AddYears(-1), DateTime.Now.AddYears(-1).AddHours(1)); // extra

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                // Load species 1 into the database
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountWithin50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid));

                // species 2
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_2_ID), PointCountBeyond50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_2_ID), PointCountBeyond50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_2_ID), PointCountBeyond50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_2_ID), PointCountWithin50.ObservationTypeGuid));

                // species 3
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_3_ID), PointCountWithin50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId2,
                                                                               new Guid(TestHelper.SPECIES_3_ID), PointCountWithin50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId3,
                                                                               new Guid(TestHelper.SPECIES_3_ID), PointCountWithin50.ObservationTypeGuid));

                // extra
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, siteVisitId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid));
            });

            // Finally, can exercise the system under test
            DataSet set = ResultsMapper.GetSpeciesCount(DateTime.Now.Year);

            Assert.IsNotNull(set, "DataSet is null");
            Assert.AreEqual(1, set.Tables.Count, "There is not 1 table in the DataSet");

            DataTable table = set.Tables[0];

            Assert.IsTrue(table.Columns.Contains("CommonName"), "Does not contain CommonName column");
            Assert.IsTrue(table.Columns.Contains("ScientificName"), "Does not contain ScientificName column");
            Assert.IsTrue(table.Columns.Contains("SpeciesCount"), "Does not contain SpeciesCount column");
            Assert.IsTrue(table.Columns.Contains("SpeciesId"), "Does not contain SpeciesId column");

            Assert.AreEqual(3, table.Rows.Count, "There are not three rows in the results");

            // Results are supposed to be sorted by common name. That means order of Species1, Species3, Species2.
            DataRow species1 = table.Rows[0];

            Assert.AreEqual(TestHelper.SPECIES_1_COMMON, species1["CommonName"], "CommonName wrong row 1");
            Assert.AreEqual(TestHelper.SPECIES_1_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 1");
            Assert.AreEqual("2", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 1");
            Assert.AreEqual(TestHelper.SPECIES_1_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 1");

            species1 = table.Rows[1];
            Assert.AreEqual(TestHelper.SPECIES_3_COMMON, species1["CommonName"], "CommonName wrong row 2");
            Assert.AreEqual(TestHelper.SPECIES_3_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 2");
            Assert.AreEqual("3", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 2");
            Assert.AreEqual(TestHelper.SPECIES_3_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 2");

            species1 = table.Rows[2];
            Assert.AreEqual(TestHelper.SPECIES_2_COMMON, species1["CommonName"], "CommonName wrong row 3");
            Assert.AreEqual(TestHelper.SPECIES_2_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 3");
            Assert.AreEqual("4", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 3");
            Assert.AreEqual(TestHelper.SPECIES_2_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 3");
        }
Exemple #8
0
        public void tGetSiteBySpecies_Full()
        {
            Guid siteVisitId1 = TestHelper.TestGuid1;
            Guid siteVisitId2 = TestHelper.TestGuid2;
            Guid siteVisitId3 = TestHelper.TestGuid3;
            Guid surveyId1    = TestHelper.TestGuid4;
            Guid surveyId2    = TestHelper.TestGuid5;
            Guid surveyId3    = TestHelper.TestGuid6;

            // Week 1 site 1, visit 1
            DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Parse("2010-01-01"));
            // Week 2 site 1, visit 2
            DbTestHelper.LoadSingleSiteVisit(siteVisitId2, _siteList[0].LocationId, DateTime.Parse("2010-01-09"));
            // Week 2 site 2, visit 1
            DbTestHelper.LoadSingleSiteVisit(siteVisitId3, _siteList[1].LocationId, DateTime.Parse("2010-01-08"));
            DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId);
            DbTestHelper.LoadSamplingPoint(surveyId2, _siteList[0].LocationId);
            DbTestHelper.LoadSamplingPoint(surveyId3, _siteList[1].LocationId);
            DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            DbTestHelper.LoadSinglePointSurvey(surveyId2, siteVisitId2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            DbTestHelper.LoadSinglePointSurvey(surveyId3, siteVisitId3, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));

            // Different year
            DbTestHelper.LoadSingleSiteVisit(surveyId1, _siteList[0].LocationId, DateTime.Parse("2009-06-06"));
            DbTestHelper.LoadSinglePointSurvey(siteVisitId1, surveyId1, TestHelper.TestGuid4, DateTime.Parse("2009-06-06 11:00 AM"), DateTime.Parse("2009-06-06 11:05 AM"));


            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                // Just 1 in week 1 site 1
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountWithin50.ObservationTypeGuid));
                // Two in week 2 site 1
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId2,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid));
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId2,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountWithin50.ObservationTypeGuid));
                // One beyond 50 in week 2 site 2
                iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId3,
                                                                               new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid));
            });

            // Finally, can exercise the system under test
            using (IDataReader reader = iba.Data.Mappers.ResultsMapper.GetSiteBySpecies(new Guid(TestHelper.SPECIES_1_ID), 2010))
            {
                // Results are supposed to be sorted by location name.
                Assert.IsTrue(reader.Read(), "missing row 1");
                Assert.AreEqual("Location 1", reader.GetString(reader.GetOrdinal("LocationName")), "LocationName wrong row 1");
                Assert.AreEqual("1", reader.GetValue(reader.GetOrdinal("Week")).ToString(), "Week wrong row 1");
                Assert.AreEqual("1", reader.GetValue(reader.GetOrdinal("SpeciesCount")).ToString(), "SpeciesCount wrong row 1");

                Assert.IsTrue(reader.Read(), "missing row 2");
                Assert.AreEqual("Location 1", reader.GetString(reader.GetOrdinal("LocationName")), "LocationName wrong row 2");
                Assert.AreEqual("2", reader.GetValue(reader.GetOrdinal("Week")).ToString(), "Week wrong row 2");
                Assert.AreEqual("2", reader.GetValue(reader.GetOrdinal("SpeciesCount")).ToString(), "SpeciesCount wrong row 2");

                Assert.IsTrue(reader.Read(), "missing row 3");
                Assert.AreEqual("Location 2", reader.GetString(reader.GetOrdinal("LocationName")), "LocationName wrong row 3");
                Assert.AreEqual("2", reader.GetValue(reader.GetOrdinal("Week")).ToString(), "Week wrong row 3");
                Assert.AreEqual("1", reader.GetValue(reader.GetOrdinal("SpeciesCount")).ToString(), "SpeciesCount wrong row 3");
            }
        }
        public void t_GetCommunityBreeding()
        {
            DateTime breedingdate1 = new DateTime(2010, 07, 01);
            DateTime breedingdate2 = new DateTime(2010, 06, 11);
            DateTime breedingdate3 = new DateTime(2009, 06, 11, 9, 32, 0);

            List <Location_ado> siteList    = DbTestHelper.LoadSites();
            SiteVisit_ado       visit1      = DbTestHelper.LoadSingleSiteVisit(TestHelper.TestGuid1, siteList[0].LocationId, breedingdate1);
            SiteVisit_ado       visit2      = DbTestHelper.LoadSingleSiteVisit(TestHelper.TestGuid2, siteList[1].LocationId, breedingdate2);
            SiteVisit_ado       extra       = DbTestHelper.LoadSingleSiteVisit(TestHelper.TestGuid3, siteList[0].LocationId, breedingdate3);
            PointSurvey_ado     surveyExtra = DbTestHelper.LoadSinglePointSurvey(TestHelper.TestGuid5, extra.EventId, TestHelper.TestGuid1, breedingdate3, breedingdate3.AddMinutes(5));
            PointSurvey_ado     survey1     = DbTestHelper.LoadSinglePointSurvey(TestHelper.TestGuid3, visit1.EventId, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            PointSurvey_ado     survey2     = DbTestHelper.LoadSinglePointSurvey(TestHelper.TestGuid4, visit2.EventId, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));

            // To make this test interesting, there must be several factors:
            // A supplemental to ignore
            // At least one observation inside of 50m
            // At least one outside of 50m for each species
            // A site that has count of zero therefore shouldn't show up
            // And relative abundance cannot calculate as zero
            Observation_ado supplementalSite1   = Observation_ado.CreateObservation_ado(0, visit1.EventId, new Guid(TestHelper.SPECIES_1_ID), LookupConstants.ObservationTypeSupplemental);
            Observation_ado site1Species1Beyond = Observation_ado.CreateObservation_ado(0, survey1.EventId, new Guid(TestHelper.SPECIES_1_ID), LookupConstants.ObservationTypePointBeyond50m);
            Observation_ado site1Species1Less   = Observation_ado.CreateObservation_ado(0, survey1.EventId, new Guid(TestHelper.SPECIES_1_ID), LookupConstants.ObservationTypePointLess50m);
            Observation_ado site1Species1Less2  = Observation_ado.CreateObservation_ado(0, survey1.EventId, new Guid(TestHelper.SPECIES_1_ID), LookupConstants.ObservationTypePointLess50m);
            Observation_ado site1Species2Beyond = Observation_ado.CreateObservation_ado(0, survey1.EventId, new Guid(TestHelper.SPECIES_2_ID), LookupConstants.ObservationTypePointBeyond50m);
            Observation_ado site1Species3Less   = Observation_ado.CreateObservation_ado(0, survey1.EventId, new Guid(TestHelper.SPECIES_3_ID), LookupConstants.ObservationTypePointLess50m);
            Observation_ado site1Species3Beyond = Observation_ado.CreateObservation_ado(0, survey1.EventId, new Guid(TestHelper.SPECIES_3_ID), LookupConstants.ObservationTypePointBeyond50m);
            Observation_ado site2Species3Beyond = Observation_ado.CreateObservation_ado(0, survey2.EventId, new Guid(TestHelper.SPECIES_3_ID), LookupConstants.ObservationTypePointBeyond50m);
            Observation_ado site2Species3Less   = Observation_ado.CreateObservation_ado(0, survey2.EventId, new Guid(TestHelper.SPECIES_3_ID), LookupConstants.ObservationTypePointLess50m);
            Observation_ado site2Species2Beyond = Observation_ado.CreateObservation_ado(0, survey2.EventId, new Guid(TestHelper.SPECIES_2_ID), LookupConstants.ObservationTypePointBeyond50m);
            Observation_ado site2Species2Less   = Observation_ado.CreateObservation_ado(0, survey2.EventId, new Guid(TestHelper.SPECIES_2_ID), LookupConstants.ObservationTypePointLess50m);
            Observation_ado extraObservation    = Observation_ado.CreateObservation_ado(0, surveyExtra.EventId, new Guid(TestHelper.SPECIES_1_ID), LookupConstants.ObservationTypePointBeyond50m);

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToObservation_ado(supplementalSite1);
                iba.AddToObservation_ado(site1Species1Beyond);
                iba.AddToObservation_ado(site1Species2Beyond);
                iba.AddToObservation_ado(site2Species3Beyond);
                iba.AddToObservation_ado(site1Species1Less);
                iba.AddToObservation_ado(site1Species1Less2);
                iba.AddToObservation_ado(site2Species3Less);
                iba.AddToObservation_ado(site1Species3Less);
                iba.AddToObservation_ado(site2Species2Beyond);
                iba.AddToObservation_ado(site2Species2Less);
                iba.AddToObservation_ado(extraObservation);
                iba.SaveChanges();
            });

            DataSet resultSet = mappers.ResultsMapper.GetCommunityBreeding(2010);

            Assert.IsNotNull(resultSet, "Resultset is null");
            Assert.AreEqual(1, resultSet.Tables.Count, "Wrong table count");


            DataTable table = resultSet.Tables[0];


            Assert.IsTrue(table.Columns.Contains("LocationName"), "Missing LocationName column");
            Assert.IsTrue(table.Columns.Contains("Richness"), "Missing Richness column");
            Assert.IsTrue(table.Columns.Contains("DiversityIndex"), "Missing DiversityIndex column");
            Assert.IsTrue(table.Columns.Contains("Evenness"), "Missing Evenness column");
            Assert.AreEqual(2, table.Rows.Count, "Wrong row count");

            var locationQuery = from locs
                                in table.AsEnumerable()
                                //where locs.Field<Guid>("LocationId").Equals(siteList[0].LocationId)
                                select new
            {
                LocationId   = locs.Field <Guid>("LocationId"),
                LocationName = locs.Field <string>("LocationName"),
                Richness     = locs.Field <int>("Richness"),
                Diversity    = locs.Field <decimal>("DiversityIndex"),
                Evenness     = locs.Field <decimal>("Evenness")
            };
            var result = from l1 in locationQuery where l1.LocationName.Equals(siteList[0].LocationName) select l1;

            Assert.AreEqual(1, result.Count(), "does not contain row for location 1");
            Assert.AreEqual(siteList[0].LocationId, result.First().LocationId, "wrong location ID for location 1");
            Assert.AreEqual(3, result.First().Richness, "Wrong Richness for location 1");
            Assert.AreEqual(0.8044m, result.First().Diversity, "Wrong DiversityIndex for location 1");
            Assert.AreEqual(0.7322m, result.First().Evenness, "Wrong Evenness for location 1");

            result = from l1 in locationQuery where l1.LocationName.Equals(siteList[1].LocationName) select l1;
            Assert.AreEqual(1, result.Count(), "does not contain row for location 2");
            Assert.AreEqual(siteList[1].LocationId, result.First().LocationId, "wrong location ID for location 2");
            Assert.AreEqual(2, result.First().Richness, "Wrong Richness for location 2");
            Assert.AreEqual(0.5828m, result.First().Diversity, "Wrong DiversityIndex for location 2");
            Assert.AreEqual(0.8409m, result.First().Evenness, "Wrong Evenness for location 2");
        }
Exemple #10
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");
            }
        }