Using SR.GetResourceString to fetch localized string (#98)
* Using SR.GetResourceString to fetch localized string * Added unit tests
This commit is contained in:
Родитель
f04eb68702
Коммит
b281d65870
|
@ -16,7 +16,7 @@ namespace System.Windows.Forms
|
|||
|
||||
protected override string GetLocalizedString(string value)
|
||||
{
|
||||
return value;
|
||||
return SR.GetResourceString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace System.Windows.Forms
|
|||
if (!this.replaced)
|
||||
{
|
||||
this.replaced = true;
|
||||
base.DescriptionValue = base.Description;
|
||||
base.DescriptionValue = SR.GetResourceString(base.Description);
|
||||
}
|
||||
return base.Description;
|
||||
}
|
||||
|
@ -29,4 +29,4 @@ namespace System.Windows.Forms
|
|||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Windows.Forms.Tests
|
||||
{
|
||||
public class SRCategoryAttributeTests
|
||||
{
|
||||
[Fact]
|
||||
public void VerifyCategoryForValidCategoryAttribute()
|
||||
{
|
||||
SRCategoryAttribute srCategoryAttribute = new SRCategoryAttribute(nameof(SR.CatAccessibility));
|
||||
Assert.True(string.Compare(srCategoryAttribute.Category, SR.CatAccessibility) == 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidCategoryShouldReturnCategoryNameAsIs()
|
||||
{
|
||||
const string fakeCategory = "fakeCategory";
|
||||
SRCategoryAttribute srCategoryAttribute = new SRCategoryAttribute(fakeCategory);
|
||||
Assert.True(string.Compare(srCategoryAttribute.Category, fakeCategory) == 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Windows.Forms.Tests
|
||||
{
|
||||
public class SRDescriptionAttributeTests
|
||||
{
|
||||
[Fact]
|
||||
public void VerifyDescriptionAttributeValue()
|
||||
{
|
||||
SRDescriptionAttribute srDescriptionAttribute = new SRDescriptionAttribute(nameof(SR.AboutBoxDesc));
|
||||
Assert.True(string.Compare(srDescriptionAttribute.Description, SR.AboutBoxDesc) == 0);
|
||||
|
||||
//Getting srDescriptionAttribute.Description again should also return description value
|
||||
Assert.True(string.Compare(srDescriptionAttribute.Description, SR.AboutBoxDesc) == 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidDescriptionAttributeShouldReturnNull()
|
||||
{
|
||||
SRDescriptionAttribute srDescriptionAttribute = new SRDescriptionAttribute("fake");
|
||||
Assert.Null(srDescriptionAttribute.Description);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче