Exemple #1
0
    public async Task NullForeignKey() {
      await _emTask;
      var prod1 = new Product();
      
      _em1.AttachEntity(prod1);
      prod1.ProductName = "Test";
      prod1.SupplierID = null;

      var q0 = new EntityQuery<Product>().Where(p => p.Supplier != null).Take(2).Expand(p => p.Supplier);
      var r0 = (await q0.Execute(_em1)).ToList();
      Assert.IsTrue(r0.Count() == 2);
      Assert.IsTrue(r0.All(p => p.Supplier != null));
      var p0 = r0[0];
      var p1 = r0[1];
      var s0 = p0.Supplier;
      var s1 = p1.Supplier;

      Assert.IsTrue(s0.Products.Contains(p0));
      p0.Supplier = null;
      Assert.IsTrue(p0.SupplierID == null);
      Assert.IsTrue(!s0.Products.Contains(p0));
      
      Assert.IsTrue(s1.Products.Contains(p1));
      p1.SupplierID = null;
      Assert.IsTrue(p1.Supplier == null);
      Assert.IsTrue(!s1.Products.Contains(p1));
    }
Exemple #2
0
    public async Task RejectChanges() {
      await _emTask;


      var prod1 = new Product();
      prod1.Discontinued = true;
      _em1.AttachEntity(prod1, EntityState.Unchanged);
      prod1.Discontinued = false;
      prod1.EntityAspect.RejectChanges();
      
      Assert.IsTrue(prod1.Discontinued == true, "should have returned to initial state");
    }
    public async Task RejectChanges2() {
      var em1 = await TestFns.NewEm(_serviceName);


      var prod1 = new Product();
      prod1.Discontinued = true;
      em1.AddEntity(prod1);
      em1.RejectChanges();


      Assert.IsTrue(prod1.EntityAspect.EntityState.IsDetached());
    }
    public async Task RejectChanges() {
      var em1 = await TestFns.NewEm(_serviceName);


      var prod1 = new Product();
      prod1.Discontinued = true;
      em1.AttachEntity(prod1, EntityState.Unchanged);
      prod1.Discontinued = false;
      prod1.EntityAspect.RejectChanges();
      
      Assert.IsTrue(prod1.Discontinued == true, "should have returned to initial state");
    }
 private OrderDetail CreateOrderDetail(EntityManager em, Order order, Product product) {
   var od = new OrderDetail();
   var orderID = order.OrderID;
   var productID = product.ProductID;
   od.ProductID = productID;
   od.OrderID = orderID;
   od.Quantity = 1;
   od.UnitPrice = 3.14m;
   em.AddEntity(od);
   return od;
 }
 private Product CreateProduct(EntityManager em) {
   var product = new Product();
   em.AddEntity(product);
   product.ProductName = "Test.NET_" + TestFns.RandomSuffix(7);
   return product;
 }
Exemple #7
0
    public async Task PrimaryKeyFixup() {
      await _emTask;

      var prod = new Product();
      _em1.AttachEntity(prod);
      var origProdId = prod.ProductID;
      var ek = prod.EntityAspect.EntityKey;
      var sameProd = _em1.FindEntityByKey(ek);
      Assert.IsTrue(prod == sameProd, "should be the same product");
      var sameProd2 = _em1.FindEntityByKey<Product>(origProdId);
      Assert.IsTrue(prod == sameProd2, "should be the same product-again");
      prod.ProductID = 7;
      var notSameProd = _em1.FindEntityByKey(ek);
      Assert.IsTrue(notSameProd == null);
      var sameProd3 = _em1.FindEntityByKey(prod.EntityAspect.EntityKey);
      Assert.IsTrue(prod == sameProd2, "should be the same product-again 2");
    }
Exemple #8
0
    public async Task UnidirectionalAttachFk() {
      await _emTask;
      if (TestFns.DEBUG_MONGO) {
        Assert.Inconclusive("NA for Mongo - Order/OrderDetail");
        return;
      }

      var od1 = new OrderDetail();
      var prod1 = new Product();
      od1.ProductID = -99;
      _em1.AttachEntity(od1);
      _em1.AttachEntity(prod1);
      Assert.IsTrue(od1.Product == null, "Product should be null");
      prod1.ProductID = 2;
      od1.ProductID = 2;
      Assert.IsTrue(od1.Product == prod1, "should now point to product");

      var od2 = new OrderDetail();
      var prod2 = new Product();
      od2.ProductID = -88;
      _em1.AttachEntity(od2);
      _em1.AttachEntity(prod2);
      Assert.IsTrue(od2.Product == null, "Product should be null - again");
      // same as above but different order
      od2.ProductID = 3;
      // should now have an unresolved parent.
      prod2.ProductID = 3;
      
      Assert.IsTrue(od2.Product == prod2, "should now point to product - again");
    }
    public async Task PrimaryKeyFixup() {
      var em1 = await TestFns.NewEm(_serviceName);

      var prod = new Product();
      em1.AttachEntity(prod);
      var origProdId = prod.ProductID;
      var ek = prod.EntityAspect.EntityKey;
      var sameProd = em1.GetEntityByKey(ek);
      Assert.IsTrue(prod == sameProd, "should be the same product");
      var sameProd2 = em1.GetEntityByKey<Product>(origProdId);
      Assert.IsTrue(prod == sameProd2, "should be the same product-again");
      prod.ProductID = 7;
      var notSameProd = em1.GetEntityByKey(ek);
      Assert.IsTrue(notSameProd == null);
      var sameProd3 = em1.GetEntityByKey(prod.EntityAspect.EntityKey);
      Assert.IsTrue(prod == sameProd2, "should be the same product-again 2");
    }
Exemple #10
0
 private Product CreateProduct(EntityManager em) {
   var product = new Product();
   em.AddEntity(product);
   product.ProductName = "Test.NET_" + TestFns.RandomSuffix(7);
   // only needed because of NH bug where we made 'rowVersion' nullable on the client.
   product.RowVersion = 0;
   return product;
 }