예제 #1
0
    public async Task AssignComplexObject() {
      await _emTask;

      var supplier = _em1.CreateEntity<Supplier>();
      // set in ctor.
      Assert.IsTrue(supplier.Location.Country == "USA", "Country should be set");
      var initLocation = supplier.Location;
      supplier.Location.City = "San Francisco";
      Assert.IsTrue(supplier.Location.City == "San Francisco", "city should be set");
      var newLocation = new Location();
      newLocation.City = "Seatle";
      supplier.Location = newLocation;
      Assert.IsTrue(supplier.Location == initLocation, "location ref should not have changed");
      Assert.IsTrue(supplier.Location.City == "Seatle", "city should have changed");
      Assert.IsTrue(supplier.Location.ComplexAspect.Parent == supplier, "parent should be set");
      Assert.IsTrue(supplier.Location.ComplexAspect.ParentEntityProperty.Name == "Location", "parentEntityProperty should be set");
    }
예제 #2
0
    public async Task SetComplexPropWithNewInstance() {
      await _emTask;

      var q = new EntityQuery<Supplier>().Where(s => s.CompanyName.StartsWith("P"));
      var suppliers = await _em1.ExecuteQuery(q);
      Assert.IsTrue(suppliers.Count() > 0, "should be some suppliers");

      var newLocation = new Location() { City = "Phoenix", PostalCode = "11111" };
      suppliers.ForEach(s => s.Location = newLocation);
      Assert.IsTrue(suppliers.All(s => s.Location != newLocation), "refs should NOT be the same");
      Assert.IsTrue(suppliers.All(s => s.Location.StructuralEquals(newLocation)), "but values should be the same");
      Assert.IsTrue(suppliers.All(s => s.EntityAspect.EntityState.IsModified()), "should have been modified");
      suppliers.All(s => s.Location.City == "Phoenix");
      var supplier = suppliers.First();
      Assert.IsTrue(supplier.Location.ComplexAspect.Parent == supplier, "parent should be set");
      Assert.IsTrue(supplier.Location.ComplexAspect.ParentEntityProperty.Name == "Location", "parentEntityProperty should be set");
    }
예제 #3
0
    public async Task EntityAndPropertyChangedEvents() {
      await _emTask;

      var newLocation = new Location() { City = "Bar", Country = "Foo" };
      var q = new EntityQuery<Supplier>().Where(s => s.CompanyName.StartsWith("P")).Take(2);

      var suppliers = await _em1.ExecuteQuery(q);
      Assert.IsTrue(suppliers.Count() > 0, "should have returned some suppliers");

      var supp0 = suppliers.First();
      List<EntityChangedEventArgs> entityChangedList = new List<EntityChangedEventArgs>();
      List<PropertyChangedEventArgs> propChangedList = new List<PropertyChangedEventArgs>();
      List<PropertyChangedEventArgs> aspectPropChangedList = new List<PropertyChangedEventArgs>();
      _em1.EntityChanged += (s, e) => {
        entityChangedList.Add(e);
      };
      ((INotifyPropertyChanged)supp0).PropertyChanged += (s, e) => {
        propChangedList.Add(e);
      };
      supp0.EntityAspect.PropertyChanged += (s, e) => {
        aspectPropChangedList.Add(e);
      };

      supp0.Location.City = "xxxxx";
      var lastEc = entityChangedList.Last();
      Assert.IsTrue(lastEc.EntityAspect == supp0.EntityAspect, "ec should have been fired");
      Assert.IsTrue(entityChangedList[0].Action == EntityAction.PropertyChange && entityChangedList[0].Entity == supp0);
      Assert.IsTrue(entityChangedList[1].Action == EntityAction.EntityStateChange && entityChangedList[1].Entity == supp0);

      Assert.IsTrue(aspectPropChangedList.Count == 2, "2 aspects should have changed"); // isChanged and EntityState.

      Assert.IsTrue(propChangedList.Count == 1);
      Assert.IsTrue(propChangedList[0].PropertyName == "Location");
      entityChangedList.Clear();
      propChangedList.Clear();
      aspectPropChangedList.Clear();
      supp0.Location.City = "city-1";
      supp0.Location.Address = "address-1";
      Assert.IsTrue(entityChangedList.Count == 2, "should be 2 entity changed events");
      Assert.IsTrue(propChangedList.Count == 2, "should be 2 propChanged events");
      Assert.IsTrue(aspectPropChangedList.Count == 0, "no more EntityAspect changes");
    }
예제 #4
0
    public async Task AssignComplexObjectWithInitializer() {
      await _emTask;

      var supplier = _em1.CreateEntity<Supplier>();
      var initLocation = supplier.Location;
      supplier.Location.City = "San Francisco";
      Assert.IsTrue(supplier.Location.City == "San Francisco", "city should be set");
      var newLocation = new Location() { City = "Seattle", PostalCode = "11111" };
      supplier.Location = newLocation;
      Assert.IsTrue(supplier.Location == initLocation, "location ref should not have changed");
      Assert.IsTrue(supplier.Location.City == "Seattle", "city should have changed");
      Assert.IsTrue(supplier.Location.ComplexAspect.Parent == supplier, "parent should be set");
      Assert.IsTrue(supplier.Location.ComplexAspect.ParentEntityProperty.Name == "Location", "parentEntityProperty should be set");
    }