单元测试代码:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
namespace CSharpUtilHelpV2.Test
{
public enum TestEnum
{
[System.ComponentModel.Description("第一")]
One,
[System.ComponentModel.Description("第二")]
Two,
[System.ComponentModel.Description("第三")]
Three,
[System.ComponentModel.Description("第五")]
Five,
[System.ComponentModel.Description("全部")]
All
}
[TestClass()]
public class EnumToolV2Test
{
[TestMethod()]
public void GetDescriptionTest()
{
string _actual = TestEnum.Five.GetDescription();
string _expected = "第五";
Assert.AreEqual(_expected, _actual);
}
[TestMethod()]
public void GetEnumNameTest()
{
TestEnum _actual = EnumToolV2.GetEnumName("第五");
TestEnum _expected = TestEnum.Five;
Assert.AreEqual(_expected, _actual);
}
[TestMethod()]
public void ToArrayListTest()
{
ArrayList _actual = EnumToolV2.ToArrayList(typeof(TestEnum));
ArrayList _expected = new ArrayList(5);
_expected.Add(new KeyValuePair(TestEnum.One, "第一"));
_expected.Add(new KeyValuePair(TestEnum.Two, "第二"));
_expected.Add(new KeyValuePair(TestEnum.Three, "第三"));
_expected.Add(new KeyValuePair(TestEnum.Five, "第五"));
_expected.Add(new KeyValuePair(TestEnum.All, "全部"));
CollectionAssert.AreEqual(_expected, _actual);
}
}
}