public void TestGetAvailableValuesForEnumWithDescriptions() { using (new CultureScope(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture)) { // try twice to test caching for (int i = 0; i < 2; ++i) { EnumValue[] enumValuesInvariant = EnumDescription.GetAllValues(typeof(EnumWithDescription)); Assert.That(enumValuesInvariant.Length, Is.EqualTo(3)); Assert.That(enumValuesInvariant[0].Value, Is.EqualTo(EnumWithDescription.Value1)); Assert.That(enumValuesInvariant[0].Description, Is.EqualTo("Value I")); Assert.That(enumValuesInvariant[1].Value, Is.EqualTo(EnumWithDescription.Value2)); Assert.That(enumValuesInvariant[1].Description, Is.EqualTo("Value II")); Assert.That(enumValuesInvariant[2].Value, Is.EqualTo(EnumWithDescription.ValueWithoutDescription)); Assert.That(enumValuesInvariant[2].Description, Is.EqualTo("ValueWithoutDescription")); CultureInfo culture = new CultureInfo("en-US"); EnumValue[] enumValuesSpecific = EnumDescription.GetAllValues(typeof(EnumWithDescription), culture); Assert.That(enumValuesSpecific.Length, Is.EqualTo(3)); Assert.That(enumValuesSpecific[0].Value, Is.EqualTo(EnumWithDescription.Value1)); Assert.That(enumValuesSpecific[0].Description, Is.EqualTo("Value I")); Assert.That(enumValuesSpecific[1].Value, Is.EqualTo(EnumWithDescription.Value2)); Assert.That(enumValuesSpecific[1].Description, Is.EqualTo("Value II")); Assert.That(enumValuesSpecific[2].Value, Is.EqualTo(EnumWithDescription.ValueWithoutDescription)); Assert.That(enumValuesSpecific[2].Description, Is.EqualTo("ValueWithoutDescription")); } } }
public void TestGetAvailableValuesForEnumFromResource() { using (new CultureScope(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture)) { // try twice to test caching for (int i = 0; i < 2; ++i) { EnumValue[] enumValues = EnumDescription.GetAllValues(typeof(EnumWithResources)); Assert.That(enumValues.Length, Is.EqualTo(3)); Assert.That(enumValues[0].Value, Is.EqualTo(EnumWithResources.Value1)); Assert.That(enumValues[0].Description, Is.EqualTo("Value 1")); Assert.That(enumValues[1].Value, Is.EqualTo(EnumWithResources.Value2)); Assert.That(enumValues[1].Description, Is.EqualTo("Value 2")); Assert.That(enumValues[2].Value, Is.EqualTo(EnumWithResources.ValueWithoutResource)); Assert.That(enumValues[2].Description, Is.EqualTo("ValueWithoutResource")); } } }