public List <FiftyMeterDataEntry> SelectAllForEvent(Guid eventId)
        {
            List <FiftyMeterDataEntry> dataEntryList = new List <FiftyMeterDataEntry>();

            if (!eventId.Equals(Guid.Empty))
            {
                List <PointCountBeyond50> beyond50List = null;
                List <PointCountWithin50> less50List   = null;
                if (_state.PointSurvey.Id.Equals(eventId))
                {
                    beyond50List = _state.PointSurvey.Observations.OfType <PointCountBeyond50>().ToList();
                    less50List   = _state.PointSurvey.Observations.OfType <PointCountWithin50>().ToList();
                }
                else
                {
                    FiftyMeterPointSurvey survey = _state.SiteVisit.PointSurveys.Find(x => x.Id.Equals(eventId));
                    if (survey != null)
                    {
                        beyond50List = survey.Observations.OfType <PointCountBeyond50>().ToList();
                        less50List   = survey.Observations.OfType <PointCountWithin50>().ToList();
                    }
                }

                FiftyMeterDataEntryFactory.CreateEntriesFromPointCounts <PointCountBeyond50>(beyond50List, dataEntryList);
                FiftyMeterDataEntryFactory.CreateEntriesFromPointCounts <PointCountWithin50>(less50List, dataEntryList);
            }

            return(dataEntryList);
        }
        public void t_CountByPointSurveyId_Beyond50()
        {
            List <FiftyMeterDataEntry> dataEntryList = new List <FiftyMeterDataEntry>();
            List <PointCountBeyond50>  fiftyList     = new List <PointCountBeyond50>()
            {
                // 2 of species 1 at same point
                new PointCountBeyond50()
                {
                    EventId     = TestHelper.TestGuid1,
                    SpeciesCode = TestHelper.SPECIES_1_CODE
                },
                new PointCountBeyond50()
                {
                    EventId     = TestHelper.TestGuid1,
                    SpeciesCode = TestHelper.SPECIES_1_CODE
                },
                // 1 of species 1 at different point
                new PointCountBeyond50()
                {
                    EventId     = TestHelper.TestGuid2,
                    SpeciesCode = TestHelper.SPECIES_1_CODE
                },
                // 1 of different species at the second point
                new PointCountBeyond50()
                {
                    EventId     = TestHelper.TestGuid2,
                    SpeciesCode = TestHelper.SPECIES_2_CODE
                }
            };

            // Exercise the system under test
            FiftyMeterDataEntryFactory.CreateEntriesFromPointCounts <PointCountBeyond50>(fiftyList, dataEntryList);

            // There should be three entries:
            // 1. Species 1 at point 1 with count 2
            // 2. Species 1 at point 2 with count 1
            // 3. Species 2 at point 2 with count 1
            Assert.AreEqual(3, dataEntryList.Count(), "wrong number of results");
            FiftyMeterDataEntry entry1 = dataEntryList.Single(x => x.PointSurveyId.Equals(TestHelper.TestGuid1) &&
                                                              x.SpeciesCode.Equals(TestHelper.SPECIES_1_CODE));

            Assert.IsNotNull(entry1, "entry 1 missing");
            Assert.AreEqual(2, entry1.CountBeyond50, "entry 1 wrong count");

            FiftyMeterDataEntry entry2 = dataEntryList.Single(x => x.PointSurveyId.Equals(TestHelper.TestGuid2) &&
                                                              x.SpeciesCode.Equals(TestHelper.SPECIES_1_CODE));

            Assert.IsNotNull(entry2, "entry 1 missing");
            Assert.AreEqual(1, entry2.CountBeyond50, "entry 2 wrong count");

            FiftyMeterDataEntry entry3 = dataEntryList.Single(x => x.PointSurveyId.Equals(TestHelper.TestGuid2) &&
                                                              x.SpeciesCode.Equals(TestHelper.SPECIES_2_CODE));

            Assert.IsNotNull(entry3, "entry 1 missing");
            Assert.AreEqual(1, entry3.CountBeyond50, "entry 3 wrong count");
        }
        public void t_IncrementPointCounts_NullLists()
        {
            Guid pointSurveyId = TestHelper.TestGuid1;
            List <FiftyMeterDataEntry> entrylist = new List <FiftyMeterDataEntry>();

            FiftyMeterDataEntryFactory.IncrementPointCounts <PointCountBeyond50>(pointSurveyId, entrylist, null);

            Assert.IsNotNull(entrylist, "entrylist is null");
            Assert.AreEqual(0, entrylist.Count(), "entrylist does not contain zero objects");
        }
        /// <summary>
        /// Factory method to build and retrieve all observation information for a particular site visit, for use on the review page.
        /// </summary>
        /// <returns></returns>
        public static List <ReviewObservation> GetReviewList(IUserStateManager state, IGlobalMap globalMap)
        {
            // TODO: use of state should be moved to a presenter class
            List <ReviewObservation> reviewList = new List <ReviewObservation>();

            state.SiteVisit.PointSurveys.OrderBy(x => x.StartTimeStamp).ToList().ForEach(x =>
            {
                List <FiftyMeterDataEntry> entryList = new List <FiftyMeterDataEntry>();
                FiftyMeterDataEntryFactory.CreateEntriesFromPointCounts <PointCountBeyond50>(
                    x.Observations.OfType <PointCountBeyond50>().ToList <PointCountBeyond50>(), entryList);
                FiftyMeterDataEntryFactory.CreateEntriesFromPointCounts <PointCountWithin50>(
                    x.Observations.OfType <PointCountWithin50>().ToList <PointCountWithin50>(), entryList);

                entryList.ForEach(y =>
                {
                    reviewList.Add(new ReviewObservation(x, y, state, globalMap));
                });
            });

            return(reviewList.OrderBy(x => x.SamplingPointName).ToList());
        }
        public void t_IncrementPointCounts_Within50_3Entries()
        {
            Guid   pointSurveyId = TestHelper.TestGuid1;
            string comments1     = "Comments";
            string comments2     = string.Empty;
            List <FiftyMeterDataEntry> entryList = new List <FiftyMeterDataEntry>();
            List <PointCountWithin50>  countList = new List <PointCountWithin50>()
            {
                new PointCountWithin50()
                {
                    Comments    = comments1,
                    EventId     = pointSurveyId,
                    SpeciesCode = TestHelper.SPECIES_1_CODE
                },
                new PointCountWithin50()
                {
                    Comments    = comments1,
                    EventId     = pointSurveyId,
                    SpeciesCode = TestHelper.SPECIES_1_CODE
                },
                new PointCountWithin50()
                {
                    Comments    = comments2,
                    EventId     = pointSurveyId,
                    SpeciesCode = TestHelper.SPECIES_2_CODE
                }
            };


            // Exercising the system under test now...
            FiftyMeterDataEntryFactory.IncrementPointCounts <PointCountWithin50>(pointSurveyId, entryList, countList);

            // Validations -- the PointCountBeyond50 objects with same species code should be combined into
            // a single entry, and the third should be a second entry in the list.
            Assert.AreEqual(2, entryList.Count(), "entryList does not contain 2 entries");

            ValidateFiftyMeterDataEntryObject(pointSurveyId, comments1, entryList, "1", 0, 2, TestHelper.SPECIES_1_CODE);
            ValidateFiftyMeterDataEntryObject(pointSurveyId, comments2, entryList, "2", 0, 1, TestHelper.SPECIES_2_CODE);
        }