/// <summary> /// Called when validations are needed for the command /// </summary> /// <param name="context">Validation Context where to add validation errors</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public void Validate(Microsoft.VisualStudio.Modeling.Validation.ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { try { Guard.NotNull(() => settings, settings); var templateValidator = new TemplateValidator(settings.Name, new UnfoldVsTemplateCommand.UnfoldVsTemplateSettings { SanitizeName = settings.GetPropertyValue<bool>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.SanitizeName)), SyncName = settings.GetPropertyValue<bool>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.SyncName)), TemplateAuthoringUri = settings.GetPropertyValue<string>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.TemplateAuthoringUri)), TemplateUri = settings.GetPropertyValue<string>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.TemplateUri)), SettingsElement = settingsElement, OwnerElement = settings.Owner, }, context, ((ModelElement)settings).Store); templateValidator.ValidateCommandSettings(tracer); } catch (Exception ex) { tracer.Error( ex, Resources.ValidationMethodFailed_Error, Reflector<TemplateValidator>.GetMethod(n => n.ValidateCommandSettings(null)).Name); throw; } }
public void WhenTemplateUriIsNotEmpty_ThenValidateTemplateUriIsNotEmptySucceeds() { var templateValidator = new TemplateValidator(this.settings.Name, new UnfoldVsTemplateCommand.UnfoldVsTemplateSettings { TemplateUri = "foo", OwnerElement = this.product }, validationContext, this.settings.Store); templateValidator.ValidateTemplateUriIsNotEmpty(); Assert.True(validationContext.CurrentViolations.Count == 0); }
public void ThenValidateTemplateUriIsNotEmptyFails() { var templateValidator = new TemplateValidator(this.settings.Name, new UnfoldVsTemplateCommand.UnfoldVsTemplateSettings { TemplateUri = string.Empty, OwnerElement = this.product, SettingsElement = (IAutomationSettingsSchema)this.settings.Extends, }, validationContext, this.settings.Store); templateValidator.ValidateTemplateUriIsNotEmpty(); Assert.True(validationContext.CurrentViolations.Count == 1); Assert.True(validationContext.ValidationSubjects.IndexOf(this.settings) == 0); }
internal void ValidateAll(ValidationContext context) { var templateValidator = new TemplateValidator(this.Name, new UnfoldVsTemplateCommand.UnfoldVsTemplateSettings { SanitizeName = this.SanitizeName, SyncName = this.SyncName, TemplateAuthoringUri = this.TemplateAuthoringUri, TemplateUri = this.TemplateUri, SettingsElement = (IAutomationSettingsSchema)this.Extends, OwnerElement = this.Owner, CreateElementOnUnfold = CreateElementOnUnfold }, context, this.Store); templateValidator.ValidateTemplateSettings(tracer); }