Using SR.GetResourceString to fetch localized string (#98)

* Using SR.GetResourceString to fetch localized string
* Added unit tests
This commit is contained in:
Shyam Gupta 2018-11-28 17:02:03 -08:00 коммит произвёл GitHub
Родитель f04eb68702
Коммит b281d65870
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 58 добавлений и 4 удалений

Просмотреть файл

@ -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);
}
}
}