public void t_Site_Delete()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(new Guid("87606168-3ac7-402a-8ae6-4f6905555581"),
                                                           "locationName", LookupConstants.LocationTypeSite);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = null;
                iba.AddToLocation_ado(location);
            });
            List <Location_ado> locationlist = DbTestHelper.LoadExtraneousLocations();

            SiteMapper.Delete(new Site()
            {
                Id = location.LocationId
            });

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var siteQuery = from sites in iba.Site_ado select sites;
                Assert.IsNotNull(siteQuery, "Query result is null");
                Assert.AreEqual(extraSites(locationlist).Count(), siteQuery.Count(), "Wrong number of results in query");
                validateExtraLocations(locationlist, siteQuery);
            }
        }
 private void loadASite()
 {
     DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
     {
         Location_ado site = Location_ado.CreateLocation_ado(TestHelper.TestParentGuid, "Parent", LookupConstants.LocationTypeSite);
         iba.AddToLocation_ado(site);
     });
 }
        public void t_SamplingPointMapper_Save_Update()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location                  = Location_ado.CreateLocation_ado(TestHelper.TestGuid1, "locationName", LookupConstants.LocationTypePoint);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = TestHelper.TestParentGuid;
                iba.AddToLocation_ado(location);
            });
            List <Location_ado> extraList = DbTestHelper.LoadExtraneousLocations();

            // Setup object to be saved. Change everything except the Id.
            SamplingPoint site = new SamplingPoint()
            {
                GeoCoordinate = new Business.DataTypes.Coordinate()
                {
                    Latitude = new Business.DataTypes.Degree()
                    {
                        Value = location.Latitude.Value + 1M
                    },
                    Longitude = new Business.DataTypes.Degree()
                    {
                        Value = location.Longitude.Value + 1M
                    }
                },
                Id     = location.LocationId,
                Name   = location.LocationName + "asd",
                SiteId = TestHelper.TestParentGuid
            };

            // Execute the test
            SamplingPointMapper.Update(site);

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var siteQuery = from sites in iba.SamplingPoint_ado select sites;
                Assert.IsNotNull(siteQuery, "Query result is null");
                Assert.AreEqual(extraSamplingPoints(extraList).Count() + 1, siteQuery.Count(), "Wrong number of results in query");
                SamplingPoint_ado adoSite = siteQuery.First(x => x.LocationId == TestHelper.TestGuid1);
                validateObjectEquality(site, adoSite);

                // double check the other objects as well, must make sure they remain unchanged.
                foreach (Location_ado adoLocation in extraSamplingPoints(extraList))
                {
                    adoSite = siteQuery.First(x => x.LocationId == adoLocation.LocationId);
                    Assert.IsNotNull(adoSite, "There is no longer an object with id " + adoLocation.LocationId.ToString());
                    Assert.AreEqual(adoLocation.Latitude, adoSite.Latitude, "Extra " + adoSite.LocationId.ToString() + " Latitude mismatch");
                    Assert.AreEqual(adoLocation.Longitude, adoSite.Longitude, "Extra " + adoSite.LocationId.ToString() + " Longitude mismatch");
                    Assert.AreEqual(adoSite.LocationName, adoSite.LocationName, "Extra " + adoSite.LocationId.ToString() + " Locationname mismatch");
                }
            }
        }
        public static Location_ado LoadSamplingPoint(Guid pointId, Guid siteId)
        {
            Location_ado point1 = null;

            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                point1 = Location_ado.CreateLocation_ado(pointId, "Point " + pointId.ToString().Substring(0, 5),
                                                         LookupConstants.LocationTypePoint);
                iba.AddToLocation_ado(point1);
            });

            return(point1);
        }
        public void t_SamplingPointMapper_Delete()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(TestHelper.TestParentGuid,
                                                           "locationName", LookupConstants.LocationTypeSite);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = null;
                iba.AddToLocation_ado(location);
            });
            Location_ado pointAdo = null;

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                pointAdo = Location_ado.CreateLocation_ado(TestHelper.TestGuid1,
                                                           "pointName", LookupConstants.LocationTypePoint);
                location.ParentLocationId = TestHelper.TestParentGuid;
                iba.AddToLocation_ado(pointAdo);
            });
            List <Location_ado> extraList = DbTestHelper.LoadExtraneousLocations();


            SamplingPoint point = new SamplingPoint()
            {
                Id     = TestHelper.TestGuid1,
                SiteId = TestHelper.TestParentGuid
            };

            // Exercise the system under test
            SamplingPointMapper.Delete(point);

            // Validate that the one record was deleted but none others were
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var pointQuery = from points in iba.Location_ado select points;
                Assert.IsNotNull(pointQuery, "Query result is null");
                Assert.AreEqual(0, pointQuery.Count(x => x.LocationId == point.Id), "Point wasn't deleted");

                // Check to see if extra points and locations are still in the database
                foreach (Location_ado extra in extraList)
                {
                    Assert.AreEqual(1, pointQuery.Count(x => x.LocationId == extra.LocationId), "Location " + extra.LocationId.ToString() + " is no longer in the database.");
                }
                Assert.AreEqual(1, pointQuery.Count(x => x.LocationId == location.LocationId), "Parent was deleted");
            }
        }
        public void t_Site_Save_Update()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(TestHelper.TestGuid1,
                                                           "locationName", LookupConstants.LocationTypeSite);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = null;
                iba.AddToLocation_ado(location);
            });
            List <Location_ado> extraList = DbTestHelper.LoadExtraneousLocations();

            // Setup object to be saved. Change everything except the Id.
            Site site = new Site()
            {
                CodeName      = location.CodeName + "a",
                GeoCoordinate = new Business.DataTypes.Coordinate()
                {
                    Latitude = new Business.DataTypes.Degree()
                    {
                        Value = location.Latitude.Value + 1M
                    },
                    Longitude = new Business.DataTypes.Degree()
                    {
                        Value = location.Longitude.Value + 1M
                    }
                },
                Id   = location.LocationId,
                Name = location.LocationName + "asd"
            };

            // Execute the test
            SiteMapper.Update(site);

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var siteQuery = from sites in iba.Site_ado select sites;
                Assert.IsNotNull(siteQuery, "Query result is null");
                Assert.AreEqual(extraSites(extraList).Count() + 1, siteQuery.Count(), "Wrong number of results in query");
                Site_ado adoSite = siteQuery.First(x => x.LocationId == TestHelper.TestGuid1);
                validateObjectEquality(site, adoSite);

                validateExtraLocations(extraList, siteQuery);
            }
        }
        /// <summary>
        /// Loads extra records into the Location table, useful for insuring that selects and updates are truly updating the right
        /// record, rather than all records (unless ALL is what was intended).
        /// </summary>
        public static List <Location_ado> LoadExtraneousLocations()
        {
            List <Location_ado> locationList = new List <Location_ado>();

            Location_ado extra1 = null;

            LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                extra1 = Location_ado.CreateLocation_ado(TestHelper.TestGuid2,
                                                         "locationName", LookupConstants.LocationTypeSite);
                extra1.CodeName         = "ex1";
                extra1.Latitude         = 89.3M;
                extra1.Longitude        = 90.10093M;
                extra1.ParentLocationId = null;
                iba.AddToLocation_ado(extra1);
            });
            locationList.Add(extra1);

            Location_ado extra2 = null;

            LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                extra2 = Location_ado.CreateLocation_ado(TestHelper.TestGuid3,
                                                         "locationName", LookupConstants.LocationTypeSite);
                extra2.CodeName         = "ex2";
                extra2.Latitude         = 69.3M;
                extra2.Longitude        = 90.10293M;
                extra2.ParentLocationId = null;
                iba.AddToLocation_ado(extra2);
            });
            locationList.Add(extra2);

            Location_ado extra3 = null;

            LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                extra3 = Location_ado.CreateLocation_ado(TestHelper.TestGuid4,
                                                         "locationName", LookupConstants.LocationTypePoint);
                extra3.CodeName         = string.Empty;
                extra3.Latitude         = 79.3M;
                extra3.Longitude        = 91.10093M;
                extra3.ParentLocationId = TestHelper.TestGuid3;
                iba.AddToLocation_ado(extra3);
            });
            locationList.Add(extra3);

            return(locationList);
        }
        private void setupOakwood()
        {
            Location_ado site  = Location_ado.CreateLocation_ado(TestHelper.TestGuid1, OAKWOOD, LookupConstants.LocationTypeSite);
            Location_ado point = Location_ado.CreateLocation_ado(TestHelper.TestGuid2, "Point", LookupConstants.LocationTypePoint);

            point.ParentLocationId = site.LocationId;
            SiteVisit_ado   visit  = DbTestHelper.LoadSingleSiteVisit(TestHelper.TestGuid1, site.LocationId, DateTime.Now.AddHours(-7));
            PointSurvey_ado survey = PointSurvey_ado.CreatePointSurvey_ado(TestHelper.TestGuid2, point.LocationId, DateTime.Now.AddHours(-7), DateTime.Now.AddHours(-6));

            survey.SiteVisitId = visit.EventId;
            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                iba.AddToPointSurvey_ado1(survey);
                iba.AddToLocation_ado(site);
                iba.AddToLocation_ado(point);
                iba.SaveChanges();
            });

            List <Observation_ado> obsList = new List <Observation_ado>();

            addABunchOfObservations(obsList, 35, List[0].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 26, List[1].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 21, List[2].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 16, List[3].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 11, List[4].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 6, List[5].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 5, List[6].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 3, List[7].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 3, List[8].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 3, List[9].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 3, List[10].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 3, List[11].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 2, List[12].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 2, List[13].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 2, List[14].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 1, List[15].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 1, List[16].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 1, List[17].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 1, List[18].SpeciesId, survey.EventId);
            addABunchOfObservations(obsList, 25, List[19].SpeciesId, survey.EventId);
            loadObservations(obsList);
        }
        public void t_SamplingPointMapper_Select_ByGuid()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(TestHelper.TestGuid1,
                                                           "locationName", LookupConstants.LocationTypePoint);
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = TestHelper.TestParentGuid;
                iba.AddToLocation_ado(location);
            });
            DbTestHelper.LoadExtraneousLocations();

            // Exercise the test
            SamplingPoint site = SamplingPointMapper.Select(location.LocationId);

            validateResults(location, site);
        }
Example #10
0
        public void t_Site_Select_ByCodeName()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(new Guid("87606168-3ac7-402a-8ae6-4f6905555581"),
                                                           "locationName", LookupConstants.LocationTypeSite);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = null;
                iba.AddToLocation_ado(location);
            });
            DbTestHelper.LoadExtraneousLocations();

            // Exercise the test
            Site site = SiteMapper.Select_ByCodeName(location.CodeName);

            validateResults(location, site);
        }
        public static List <Location_ado> LoadSites()
        {
            List <Location_ado> siteList = new List <Location_ado>();

            LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                Location_ado site1 = Location_ado.CreateLocation_ado(TestHelper.TestGuid1, "Location 1",
                                                                     LookupConstants.LocationTypeSite);
                iba.AddToLocation_ado(site1);
                siteList.Add(site1);
                Location_ado site2 = Location_ado.CreateLocation_ado(TestHelper.TestGuid2, "Location 2",
                                                                     LookupConstants.LocationTypeSite);
                iba.AddToLocation_ado(site2);
                siteList.Add(site2);
                Location_ado site3 = Location_ado.CreateLocation_ado(TestHelper.TestGuid3, "Location 3",
                                                                     LookupConstants.LocationTypeSite);
                iba.AddToLocation_ado(site3);
                siteList.Add(site3);
            });

            return(siteList);
        }