public void WhenTemplateTypeIsItem_ThenReturnsBaseUri() { Assert.Equal("template://item", VsTemplateUri.GetUriBase(VsTemplateType.Item)); }
public void WhenTemplateTypeIsProjectGroup_ThenReturnsBaseUri() { Assert.Equal("template://projectgroup", VsTemplateUri.GetUriBase( VsTemplateType.ProjectGroup)); }
internal void ValidateAuthoringUriIsValidAndTemplateIsConfiguredCorrectly(bool validatingTemplate) { try { if (!string.IsNullOrEmpty(settings.TemplateAuthoringUri)) { IItemContainer item = GetVsTemplateProjectItem(); if (item != null) { //Doing all the validation in one method to avoid the performance impact of reading the file from disc IVsTemplate template = VsTemplateFile.Read(item.PhysicalPath); if (template == null) { if (!(settings.OwnerElement.Root.PatternModel.IsInTailorMode())) { context.LogError( string.Format( CultureInfo.CurrentCulture, Resources.Validate_TemplateSettingsAssociatedTemplateIsNotAValidTemplateFile, settings.OwnerElement.Name), Resources.Validate_TemplateSettingsAssociatedTemplateIsNotAValidTemplateFileCode, settings.SettingsElement as ModelElement); } return; } if (!settings.TemplateUri.EndsWith(template.TemplateData.TemplateID, StringComparison.OrdinalIgnoreCase)) { //wrong id context.LogError( string.Format( CultureInfo.CurrentCulture, Resources.Validate_TemplateSettingsTemplateIdDoesNotMatchReferencedTemplate, this.name), Resources.Validate_TemplateSettingsTemplateIdDoesNotMatchReferencedTemplateCode, settings.SettingsElement as ModelElement); } if (!((template.Type == VsTemplateType.Item && settings.TemplateUri.StartsWith(VsTemplateUri.GetUriBase(VsTemplateType.Item), StringComparison.OrdinalIgnoreCase)) || (template.Type == VsTemplateType.Project && settings.TemplateUri.StartsWith(VsTemplateUri.GetUriBase(VsTemplateType.Project), StringComparison.OrdinalIgnoreCase)) || (template.Type == VsTemplateType.ProjectGroup && settings.TemplateUri.StartsWith(VsTemplateUri.GetUriBase(VsTemplateType.ProjectGroup), StringComparison.OrdinalIgnoreCase)))) { //wrong uri for type context.LogError( string.Format( CultureInfo.CurrentCulture, Resources.Validate_TemplateSettingsTemplateTypeDoesNotMatchReferencedTemplate, settings.OwnerElement.Name, template.Type), Resources.Validate_TemplateSettingsTemplateTypeDoesNotMatchReferencedTemplateCode, settings.SettingsElement as ModelElement); } var elementReplacementsWizard = template.WizardExtension.GetExtension(TemplateWizardInfo.ElementReplacementsTemplateWizardFullTypeName); if (validatingTemplate) { var instantiationWizard = template.WizardExtension.GetExtension(TemplateWizardInfo.InstantiationTemplateWizardFullTypeName); if (instantiationWizard == null || elementReplacementsWizard == null) { //wizards not present context.LogWarning( string.Format( CultureInfo.CurrentCulture, Resources.Validate_TemplateSettingsWizardsNotPresentInTemplate, settings.OwnerElement.Name), Resources.Validate_TemplateSettingsWizardsNotPresentInTemplateCode, settings.SettingsElement as ModelElement); } else if (template.WizardExtension.ToList().IndexOf(instantiationWizard) > template.WizardExtension.ToList().IndexOf(elementReplacementsWizard)) { //wizards in wrong order context.LogWarning( string.Format( CultureInfo.CurrentCulture, Resources.Validate_TemplateSettingsWizardOrderIsNotCorrect, settings.OwnerElement.Name), Resources.Validate_TemplateSettingsWizardOrderIsNotCorrectCode, settings.SettingsElement as ModelElement); } } else { if (elementReplacementsWizard == null) { //wizards not present context.LogWarning( string.Format( CultureInfo.CurrentCulture, Resources.Validate_TemplateSettingsWizardsNotPresentInTemplate, settings.OwnerElement.Name), Resources.Validate_TemplateSettingsWizardsNotPresentInTemplateCode, settings.SettingsElement as ModelElement); } } } } } catch (Exception ex) { tracer.Error( ex, Resources.ValidationMethodFailed_Error, Reflector <TemplateValidator> .GetMethod(n => n.ValidateAuthoringUriIsValidAndTemplateIsConfiguredCorrectly(true)).Name); throw; } }