public void SetCustomValidationOptionsAsDefault() { // change the default options, turning off "OnAttach" var valOpts = new ValidationOptions { ValidationApplicability = ValidationApplicability.OnPropertyChange | ValidationApplicability.OnSave }; var oldValOpts = ValidationOptions.Default; try { // make custom ValidationOptions the default for all future managers ValidationOptions.Default = valOpts; var manager = new EntityManager(_serviceName); // new empty EntityManager Assert.AreEqual(valOpts, manager.ValidationOptions); } finally { ValidationOptions.Default = oldValOpts; } }
public async Task DoesNotValidateOnAttachWhenOptionIsOff() { var manager = new EntityManager(_serviceName); // new empty EntityManager await manager.FetchMetadata(); // required before creating a new entity // change the default options, turning off "OnAttach" var valOpts = new ValidationOptions { ValidationApplicability = ValidationApplicability.OnPropertyChange | ValidationApplicability.OnSave }; // reset manager's options manager.ValidationOptions = valOpts; var customer = new Customer(); manager.AttachEntity(customer); var validationErrors = customer.EntityAspect.ValidationErrors; Assert.IsFalse(validationErrors.Any(), "Should be no validation errors even though CompanyName is required."); }