예제 #1
0
        public void EntitySetDeclaredInReferencedModelE2E()
        {
            // Query Entity Set in GPS
            TestClientContext.MergeOption = MergeOption.OverwriteChanges;
            var vehicleGPSSetInGPS = TestClientContext.VehicleGPSSetInGPS;

            foreach (var vehicleGPS in vehicleGPSSetInGPS)
            {
                Assert.IsTrue(vehicleGPS != null);
            }
            Assert.AreEqual(3, vehicleGPSSetInGPS.Count());

            // Create an entity in VehicleGPSSetInGPS
            var newVehicleGPS = new VehicleGPSType()
            {
                Key           = "101",
                VehicleSpeed  = 100.1,
                StartLocation = new GeoLocation()
                {
                    Lat  = 1,
                    Long = 2,
                },
                EndLocation = new GeoLocation()
                {
                    Lat  = 3,
                    Long = 4,
                },
                CurrentLocation = new GeoLocation()
                {
                    Lat  = 1.2,
                    Long = 2.4,
                },
                LostSignalAlarm = new GPSLostSignalAlarmType()
                {
                    Severity          = 1,
                    LastKnownLocation = new GeoLocation()
                    {
                        Lat  = 2.1,
                        Long = 1.2,
                    }
                },
                Map = new MapType()
                {
                    MBytesDownloaded = 1.2,
                    ProviderName     = "TESTNEW",
                    Uri = "TESTNEW.TEST",
                }
            };

            TestClientContext.AddToVehicleGPSSetInGPS(newVehicleGPS);
            TestClientContext.SaveChanges();

            // Get the created entity
            var            queryable  = TestClientContext.VehicleGPSSetInGPS.Where(vehicleGPS => vehicleGPS.Key == "101");
            VehicleGPSType newCreated = queryable.Single();

            Assert.AreEqual(100.1, newCreated.VehicleSpeed);

            // Update the created entity
            newCreated.VehicleSpeed = 200.1;
            TestClientContext.UpdateObject(newCreated);
            TestClientContext.SaveChanges();

            // Query and Delete entity
            VehicleGPSType updated = queryable.Single();

            Assert.AreEqual(200.1, newCreated.VehicleSpeed);

            TestClientContext.DeleteObject(updated);
            TestClientContext.SaveChanges();
            Assert.AreEqual(3, vehicleGPSSetInGPS.Count());
        }