示例#1
0
        public void Verify_Update()
        {
            const string newCompanyName = "New Company Name";

            using(var transaction = new TransactionScope())
            {
                // PrepareDb
                InsertCustomer();

                using (var northwindContext = new NorthwindEntities())
                {
                    var customer = northwindContext
                        .Customers
                        .Single(c => c.CustomerID == customerId);

                    customer.CompanyName = newCompanyName;
                    customer.Location = SpatialServices.Instance.GeographyFromText("POINT (-122.191667 47.685833)");

                    northwindContext.SaveChanges();
                }

                // Verify the customer was updated
                Assert.Equal(
                    1,
                    ExecuteScalar(
                        string.Format(
                            "SELECT COUNT(*) " +
                            "FROM Customers " +
                            "WHERE CustomerID = '{0}' AND CompanyName = '{1}' AND Location.STAsText() = 'POINT (-122.191667 47.685833)'",
                            customerId,
                            newCompanyName)));
            }
        }
示例#2
0
        public void Verify_Delete()
        {
            using (var transaction = new TransactionScope())
            {
                // PrepareDb
                InsertCustomer();

                using (var northwindContext = new NorthwindEntities())
                {
                    var customer = northwindContext
                        .Customers
                        .Single(c => c.CustomerID == customerId);

                    northwindContext.Customers.DeleteObject(customer);
                    northwindContext.SaveChanges();
                }

                // Verify the customer was updated
                Assert.Equal(
                    0,
                    ExecuteScalar(
                        string.Format(
                            "SELECT COUNT(*) FROM Customers WHERE CustomerID = '{0}' AND CompanyName = '{1}'",
                            customerId,
                            companyName)));
            }
        }
示例#3
0
        private static void InsertCustomer()
        {
            using (var northwindContext = new NorthwindEntities())
            {
                northwindContext.Customers.AddObject(
                    new Customer()
                        {
                            CustomerID = customerId,
                            CompanyName = companyName,
                            Location = SpatialServices.Instance.GeographyFromText("POINT (17.038333 51.107778)")
                        });

                northwindContext.SaveChanges();
            }
        }
示例#4
0
        public void Verify_Update_DbGeography()
        {
            using (var transaction = new TransactionScope())
            {
                int orderID;
                using (var northwindContext = new NorthwindEntities())
                {
                    var order = northwindContext
                        .Orders
                        .OrderBy(o => o.OrderID)
                        .First();

                    orderID = order.OrderID;

                    order.ContainerSize = SpatialServices.Instance.GeometryFromText("LINESTRING (100 100, 20 180, 180 180)");
                    northwindContext.SaveChanges();
                }

                // Verify the customer was updated
                Assert.Equal(
                    1,
                    ExecuteScalar(
                        string.Format(
                            "SELECT COUNT(*) FROM Orders WHERE OrderID = '{0}' AND ContainerSize.STAsText() = 'LINESTRING (100 100, 20 180, 180 180)'",
                            orderID)));
            }
        }