Exemplo n.º 1
0
    public async Task AttachEntityWithComplexPropsSet() {
      await _emTask;

      var supplier = new Supplier();
      supplier.CompanyName = "Test1";
      supplier.Location = new Location() { City = "Seattle", PostalCode = "11111" };
      _em1.AttachEntity(supplier);
      Assert.IsTrue(supplier.EntityAspect.IsAttached);
      Assert.IsTrue(supplier.CompanyName == "Test1" && supplier.Location.City == "Seattle" && supplier.Location.PostalCode == "11111");
      Assert.IsTrue(supplier.Location.ComplexAspect.Parent == supplier, "parent should be set");
      Assert.IsTrue(supplier.Location.ComplexAspect.ParentEntityProperty.Name == "Location", "parentEntityProperty should be set");
    }
Exemplo n.º 2
0
    public async Task SaveAdded() {
      await _emTask;

      var supplier = new Supplier();
      supplier.CompanyName = "Test-" + TestFns.RandomSuffix(5);
      var companyName = supplier.CompanyName;
      supplier.Location = new Location() { Region = "USA", Address = "123 Main Street", City = "San Diego", PostalCode = "12345" } ;
      _em1.AddEntity(supplier);
      
      var sr = await _em1.SaveChanges();
      Assert.IsTrue(sr.Entities.Count == 1);
      var ek = sr.Entities.First().EntityAspect.EntityKey;

      var _em2 = new EntityManager(_em1);
      var q1 = ek.ToQuery<Supplier>();
      var r1 = await q1.Execute(_em2);
      Assert.IsTrue(r1.Count() == 1);
      Assert.IsTrue(r1.First().CompanyName == companyName, "should have set the companyName");
      Assert.IsTrue(r1.First().Location.City == "San Diego");
      Assert.IsTrue(r1.First().Location.PostalCode == "12345");

    }
Exemplo n.º 3
0
    public async Task DeleteTestEntities() {
      await _emTask;

      var supplier = new Supplier();
      supplier.CompanyName = "Test-" + TestFns.RandomSuffix(5);
      var companyName = supplier.CompanyName;
      supplier.Location = new Location() { Region = "USA", Address = "123 Main Street", City = "San Diego", PostalCode = "12345" };
      _em1.AddEntity(supplier);

      var sr = await _em1.SaveChanges();

      Assert.IsTrue(sr.Entities.Count ==1);
      var q1 = new EntityQuery<Supplier>().Where(s => s.CompanyName.StartsWith("Test"));
      var r1 = await _em1.ExecuteQuery(q1);
      Assert.IsTrue(r1.Count() > 0);
      r1.ForEach(r => r.EntityAspect.Delete());
      var sr2 = await _em1.SaveChanges();
      Assert.IsTrue(sr2.Entities.Count == r1.Count());
      Assert.IsTrue(_em1.GetEntities().Count() == 0);
      var r2 = await _em1.ExecuteQuery(q1);
      Assert.IsTrue(r2.Count() == 0);
    }
Exemplo n.º 4
0
 public async Task RejectChangesAfterSave() {
   var em1 = await TestFns.NewEm(_serviceName);
   var supplier = new Supplier();
   em1.AddEntity(supplier);
   supplier.CompanyName = "Test_" + TestFns.RandomSuffix(10);
   supplier.Location.City = "LA";
   var sr1 = await em1.SaveChanges();
   Assert.IsTrue(sr1.Entities.Count == 1);
   Assert.IsTrue(supplier.Location.City == "LA");
   var r1 = await supplier.EntityAspect.EntityKey.ToQuery<Supplier>().Execute(em1);
   Assert.IsTrue(r1.Count() == 1);
   Assert.IsTrue(r1.First() == supplier);
   supplier.Location.City = "Fooo";
   Assert.IsTrue(supplier.EntityAspect.HasChanges());
   supplier.EntityAspect.RejectChanges();
   Assert.IsTrue(supplier.Location.City == "LA");
   
 }
Exemplo n.º 5
0
    public async Task ValidationErrorsChanged2() {
      var em1 = await TestFns.NewEm(_serviceName);
      var supplier = new Supplier();
      em1.AddEntity(supplier);
      var s = "very long involved value";
      s = s + s + s + s + s + s + s + s + s + s + s + s + s;
      supplier.CompanyName = s;
      ClearAndRevalidate(supplier, 1);
      supplier.Location.City = s;
      ClearAndRevalidate(supplier, 2);
      supplier.Location.City = "shorter";
      ClearAndRevalidate(supplier, 1);

    }
Exemplo n.º 6
0
    public async Task ValidationErrorsChanged() {
      var em1 = await TestFns.NewEm(_serviceName);

      var supplier = new Supplier();
      var valErrors = supplier.EntityAspect.ValidationErrors;
      var errors = new List<DataErrorsChangedEventArgs>();
      ((INotifyDataErrorInfo)supplier).ErrorsChanged += (se, e) => {
        errors.Add(e);
      };
      em1.AddEntity(supplier);
      Assert.IsTrue(errors.Count == 1);
      Assert.IsTrue(valErrors.Count == 1);
      
      
      var s = "very long involved value";
      s = s + s + s + s + s + s + s + s + s + s + s + s + s;
      supplier.CompanyName = s;
      Assert.IsTrue(errors.Count == 3);  // setting the companyName will remove the requiredError but add the maxLenght error
      Assert.IsTrue(errors.Last().PropertyName == "CompanyName");
      Assert.IsTrue(valErrors.Count == 1);
      Assert.IsTrue(((INotifyDataErrorInfo)supplier).HasErrors);
      var location = supplier.Location;
      location.City = s;
      Assert.IsTrue(errors.Last().PropertyName == "Location.City", "location.city should have been the propertyName");
      Assert.IsTrue(errors.Count == 4);  
      Assert.IsTrue((String) valErrors.Last().Context.PropertyPath == "Location.City");
      Assert.IsTrue(valErrors.Count == 2); // companyName_required and location.city_maxLength
      Assert.IsTrue(((INotifyDataErrorInfo)supplier).HasErrors);
      location.City = "much shorter";
      Assert.IsTrue(errors.Last().PropertyName == "Location.City", "location.city should have changed again");
      Assert.IsTrue(errors.Count == 5);
      Assert.IsTrue(valErrors.Count == 1);
      Assert.IsTrue(((INotifyDataErrorInfo)supplier).HasErrors);
      supplier.CompanyName = "shortName";
      Assert.IsTrue(errors.Count == 6);
      Assert.IsTrue(valErrors.Count == 0);
      Assert.IsTrue(((INotifyDataErrorInfo)supplier).HasErrors == false);
    }
Exemplo n.º 7
0
 public async Task CaptureAddlAddOnServer() {
   var em1 = await TestFns.NewEm(_serviceName);
   //        ok(true, "Skipped test - OData does not support server interception or alt resources");
   var supplier = new Supplier() { CompanyName = "CompName" };
   em1.AddEntity(supplier);
   var sr = await em1.SaveChanges(null, new SaveOptions(tag: "addProdOnServer"));
   Assert.IsTrue(sr.Entities.Count == 2, "should have saved two entities");
   Assert.IsTrue(supplier.Products.Count == 1, "supplier should have one product");
   Assert.IsTrue(supplier.Products.First().EntityAspect.EntityState.IsUnchanged(), "should be unchanged");
 }
Exemplo n.º 8
0
    public async Task ValidationErrorsChanged2() {
      await _emTask;
      var supplier = new Supplier();
      _em1.AddEntity(supplier);
      var s = "very long involved value";
      s = s + s + s + s + s + s + s + s + s + s + s + s + s;
      supplier.CompanyName = s;
      ClearAndRevalidate(supplier, 1);
      supplier.Location.City = s;
      ClearAndRevalidate(supplier, 2);
      supplier.Location.City = "shorter";
      ClearAndRevalidate(supplier, 1);

    }