private DiagnosticDescriptor CreateDescriptorWithId(string id, LocalizableString title, LocalizableString message, DiagnosticSeverity severity, params string[] customTags) => new DiagnosticDescriptor( id, title, message, DiagnosticCategory.Style, severity, isEnabledByDefault: true, customTags: customTags);
/// <summary> /// Initializes a new instance of the <see cref="ActionSubjectTemplate"/> class. /// </summary> /// <param name="template"> /// The template. /// </param> /// <param name="actionHelper"> /// The action helper. /// </param> public ActionSubjectTemplate(LocalizableString template, IActionHelper actionHelper) { if (actionHelper == null) throw new ArgumentNullException("actionHelper"); _actionHelper = actionHelper; _template = template; }
public void LocalizableString_Null_Value_Returned() { LocalizableString prop = new LocalizableString("MyProperty"); Assert.IsNull(prop.Value); Assert.IsNull(prop.GetLocalizableValue(), "LocalizedValue should be null when Value and resourceType are null"); prop.ResourceType = typeof(LocalizableStringTest); Assert.IsNull(prop.GetLocalizableValue(), "LocalizedValue should be null when Value is null and resourceType is not null"); }
/// <summary> /// Initializes a new instance of the <see cref="ActionMessageTemplate"/> class. /// </summary> /// <param name="template"> /// The template. /// </param> /// <param name="actionHelper"> /// The action helper. /// </param> /// <param name="deepLinkHelper"> /// The deep link helper. /// </param> public ActionMessageTemplate(LocalizableString template, IActionHelper actionHelper, IDeepLinkHelper deepLinkHelper) { if (actionHelper == null) throw new ArgumentNullException("actionHelper"); if (deepLinkHelper == null) throw new ArgumentNullException("deepLinkHelper"); _actionHelper = actionHelper; _deepLinkHelper = deepLinkHelper; _template = template; }
public void LocalizableString_Value_Getter_Equals_Setter() { LocalizableString prop = new LocalizableString("MyProperty"); Assert.IsNull(prop.Value, "Value should be null by default"); prop.Value = "foo"; Assert.AreEqual("foo", prop.Value, "Value getter should equal setter after setting it to 'foo'"); prop.Value = string.Empty; Assert.AreEqual(string.Empty, prop.Value, "Value should be string.Empty after setting it to such"); prop.Value = null; Assert.IsNull(prop.Value, "Value should be null after setting it to null"); }
protected AbstractCodeStyleDiagnosticAnalyzer( string descriptorId, LocalizableString title, LocalizableString message = null) { DescriptorId = descriptorId; _localizableTitle = title; _localizableMessage = message ?? title; _descriptor = CreateDescriptor(descriptorId, DiagnosticSeverity.Hidden); UnnecessaryWithSuggestionDescriptor = CreateDescriptor( descriptorId, DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary); UnnecessaryWithoutSuggestionDescriptor = CreateDescriptor(descriptorId + "WithoutSuggestion", DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary); SupportedDiagnostics = ImmutableArray.Create( _descriptor, UnnecessaryWithoutSuggestionDescriptor, UnnecessaryWithSuggestionDescriptor); }
public CSharpTypeStyleDiagnosticAnalyzerBase(string diagnosticId, LocalizableString title, LocalizableString message) { _diagnosticId = diagnosticId; _title = title; _message = message; _noneDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Hidden); _infoDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Info); _warningDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Warning); _errorDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Error); _severityToDescriptorMap = new Dictionary<DiagnosticSeverity, DiagnosticDescriptor> { {DiagnosticSeverity.Hidden, _noneDiagnosticDescriptor }, {DiagnosticSeverity.Info, _infoDiagnosticDescriptor }, {DiagnosticSeverity.Warning, _warningDiagnosticDescriptor }, {DiagnosticSeverity.Error, _errorDiagnosticDescriptor }, }; }
protected AbstractCodeStyleDiagnosticAnalyzer( string descriptorId, LocalizableString title, LocalizableString message = null) { DescriptorId = descriptorId; _localizableTitle = title; _localizableMessage = message ?? title; HiddenDescriptor = CreateDescriptorWithSeverity(DiagnosticSeverity.Hidden); InfoDescriptor = CreateDescriptorWithSeverity(DiagnosticSeverity.Info); WarningDescriptor = CreateDescriptorWithSeverity(DiagnosticSeverity.Warning); ErrorDescriptor = CreateDescriptorWithSeverity(DiagnosticSeverity.Error); UnnecessaryWithSuggestionDescriptor = CreateDescriptorWithId( descriptorId, _localizableTitle, _localizableMessage, DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary); UnnecessaryWithoutSuggestionDescriptor = CreateDescriptorWithId( descriptorId + "WithoutSuggestion", _localizableTitle, _localizableMessage, DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary); SupportedDiagnostics = ImmutableArray.Create( HiddenDescriptor, UnnecessaryWithoutSuggestionDescriptor, UnnecessaryWithSuggestionDescriptor); }
public void LocalizableString_GetLocalizedValue_Fails_When_Resource_Key_Is_Empty() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = string.Empty; prop.ResourceType = typeof(LocalizableString_Resources); ExceptionHelper.ExpectException<InvalidOperationException>(() => { prop.GetLocalizableValue(); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "MyProperty", prop.ResourceType.FullName, prop.Value)); }
public void LocalizableString_GetLocalizedValue_Respects_Current_UI_Culture() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = "Language"; prop.ResourceType = typeof(LocalizableString_Resources_WithGermanSupport); CultureInfo defaultCulture = CultureInfo.CurrentUICulture; try { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); Assert.AreEqual("English", prop.GetLocalizableValue(), "GetLocalizableValue should return 'English' with the 'en' culture"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("de"); Assert.AreEqual("German", prop.GetLocalizableValue(), "GetLocalizableValue should return 'German' with the 'de' culture"); } finally { Thread.CurrentThread.CurrentUICulture = defaultCulture; } }
public void LocalizableString_Literal_Value_Returned() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = "theValue"; Assert.AreEqual("theValue", prop.Value); Assert.AreEqual("theValue", prop.GetLocalizableValue()); }
public void LocalizableString_PublicStaticStringProperty_On_Public_Class_Succeeds() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = "PublicStaticString"; prop.ResourceType = typeof(LocalizableString_Resources); Assert.AreEqual("Public Static String", prop.GetLocalizableValue(), "LocalizedValue should contain the value of the public static string property"); }
public void LocalizableString_Resource_File_Can_Be_Used() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = "LocalizableStringTest_Resource"; prop.ResourceType = typeof(DataAnnotationsTestResources); string expected = "This is a localized string"; Assert.AreEqual(expected, prop.GetLocalizableValue(), "LocalizedValue should contain the localized string found in the resources file"); }
protected CSharpTypeStyleDiagnosticAnalyzerBase( string diagnosticId, LocalizableString title, LocalizableString message) : base(diagnosticId, title, message) { }
public CSharpTypeStyleDiagnosticAnalyzerBase(string diagnosticId, LocalizableString title, LocalizableString message) { _diagnosticId = diagnosticId; _title = title; _message = message; }
protected CSharpTypeStyleDiagnosticAnalyzerBase( string diagnosticId, EnforceOnBuild enforceOnBuild, LocalizableString title, LocalizableString message) : base(diagnosticId, enforceOnBuild, ImmutableHashSet.Create <ISingleValuedOption>(CSharpCodeStyleOptions.VarForBuiltInTypes, CSharpCodeStyleOptions.VarWhenTypeIsApparent, CSharpCodeStyleOptions.VarElsewhere), LanguageNames.CSharp, title, message) { }
public void LocalizableString_PublicConstString_Throws() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = "PublicConstString"; prop.ResourceType = typeof(LocalizableString_Resources); ExceptionHelper.ExpectException<InvalidOperationException>(() => { prop.GetLocalizableValue(); }, GetExpectedErrorMessage(prop.Value)); }
/// <summary> /// Initializes a new instance of the <see cref="ActionSubjectTemplate"/> class. /// </summary> /// <param name="template"> /// The template. /// </param> public ActionSubjectTemplate(LocalizableString template) { _template = template; }
/// <summary> /// Creates a new localizable string command. /// </summary> /// <param name="collection">The collection to be modified.</param> /// <param name="element">The entry to be set in the <paramref name="collection"/>.</param> public SetLocalizableString(LocalizableStringCollection collection, LocalizableString element) { _collection = collection; _entry = element; }
private static LocalizableString L(string name) { return(LocalizableString.Create <AbpPermissionCacheTestResource>(name)); }
protected DiagnosticDescriptor CreateDescriptorWithTitle(LocalizableString title, DiagnosticSeverity severity, params string[] customTags) => CreateDescriptorWithId(DescriptorId, title, title, severity, customTags);
/// <summary> /// Initializes a new instance of the <see cref="ActionMessageTemplate"/> class. /// </summary> /// <param name="template"> /// The template. /// </param> public ActionMessageTemplate(LocalizableString template) { _template = template; }
/// <summary> /// Creates a new <see cref="ActionMessageTemplate"/>. /// </summary> /// <param name="templateString"> /// The template. /// </param> /// <returns> /// The <see cref="ActionMessageTemplate"/>. /// </returns> public ActionMessageTemplate CreateMessageTemplate(LocalizableString templateString) { #if !SILVERLIGHT return new ActionMessageTemplate(templateString, ActionHelper, DeepLinkHelper); #else return new ActionMessageTemplate(templateString); #endif }
public void LocalizableString_PublicStaticStringProperty_On_Internal_Class_Throws() { LocalizableString prop = new LocalizableString("MyProperty"); prop.Value = "PublicStaticString"; prop.ResourceType = typeof(LocalizableString_Resources_NonPublic); ExceptionHelper.ExpectException<InvalidOperationException>(() => { prop.GetLocalizableValue(); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "MyProperty", typeof(LocalizableString_Resources_NonPublic).FullName, prop.Value)); }
private static void ForceLocalizableStringExceptions(LocalizableString localizableString, EventHandler<Exception> handler) { if (localizableString.CanThrowExceptions) { localizableString.OnException += handler; localizableString.ToString(); localizableString.OnException -= handler; } }
protected DiagnosticDescriptor CreateDescriptor(string id, LocalizableString title, DiagnosticSeverity severity, params string[] customTags) => CreateDescriptor(id, title, title, severity, customTags);
/// <summary> /// Creates a new <see cref="ActionSubjectTemplate"/>. /// </summary> /// <param name="templateString"> /// The template. /// </param> /// <returns> /// The <see cref="ActionSubjectTemplate"/>. /// </returns> public ActionSubjectTemplate CreateSubjectTemplate(LocalizableString templateString) { #if !SILVERLIGHT return new ActionSubjectTemplate(templateString, ActionHelper); #else return new ActionSubjectTemplate(templateString); #endif }