public void t_SamplingPointMapper_Save_Insert()
        {
            loadASite();
            SamplingPoint site = new SamplingPoint()
            {
                GeoCoordinate = new Business.DataTypes.Coordinate()
                {
                    Latitude = new Business.DataTypes.Degree()
                    {
                        Value = 56.789M
                    },
                    Longitude = new Business.DataTypes.Degree()
                    {
                        Value = 67.281M
                    }
                },
                Id     = TestHelper.TestGuid1,
                Name   = "Site Name",
                SiteId = TestHelper.TestParentGuid
            };

            SamplingPointMapper.Insert(site);


            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var siteQuery = from sites in iba.SamplingPoint_ado select sites;
                Assert.IsNotNull(siteQuery, "Query result is null");
                Assert.AreEqual(1, siteQuery.Count(), "Wrong number of results in query");
                SamplingPoint_ado adoSite = siteQuery.First();
                validateObjectEquality(site, adoSite);
            }
        }
 private static void validateObjectEquality(SamplingPoint site, SamplingPoint_ado adoSite)
 {
     Assert.IsNotNull(adoSite, "There is not Site with the ID to test for");
     Assert.AreEqual(site.GeoCoordinate.Latitude.Value, adoSite.Latitude, "Latitude");
     Assert.AreEqual(site.GeoCoordinate.Longitude.Value, adoSite.Longitude, "Longitude");
     Assert.AreEqual(site.Id, adoSite.LocationId, "Id");
     Assert.AreEqual(site.Name, adoSite.LocationName, "Name");
 }
        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");
                }
            }
        }