예제 #1
0
 public async Task CreateEntityWithInitializer2() {
   var em1 = await TestFns.NewEm(_serviceName);
   var order = new Order();
   var cust = (Customer)em1.CreateEntity(typeof(Customer), new { CompanyName = "Testzzz", Orders = new Order[] {order}, RowVersion = 3 });
   Assert.IsTrue(cust.EntityAspect.EntityState.IsAdded());
   Assert.IsTrue(cust.CompanyName == "Testzzz");
   Assert.IsTrue(cust.Orders.Count == 1 && cust.Orders.First() == order);
   Assert.IsTrue(cust.RowVersion == 3);
   Assert.IsTrue(order.EntityAspect.EntityState.IsAdded());
   Assert.IsTrue(order.Customer == cust);
   Assert.IsTrue(order.CustomerID == cust.CustomerID);
 }
예제 #2
0
    public async Task RejectChangesFkFixup() {
      var em1 = await TestFns.NewEm(_serviceName);

      var emp1 = new Employee();
      em1.AttachEntity(emp1);
      var emp2 = em1.CreateEntity<Employee>();
      
      var order1 = new Order();
      emp1.Orders.Add(order1);
      Assert.IsTrue(order1.EntityAspect.EntityState.IsAdded());
      Assert.IsTrue(order1.Employee == emp1);
      order1.EntityAspect.AcceptChanges();
      // move the order;
      emp2.Orders.Add(order1);
      Assert.IsTrue(emp1.Orders.Count == 0);
      Assert.IsTrue(emp2.Orders.Count == 1);
      Assert.IsTrue(order1.Employee == emp2);
      Assert.IsTrue(order1.EntityAspect.EntityState.IsModified());
      order1.EntityAspect.RejectChanges();
      Assert.IsTrue(order1.Employee == emp1);
      Assert.IsTrue(emp1.Orders.Count == 1);
      Assert.IsTrue(emp2.Orders.Count == 0);
    }
예제 #3
0
    public async Task Int32FkSetToNull() {
      var em1 = await TestFns.NewEm(_serviceName);

      //        ok(true, "N/A for Mongo - employeeId is not an integer on Mongo");
      var order = new Order() { EmployeeID = 1 };
      em1.AddEntity(order);
      var sr = await em1.SaveChanges();
      Assert.IsTrue(sr.Entities.Count == 1, "should have saved 1 entity");
      order.EmployeeID = null;
      var sr2 = await em1.SaveChanges();
      Assert.IsTrue(sr.Entities.Count == 1, "should have again saved 1 entity");
      Assert.IsTrue(order.EmployeeID == null, "should be null");
      order.EntityAspect.EntityState = EntityState.Deleted;
      Assert.IsTrue(order.EntityAspect.EntityState.IsDeleted());
      var sr3 = await em1.SaveChanges();
      Assert.IsTrue(sr.Entities.Count == 1, "should have again saved 1 entity");
      Assert.IsTrue(order.EntityAspect.EntityState.IsDetached());
    }
예제 #4
0
    public async Task ExpImpTempKeyFixup2() {
      var em1 = await TestFns.NewEm(_serviceName);

      var q = new EntityQuery<Foo.Supplier>("Suppliers").Where(s => s.CompanyName.StartsWith("P"));

      var suppliers = await q.Execute(em1);

      Assert.IsTrue(suppliers.Count() > 0, "should be some suppliers");
      var orderIdProp = MetadataStore.Instance.GetEntityType("Order").KeyProperties[0];
      em1.KeyGenerator.GetNextTempId(orderIdProp);

      var order1 = new Order();
      var emp1 = new Employee();
      em1.AddEntity(order1); em1.AddEntity(emp1);
      emp1.LastName = "bar";
      var cust1 = new Customer() { CompanyName = "Foo" };
      order1.Employee = emp1;
      order1.Customer = cust1;
      var exportedEm = em1.ExportEntities(null, false);

      var em2 = new EntityManager(em1);
      em2.ImportEntities(exportedEm);

      var suppliers2 = em2.GetEntities<Supplier>().ToList();
      Assert.IsTrue(suppliers.Count() == suppliers2.Count, "should be the same number of suppliers");
      var addedOrders = em2.GetEntities<Order>(EntityState.Added);
      Assert.IsTrue(addedOrders.Count() == 1, "should be 1 added order");
      var order1x = addedOrders.First();
      var cust1x = order1x.Customer;
      Assert.IsTrue(cust1x.CompanyName == "Foo", "customer company name should be 'Foo'");
      var emp1x = order1x.Employee;
      Assert.IsTrue(emp1x.LastName == "bar", "lastName should be 'bar'");

    }
예제 #5
0
    public async Task ExpImpTempKeyFixup1() {
      var em1 = await TestFns.NewEm(_serviceName);

      var q = new EntityQuery<Foo.Employee>("Employees").Take(3);

      var results = await q.Execute(em1);

      Assert.IsTrue(results.Count() > 0);
      var emp1 = new Employee();
      var order1 = new Order();
      var order2 = new Order();
      em1.AddEntity(emp1);
      emp1.Orders.Add(order1);
      emp1.Orders.Add(order2);

      var exportedEntities = em1.ExportEntities(null, false);

      // custs1 and 2 shouldn't be imported because of default preserveChanges
      // emps1 and 2 should cause the creation of NEW emps with new temp ids;
      // tempKeys should cause creation of new entities;
      var impResult = em1.ImportEntities(exportedEntities);
      var allEntities = em1.GetEntities();

      Assert.IsTrue(allEntities.Count() == 9, "should have 9 (3 orig, 3 added, 3 imported (new) entities in the cache");

      Assert.IsTrue(allEntities.OfType<Order>().Count() == 4, "should be 4 orders (2 + 2)");
      Assert.IsTrue(allEntities.OfType<Employee>().Count() == 5, "should be 5 emps (3 + 1 + 1) ");
      Assert.IsTrue(allEntities.OfType<Employee>().Count(c => c.EntityAspect.EntityState.IsAdded()) == 2, "should only be 2 added emps");
      Assert.IsTrue(allEntities.OfType<Order>().All(c => c.EntityAspect.EntityState.IsAdded()));
      Assert.IsTrue(impResult.ImportedEntities.Count == 6, "should have imported 6 entities - 3 orig + 3 new");
      Assert.IsTrue(impResult.ImportedEntities.OfType<Order>().Count() == 2, "should have imported 2 orders");
      Assert.IsTrue(impResult.ImportedEntities.OfType<Employee>().Count(e => e.EntityAspect.EntityState.IsAdded()) == 1, "should have imported 1 added emp");
      Assert.IsTrue(impResult.ImportedEntities.OfType<Employee>().Count(e => e.EntityAspect.EntityState.IsUnchanged()) == 3, "should have imported 3 unchanged emps");
      Assert.IsTrue(impResult.TempKeyMap.Count == 3, "tempKeyMap should be of length 3");
      Assert.IsTrue(impResult.TempKeyMap.All(kvp => kvp.Key != kvp.Value), "imported entities should not have same key values");
      var newOrders = impResult.ImportedEntities.OfType<Order>();
      var newEmp = impResult.ImportedEntities.OfType<Employee>().First(e => e.EntityAspect.EntityState.IsAdded());
      Assert.IsTrue(newOrders.All(no => no.EmployeeID == newEmp.EmployeeID), "should have updated order empId refs");

    }
예제 #6
0
 public async Task AddToNavSet() {
     await _emTask;
     
     var customer = new Customer();
     var order = new Order();
     _em1.AttachEntity(customer);
     var origOrders = customer.Orders;
     Assert.IsTrue(origOrders.Count == 0);
     origOrders.Add(order);
     // next line won't compile - this is good!
     // customer.Orders = new NavigationSet<Order>();
     Assert.IsTrue(origOrders.Count == 1);
     Assert.IsTrue(customer.Orders == origOrders, "should be same collection");
     Assert.IsTrue(order.EntityAspect.IsAttached, "should be attached");
     Assert.IsTrue(order.Customer == customer, "order.Customer should = customer");
 }
예제 #7
0
    public async Task UnattachedChildren() {
      await _emTask;

      var cust1 = new Customer();
      var cust2 = new Customer();
      var order1 = new Order();
      cust1.CustomerID = Guid.NewGuid();
      _em1.AttachEntity(order1);
      Assert.IsTrue(order1.EntityAspect.EntityState.IsUnchanged());
      order1.CustomerID = cust1.CustomerID;
      Assert.IsTrue(order1.EntityAspect.EntityState.IsModified());
      Assert.IsTrue(order1.Customer == null, "customer should be null");
      order1.EntityAspect.AcceptChanges();
      Assert.IsTrue(order1.EntityAspect.EntityState.IsUnchanged());
      _em1.AttachEntity(cust1);
      Assert.IsTrue(order1.Customer == cust1, "customer should now be set");
      Assert.IsTrue(order1.EntityAspect.EntityState.IsUnchanged(), "fixup should not change entityState");
    }
예제 #8
0
    public async Task GraphAttachMultipartKey() {
      var em1 = await TestFns.NewEm(_serviceName);

      if (TestFns.DEBUG_MONGO) {
        Assert.Inconclusive("NA for Mongo - OrderDetail");
        return;
      }

      var order = new Order();
      order.OrderID = 999;
      for (int i = 0; i < 3; i++) {
        var od = new OrderDetail();
        od.ProductID = i;
        order.OrderDetails.Add(od);
      }
      em1.AttachEntity(order);
      Assert.IsTrue(order.EntityAspect.EntityState.IsUnchanged(), "order should be unchanged");
      Assert.IsTrue(order.OrderDetails.All(od => od.EntityAspect.EntityState.IsUnchanged()), "ods should all be unchanged");
      Assert.IsTrue(order.OrderDetails.Count == 3, "should be 3 ods");
      Assert.IsTrue(order.OrderDetails.All(od => od.Order == order), "should all point to order");
      Assert.IsTrue(order.OrderDetails.All(od => od.OrderID == 999), "should all have correct orderId");
      
    }
예제 #9
0
 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;
 }
예제 #10
0
    public async Task GraphAttachChild() {
      await _emTask;

      var cust1 = new Customer();
      // this test will fail if we don't give the customer a new Guid 
      cust1.CustomerID = Guid.NewGuid();
      var order1 = new Order();
      order1.Customer = cust1;
      
      _em1.AddEntity(order1);

      Assert.IsTrue(order1.EntityAspect.EntityState.IsAdded());
      
      Assert.IsTrue(cust1.EntityAspect.EntityState.IsAdded());
      var orders = cust1.Orders;
      Assert.IsTrue(orders.Contains(order1) , "should contain order1");
      Assert.IsTrue(order1.Customer == cust1, "Customer should be cust2");
      Assert.IsTrue(order1.CustomerID == cust1.CustomerID, "CustomerID should be cust2's id");
      

    }
예제 #11
0
    public async Task ChangeParent1ToN() {
      await _emTask;

      var cust1 = new Customer();
      var cust2 = new Customer();
      
      var order1 = new Order();
      var order2 = new Order();
      _em1.AddEntity(cust1);
      _em1.AddEntity(cust2);
      
      cust1.Orders.Add(order1);
      cust1.Orders.Add(order2);

      var cust1CollChangedList = new List<NotifyCollectionChangedEventArgs>();
      cust1.Orders.CollectionChanged += (s, e) => {
        cust1CollChangedList.Add(e);
      };
      var cust2CollChangedList = new List<NotifyCollectionChangedEventArgs>();
      cust2.Orders.CollectionChanged += (s, e) => {
        cust2CollChangedList.Add(e);
      };

      var propChangedList = new List<PropertyChangedEventArgs>();
      ((INotifyPropertyChanged)order1).PropertyChanged += (s, e) => {
        propChangedList.Add(e);
      };
      // move order
      cust2.Orders.Add(order1);

      Assert.IsTrue(cust1CollChangedList.Last().Action == NotifyCollectionChangedAction.Remove);
      Assert.IsTrue(cust1CollChangedList.Last().OldItems.Contains(order1), "change event should contain order1");

      Assert.IsTrue(cust2CollChangedList.Last().Action == NotifyCollectionChangedAction.Add);
      Assert.IsTrue(cust2CollChangedList.Last().NewItems.Contains(order1), "change event should contain order1");
      // TODO: this is not yet happening but it should
      // Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "Customer"), "propChange should mention Customer");
      Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "CustomerID"), "propChange should mention CustomerID");

      Assert.IsTrue(!cust1.Orders.Contains(order1), "order1 should have been removed");
      Assert.IsTrue(cust2.Orders.Contains(order1), "order1 should have been removed");
      Assert.IsTrue(order1.Customer == cust2, "Customer should be cust2");
      Assert.IsTrue(order1.CustomerID == cust2.CustomerID, "CustomerID should be cust2's id");
      Assert.IsTrue(order1.EntityAspect.EntityState.IsAdded());
      Assert.IsTrue(cust1.Orders.Count == cust2.Orders.Count, "count should be 1");

      cust1CollChangedList.Clear();
      cust2CollChangedList.Clear();
      propChangedList.Clear();
      order1.Customer = cust1;
      Assert.IsTrue(cust1CollChangedList.Last().Action == NotifyCollectionChangedAction.Add);
      Assert.IsTrue(cust1CollChangedList.Last().NewItems.Contains(order1), "change event should contain order1");
      // Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "Customer"), "propChange should mention Customer");
      Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "CustomerID"), "propChange should mention CustomerID");
      
      Assert.IsTrue(cust1.Orders.Count == 2, "count should be 2");

    }
예제 #12
0
    public async Task DetachFromNavCollection() {
      await _emTask;

      var cust1 = new Customer();
      var order1 = new Order();
      var order2 = new Order();
      _em1.AddEntity(cust1);
      var orders = cust1.Orders;
      orders.Add(order1);
      orders.Add(order2);

      var collectionChangedList = new List<NotifyCollectionChangedEventArgs>();
      orders.CollectionChanged += (s, e) => {
        collectionChangedList.Add(e);
      };
      var propChangedList = new List<PropertyChangedEventArgs>();
      ((INotifyPropertyChanged)order1).PropertyChanged += (s, e) => {
        propChangedList.Add(e);
      };
      order1.EntityAspect.Detach();
      Assert.IsTrue(collectionChangedList.Last().Action == NotifyCollectionChangedAction.Remove);
      Assert.IsTrue(collectionChangedList.Last().OldItems.Contains(order1), "change event should contain order1");
      
      
      Assert.IsTrue(propChangedList.Count == 0, "Detaching an entity will not create a propertyChange event");

      Assert.IsTrue(!orders.Contains(order1), "order1 should have been removed");
      Assert.IsTrue(order1.Customer == null, "Customer should be null");
      Assert.IsTrue(order1.CustomerID == null); // null because not required.
      Assert.IsTrue(order1.EntityAspect.EntityState.IsDetached());
      Assert.IsTrue(orders.Count == 1, "count should be 1");

      collectionChangedList.Clear();
      propChangedList.Clear();
      order1.Customer = cust1;
      Assert.IsTrue(collectionChangedList.Last().Action == NotifyCollectionChangedAction.Add);
      Assert.IsTrue(collectionChangedList.Last().NewItems.Contains(order1), "change event should contain order1");
      // Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "Customer"), "propChange should mention Customer");
      Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "CustomerID"), "propChange should mention CustomerID");

      Assert.IsTrue(orders.Contains(order1), "order1 should be back");
      Assert.IsTrue(order1.Customer == cust1, "Customer should be back");
      Assert.IsTrue(order1.CustomerID == cust1.CustomerID, "CustomerID should be back"); // null because not required.
      Assert.IsTrue(order1.EntityAspect.EntityState.IsAdded());
      Assert.IsTrue(orders.Count == 2, "count should be 2");

    }
예제 #13
0
    public async Task AddToNavCollection() {
      await _emTask;

      var cust1 = new Customer();
      var order1 = new Order();
      _em1.AttachEntity(cust1, EntityState.Added);
      Assert.IsTrue(cust1.EntityAspect.HasTemporaryKey, "should have a temp key");
      var orders = cust1.Orders;
      Assert.IsTrue(orders.ParentEntity == cust1, "ParentEntity should be set");
      Assert.IsTrue(orders.NavigationProperty == cust1.EntityAspect.EntityType.GetNavigationProperty("Orders"), "NavProperty should be set");

      NotifyCollectionChangedEventArgs changeArgs = null;
      orders.CollectionChanged += (s, e) => {
        changeArgs = e;
      };
      orders.Add(order1);
      Assert.IsTrue(order1.EntityAspect.EntityState.IsAdded(), "should be added");
      Assert.IsTrue(orders.Contains(order1), "should contain order");
      Assert.IsTrue(order1.Customer == cust1, "should be connected");
      Assert.IsTrue(changeArgs != null, "changeArgs should not be null");
      Assert.IsTrue(changeArgs.Action == NotifyCollectionChangedAction.Add);
      Assert.IsTrue(changeArgs.NewItems.Contains(order1), "change should mention order1");

    }
예제 #14
0
    public async Task FkSetToNull() {
      await _emTask;

      var cust = _em1.CreateEntity<Customer>(EntityState.Unchanged);
      var order1 = _em1.CreateEntity<Order>();
      order1.Customer = cust;
      Assert.IsTrue(order1.Customer == cust, "should be customer");
      Assert.IsTrue(cust.Orders.Contains(order1), "should contain order1");

      var order2 = new Order();
      order2.Customer = cust;
      Assert.IsTrue(order2.EntityAspect.IsAttached && order2.EntityAspect.EntityState.IsAdded());
      Assert.IsTrue(order2.Customer == cust, "should be customer - again");
      Assert.IsTrue(cust.Orders.Contains(order2), "should contain order2");

      order1.CustomerID = null;
      Assert.IsTrue(order1.Customer == null, "should be null");
      Assert.IsTrue(!cust.Orders.Contains(order1), "should not contain order1");

    }
예제 #15
0
    public async Task DeleteFromNavCollection()
    {
      var em1 = await TestFns.NewEm(_serviceName);

      var cust1 = new Customer();
      var order1 = new Order();
      var order2 = new Order();
      em1.AddEntity(cust1);
      var orders = cust1.Orders;
      orders.Add(order1);
      orders.Add(order2);
      em1.AcceptChanges();

      var collectionChangedList = new List<NotifyCollectionChangedEventArgs>();
      orders.CollectionChanged += (s, e) =>
      {
        collectionChangedList.Add(e);
      };
      var propChangedList = new List<PropertyChangedEventArgs>();
      ((INotifyPropertyChanged)order1).PropertyChanged += (s, e) =>
      {
        propChangedList.Add(e);
      };
      var entityChangedList = new List<EntityChangedEventArgs>();
      em1.EntityChanged += (s, e) =>
      {
        entityChangedList.Add(e);
      };
      order1.EntityAspect.Delete();

      Assert.IsTrue(collectionChangedList.Last().Action == NotifyCollectionChangedAction.Remove, "should have removed from collection");
      Assert.IsTrue(collectionChangedList.Last().OldItems.Contains(order1), "change event should contain order1");

      //Assert.IsTrue(propChangedList.Count == 0, "Deleting an entity will not create a propertyChange event");

      Assert.IsTrue(!orders.Contains(order1), "order1 should have been removed");
      Assert.IsTrue(order1.Customer == null, "Customer should be null");
      Assert.IsTrue(order1.CustomerID == cust1.CustomerID, "customerID should NOT be cleared when detached - just the Customer");
      Assert.IsTrue(order1.EntityAspect.EntityState.IsDeleted(), "state should be deleted");
      Assert.IsTrue(orders.Count == 1, "count should be 1");

      collectionChangedList.Clear();
      propChangedList.Clear();
      order1.EntityAspect.RejectChanges();
      Assert.IsTrue(collectionChangedList.Last().Action == NotifyCollectionChangedAction.Add, "should have added to collection");
      Assert.IsTrue(collectionChangedList.Last().NewItems.Contains(order1), "change event should contain order1");
      Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "Customer"), "propChange should mention Customer");
      // Not needed because CustomerID is not cleared.
      // Assert.IsTrue(propChangedList.Any(args => args.PropertyName == "CustomerID"), "propChange should mention CustomerID");

      Assert.IsTrue(orders.Contains(order1), "order1 should be back");
      Assert.IsTrue(order1.Customer == cust1, "Customer should be back");
      Assert.IsTrue(order1.CustomerID == cust1.CustomerID, "CustomerID should not have changed"); // null because not required.
      Assert.IsTrue(order1.EntityAspect.EntityState.IsUnchanged(), "State should be unchanged but is " + order1.EntityAspect.EntityState);
      Assert.IsTrue(orders.Count == 2, "count should be 2");

    }
예제 #16
0
    public async Task OrderAndInternationalOrder() {
      var em1 = await TestFns.NewEm(_serviceName);
      //        ok(true, "N/A for Mongo - primary keys cannot be shared between collections");
      var order = new Order() {
        CustomerID = TestFns.WellKnownData.AlfredsID,
        EmployeeID = TestFns.WellKnownData.NancyEmployeeID,
        ShipName = "Test " + new DateTime().ToString()
      };
      em1.AddEntity(order);
      var internationalOrder = new InternationalOrder() {
        OrderID = order.OrderID,
        Order = order,
        CustomsDescription = "rare, exotic birds"
      };
      Assert.IsTrue(internationalOrder.EntityAspect.EntityState.IsAdded(), "internationalOrder should be Added");
      var sr = await em1.SaveChanges();
      Assert.IsTrue(sr.Entities.Count == 2, "should have saved 2 entities");
      Assert.IsTrue(order.OrderID == internationalOrder.OrderID);
      Assert.IsTrue(order.OrderID > 0);
      Assert.IsTrue(order.InternationalOrder == internationalOrder);

    }
예제 #17
0
    //test("save/mods with EntityErrorsException", function () {
    //    if (testFns.DEBUG_ODATA) {
    //        ok(true, "Skipped test - OData does not support server interception or alt resources");
    //        return;
    //    };

    //    if (testFns.DEBUG_MONGO) {
    //        ok(true, "Skipped test - Mongo does not YET support server side validation");
    //        return;
    //    };


    //    var em = newEm();
    //    var zzz = createParentAndChildren(em);
    //    var cust1 = zzz.cust1;
        
    //    stop();
    //    em.saveChanges().then(function (sr) {
    //        zzz.cust1.setProperty("contactName", "foo");
    //        zzz.cust2.setProperty("contactName", "foo");
    //        zzz.order1.setProperty("freight", 888.11);
    //        zzz.order2.setProperty("freight", 888.11);
    //        ok(zzz.cust1.entityAspect.entityState.isModified(), "cust1 should be modified");
    //        ok(zzz.order1.entityAspect.entityState.isModified(), "order1 should be modified");
    //        var so = new SaveOptions({ resourceName: "SaveWithEntityErrorsException", tag: "entityErrorsException" });
    //        return em.saveChanges(null, so);
    //    }).then(function(sr2) {
    //        ok(false, "should not get here");
    //    }).fail(function (e) {
    //        ok(e.entityErrors, "should have server errors");
    //        ok(e.entityErrors.length === 2, "2 order entities should have failed");
    //        ok(zzz.order1.entityAspect.getValidationErrors().length === 1);
    //        var order2Errs = zzz.order2.entityAspect.getValidationErrors();
    //        ok(order2Errs.length === 1, "should be 1 error for order2");
    //        ok(order2Errs[0].propertyName === "orderID", "errant property should have been 'orderID'");
    //        // now save it properly
    //        return em.saveChanges();
    //    }).then(function (sr) {
    //        ok(sr.entities.length === 4, "should have saved ok");
    //    }).fail(testFns.handleFail).fin(start);

    //});

    //test("save with client side validation error", function () {

    //    var em = newEm();
    //    var zzz = createParentAndChildren(em);
    //    var cust1 = zzz.cust1;
    //    cust1.setProperty("companyName", null);
    //    stop();
    //    em.saveChanges().then(function (sr) {
    //        ok(false, "should not get here");
    //    }).fail(function (e) {
    //        ok(e.entityErrors, "should be a  entityError");
    //        ok(e.entityErrors.length === 1, "should be only one error");
    //        ok(!e.entityErrors[0].isServerError, "should NOT be a server error");
    //        var errors = cust1.entityAspect.getValidationErrors();
    //        ok(errors[0].errorMessage === errors[0].errorMessage, "error message should appear on the cust");

    //    }).fin(start);
    //});

    //test("save with server side entity level validation error", function () {
    //    if (testFns.DEBUG_ODATA) {
    //        ok(true, "Skipped test - OData does not support server interception or alt resources");
    //        return;
    //    };

    //    if (testFns.DEBUG_MONGO) {
    //        ok(true, "Skipped test - Mongo does not YET support server side validation");
    //        return;
    //    };

    //    var em = newEm();
    //    var zzz = createParentAndChildren(em);
    //    var cust1 = zzz.cust1;
    //    cust1.setProperty("companyName", "error");
    //    stop();
    //    em.saveChanges().then(function(sr) {
    //        ok(false, "should not get here");
    //    }).fail(function (e) {
    //        ok(e.entityErrors, "should be a server error");
    //        ok(e.entityErrors.length === 1, "should be only one server error");
    //        var errors = cust1.entityAspect.getValidationErrors();
    //        ok(errors[0].errorMessage === e.entityErrors[0].errorMessage, "error message should appear on the cust");
    //    }).fin(start);
    //});

    //test("save with server side entity level validation error + repeat", function () {
    //    if (testFns.DEBUG_ODATA) {
    //        ok(true, "Skipped test - OData does not support server interception or alt resources");
    //        return;
    //    };

    //    if (testFns.DEBUG_MONGO) {
    //        ok(true, "Skipped test - Mongo does not YET support server side validation");
    //        return;
    //    };

    //    var em = newEm();
    //    var zzz = createParentAndChildren(em);
    //    var cust1 = zzz.cust1;
    //    cust1.setProperty("companyName", "error");
    //    stop();
    //    em.saveChanges().then(function (sr) {
    //        ok(false, "should not get here");
    //    }).fail(function (e) {
    //        ok(e.entityErrors, "should be a server error");
    //        ok(e.entityErrors.length === 1, "should be only one server error");
    //        var errors = cust1.entityAspect.getValidationErrors();
    //        ok(errors.length === 1, "should only be 1 error");
    //        ok(errors[0].errorMessage === e.entityErrors[0].errorMessage, "error message should appear on the cust");
    //        return em.saveChanges();
    //    }).fail(function(e2) {
    //        ok(e2.entityErrors, "should be a server error");
    //        ok(e2.entityErrors.length === 1, "should be only one server error");
    //       var errors = cust1.entityAspect.getValidationErrors();
    //       ok(errors.length === 1, "should only be 1 error");
    //       ok(errors[0].errorMessage === e2.entityErrors[0].errorMessage, "error message should appear on the cust");
    //    }).fin(start);
    //});
 
    //test("add UserRole", function () {
    //    if (testFns.DEBUG_MONGO) {
    //        ok(true, "TODO for Mongo - needs to be written specifically for Mongo - should succeed in Mongo");
    //        return;
    //    }

    //    var em = newEm();
    //    var roleId;
    //    var userId = 6;
    //    var p2 = breeze.Predicate.create("userId", "ne", userId);
    //    var p1 = breeze.Predicate.create("userRoles", "all", p2);

    //    var q = new EntityQuery("Roles").where(p1).take(1);
    //    stop();
    //    q.using(em).execute().then(function (data) {
    //        ok(data.results.length === 1, "should be one result");
    //        var role = data.results[0];
    //        roleId = role.getProperty("id");

    //        var newUserRole = em.createEntity('UserRole', {
    //            userId: userId,
    //            roleId: roleId
    //        });

    //        return em.saveChanges();
    //    }).then(function (sr) {
    //        ok(true, "save succeeded");
    //        var resultRole = sr.entities[0];
    //        var roleId2 = resultRole.getProperty("roleId");
    //        ok(roleId2 === roleId, "roleIds match");
    //        var userId2 = resultRole.getProperty("userId");
    //        ok(userId2 === userId, "userIds match");
            
    //        // delete entity
    //        resultRole.entityAspect.setDeleted();
    //        return em.saveChanges();
    //    }).then(function (sr) {
    //        ok(true, "delete succeeded");
    //    }).fail(function (e) {
    //        ok(false, "error on save: " + e.message);
    //    }).fail(testFns.handleFail).fin(start);

    //});

    private Order CreateOrder(EntityManager em) {
      var order = new Order();
      em.AddEntity(order);
      order.ShipName = "Test.NET_" + TestFns.RandomSuffix(7);
      return order;
    }
예제 #18
0
    public async Task GraphAttachParent() {
      await _emTask;

      var cust1 = new Customer();
      var order1 = new Order();
      cust1.Orders.Add(order1);

      _em1.AddEntity(cust1);

      Assert.IsTrue(order1.EntityAspect.EntityState.IsAdded());
      Assert.IsTrue(cust1.EntityAspect.EntityState.IsAdded());
      var orders = cust1.Orders;
      Assert.IsTrue(orders.Contains(order1), "should contain both orders");
      Assert.IsTrue(order1.Customer == cust1, "Customer should be cust2");
      Assert.IsTrue(order1.CustomerID == cust1.CustomerID, "CustomerID should be cust2's id");


    }
예제 #19
0
 private TwoCusts CreateParentAndChildren(EntityManager em) {
   var cust1 = new Customer();
   cust1.CompanyName = "Test1_" + TestFns.RandomSuffix(8);
   cust1.City = "Oakland";
   cust1.RowVersion = 13;
   cust1.Fax = "510 999-9999";
   em.AddEntity(cust1);
   var cust2 = em.CreateEntity<Customer>();
   cust2.CompanyName = "Test2_" + TestFns.RandomSuffix(8);
   cust2.City = "Emeryville";
   cust2.RowVersion = 1;
   cust2.Fax = "510 888-8888";
   var order1 = new Order();
   order1.OrderDate = DateTime.Today;
   var order2 = em.CreateEntity<Order>();
   order1.OrderDate = DateTime.Today;
   cust1.Orders.Add(order1);
   cust1.Orders.Add(order2);
   Assert.IsTrue(cust1.Orders.Count == 2);
   Assert.IsTrue(cust2.Orders.Count == 0);
   return new TwoCusts() { Cust1 = cust1, Cust2 = cust2 };
 }
예제 #20
0
    public async Task UnattachedChildrenMultipartkey() {
      await _emTask;

      if (TestFns.DEBUG_MONGO) {
        Assert.Inconclusive("NA for Mongo - OrderDetail");
        return;
      }

      var order = new Order();
      order.OrderID = 999;
      for (int i = 0; i < 3; i++) {
        var od = new OrderDetail();
        od.ProductID = i;
        od.OrderID = order.OrderID;
        _em1.AttachEntity(od);
      }
      _em1.AttachEntity(order);
      Assert.IsTrue(order.EntityAspect.EntityState.IsUnchanged(), "order should be unchanged");
      Assert.IsTrue(order.OrderDetails.All(od => od.EntityAspect.EntityState.IsUnchanged()), "ods should all be unchanged");
      Assert.IsTrue(order.OrderDetails.Count == 3, "should be 3 ods");
      Assert.IsTrue(order.OrderDetails.All(od => od.Order == order), "should all point to order");
      Assert.IsTrue(order.OrderDetails.All(od => od.OrderID == order.OrderID), "should all have correct orderId");

    }