Пример #1
0
    public EntityError Resolve(EntityManager em) {
      IsServerError = true;
      try {
        EntityType entityType = null;
        if (EntityTypeName != null) {
          var stName = StructuralType.ClrTypeNameToStructuralTypeName(EntityTypeName);
          entityType = MetadataStore.Instance.GetEntityType(stName);
          var ek = new EntityKey(entityType, KeyValues);
          Entity = em.FindEntityByKey(ek);
        }

        if (PropertyName != null) {
          PropertyName = MetadataStore.Instance.NamingConvention.ServerPropertyNameToClient(PropertyName);
        }
        if (Entity != null) {
          Property = entityType.GetProperty(PropertyName);
          var vc = new ValidationContext(this.Entity);
          vc.Property = this.Property;
          var veKey = (ErrorName ?? ErrorMessage) + (PropertyName ?? "");
          var ve = new ValidationError(null, vc, ErrorMessage, veKey);
          ve.IsServerError = true;
          this.Entity.EntityAspect.ValidationErrors.Add(ve);
        }
      } catch (Exception e) {
        ErrorMessage = ( ErrorMessage ?? "") + ":  Unable to Resolve this error: " + e.Message;
      }
      return this;
    }
Пример #2
0
 public ValidationContext(ValidationContext vc) {
   Instance = vc.Instance;
   PropertyValue = vc.PropertyValue;
   Property = vc.Property;
 }
Пример #3
0
 public async Task RequiredProperty() {
   await _emTask;
   
   var emp = new Employee();
   var vr = new RequiredValidator();
   var dp = emp.EntityAspect.EntityType.GetDataProperty("LastName");
   var vc = new ValidationContext(emp, dp, null);
   var ve = vr.Validate(vc);
   Assert.IsTrue(ve != null);
   Assert.IsTrue(ve.Message.Contains("LastName") && ve.Message.Contains("required"));
   Assert.IsTrue(ve.Context.Entity == emp);
   Assert.IsTrue(ve.Validator == vr);
   Assert.IsTrue(ve.Key != null);
 }
Пример #4
0
 public ValidationContext(ValidationContext vc) {
   Entity = vc.Entity;
   Property = vc.Property;
   PropertyValue = vc.PropertyValue;
   ComplexObject = vc.ComplexObject;
 }
Пример #5
0
 public override string GetErrorMessage(ValidationContext validationContext) {
   return LocalizedMessage.Format(validationContext.Property.DisplayName);
 }
Пример #6
0
 protected override bool ValidateCore(ValidationContext context) {
   var value = (String)context.PropertyValue;
   if (value == null) return true;
   return value.StartsWith("US");
 }
Пример #7
0
    public async Task ChangeMessageBaseAndAssembly() {
      await _emTask;

      var emp = new Employee();
      var vr = new RequiredValidator().WithMessage("Model_Northwind_NetClient.CustomMessages2", typeof(Employee).Assembly);
      var dp = emp.EntityAspect.EntityType.GetDataProperty("LastName");
      var vc = new ValidationContext(emp, dp, null);
      var ve = vr.Validate(vc);
      Assert.IsTrue(ve != null);
      Assert.IsTrue(ve.Message.Contains("LastName") && ve.Message.Contains("required") && ve.Message.Contains("CUSTOM 2"));
      Assert.IsTrue(ve.Context.Entity == emp);
      Assert.IsTrue(ve.Validator == vr);
      Assert.IsTrue(ve.Key != null);
    }
Пример #8
0
    public async Task ChangeMessageResourceType() {
      var em1 = await TestFns.NewEm(_serviceName);

      var emp = new Employee();
      var vr = new RequiredValidator().WithMessage(typeof(Model_Northwind_NetClient.CustomMessages1));
      var dp = emp.EntityAspect.EntityType.GetDataProperty("LastName");
      var vc = new ValidationContext(emp, dp, null);
      var ve = vr.Validate(vc);
      Assert.IsTrue(ve != null);
      Assert.IsTrue(ve.Message.Contains("LastName") && ve.Message.Contains("required") && ve.Message.Contains("CUSTOM 1"));
      Assert.IsTrue(ve.Context.Entity == emp);
      Assert.IsTrue(ve.Validator == vr);
      Assert.IsTrue(ve.Key != null);
    }
Пример #9
0
    public async Task ChangeMessageString() {
      var em1 = await TestFns.NewEm(_serviceName);

      var emp = new Employee();
      var vr = new RequiredValidator().WithMessage("{0} is bad");
      var dp = emp.EntityAspect.EntityType.GetDataProperty("LastName");
      var vc = new ValidationContext(emp, dp, null);
      var ve = vr.Validate(vc);
      Assert.IsTrue(ve != null);
      Assert.IsTrue(ve.Message.Contains("LastName") && ve.Message.Contains("bad"));
      Assert.IsTrue(ve.Context.Entity == emp);
      Assert.IsTrue(ve.Validator == vr);
      Assert.IsTrue(ve.Key != null);
    }