public async Task ValidationErrorsChanged2() { var em1 = await TestFns.NewEm(_serviceName); using (TestFns.ShareWithDetached(em1.MetadataStore)) { 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); } }
public async Task RequiredProperty2() { var em1 = await TestFns.NewEm(_serviceName); using (TestFns.ShareWithDetached(em1.MetadataStore)) { var emp = new Employee(); var dp = emp.EntityAspect.EntityType.GetDataProperty("LastName"); var ves = emp.EntityAspect.ValidateProperty(dp); Assert.IsTrue(ves.Count() > 0); var ve1 = ves.First(); Assert.IsTrue(ve1.Message.Contains("LastName") && ve1.Message.Contains("required")); Assert.IsTrue(ve1.Context.Entity == emp); Assert.IsTrue(ves.Any(ve => ve.Validator.Equals(new RequiredValidator().Intern())), "validator should be a requiredValdator. "); Assert.IsTrue(ve1.Key != null); } }
public async Task ValidationErrorsChanged() { var em1 = await TestFns.NewEm(_serviceName); using (TestFns.ShareWithDetached(em1.MetadataStore)) { 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); } }
public async Task AttachRecursive() { var em1 = await TestFns.NewEm(_serviceName); using (TestFns.ShareWithDetached(em1.MetadataStore)) { var emp1 = new Employee(); var emp2 = new Employee(); var emp3 = new Employee(); emp2.Manager = emp1; emp3.Manager = emp2; em1.AddEntity(emp3); Assert.IsTrue(emp3.EntityAspect.IsAttached); Assert.IsTrue(emp2.EntityAspect.IsAttached); Assert.IsTrue(emp1.EntityAspect.IsAttached); Assert.IsTrue(emp1.DirectReports.Contains(emp2), "emp1 manages emp2"); Assert.IsTrue(emp2.DirectReports.Contains(emp3), "emp2 manages emp3"); Assert.IsTrue(emp2.Manager == emp1, "emp2 manager is emp1"); Assert.IsTrue(emp3.Manager == emp2, "emp3 manager is emp2"); } }
public async Task EntireEntity() { var em1 = await TestFns.NewEm(_serviceName); using (TestFns.ShareWithDetached(em1.MetadataStore)) { var emp = new Employee(); var ves = emp.EntityAspect.Validate(); Assert.IsTrue(ves.Count() == 2, "should only be 2 emp validation errors here"); Assert.IsTrue(ves.Any(ve => ve.Message.Contains("LastName") && ve.Message.Contains("required"))); Assert.IsTrue(ves.All(ve => ve.Context.Entity == emp)); var msg = ves.Select(ve => ve.Validator.GetType() + " " + ve.Key + " " + (ve.Validator.Equals(new RequiredValidator().Intern())).ToString() ).ToAggregateString(" ,"); Assert.IsTrue(ves.Any(ve => ve.Validator.Equals(new RequiredValidator().Intern())), "validator should be a requiredValdator. " + msg); Assert.IsTrue(ves.All(ve => ve.Key != null)); } }