public void Test_Parse_MemberIsEmpty(string member) { AssertHelper.Throws <ArgumentNullException>(() => { Enum.Parse <EnumSample>(member); }, "member"); }
public void Test_ParseByDescription_MemberIsEmpty(string desc) { AssertHelper.Throws <ArgumentNullException>(() => { Enum.ParseByDescription <EnumSample>(desc); }, "desc"); }
public void Test_GetNames() { var names = Enum.GetNames <EnumSample>().OrderBy(t => t).ToList(); Assert.Equal(5, names.Count); Assert.Equal("A", names[0]); Assert.Equal("D", names[3]); Assert.Equal("E", names[4]); }
public void Test_GetItems() { var items = Enum.GetItems <EnumSample>(); Assert.Equal(5, items.Count); Assert.Equal("A", items[0].Text); Assert.Equal(1, items[0].Value); Assert.Equal("D4", items[3].Text); Assert.Equal(4, items[3].Value); Assert.Equal("E5", items[4].Text); Assert.Equal(5, items[4].Value); }
public void Test_GetItems_Nullable_Type() { var items = Enum.GetItems(typeof(EnumSample?)); Assert.Equal(5, items.Count); Assert.Equal("A", items[0].Text); Assert.Equal(1, items[0].Value); Assert.Equal("D4", items[3].Text); Assert.Equal(4, items[3].Value); Assert.Equal("E5", items[4].Text); Assert.Equal(5, items[4].Value); }
/// <summary> /// 执行 /// </summary> /// <param name="level">日志级别</param> /// <param name="content">日志内容</param> protected virtual void Execute(LogLevel level, ref TContent content) { if (content == null) return; if (Enabled(level) == false) return; try { content.Level = Enum.GetName<LogLevel>(level); Init(content); Provider.WriteLog(level, content); } finally { content = null; } }
/// <summary> /// 获取值 /// </summary> /// <param name="expression">表达式</param> public object GetValue(Expression expression) { if (expression == null) { return(null); } var result = Lambdas.GetValue(expression); if (result == null) { return(null); } var type = result.GetType(); if (type.IsEnum) { return(Enum.GetValue(type, result)); } return(result); }
public void Test_ParseByDescription_Nullable(string member, EnumSample?sample) { Assert.Equal(sample, Enum.ParseByDescription <EnumSample?>(member)); }
public void Test_ParseByDescription(string desc, EnumSample sample) { Assert.Equal(sample, Enum.ParseByDescription <EnumSample>(desc)); }
public void Test_Parse(string member, EnumSample sample) { Assert.Equal(sample, Enum.Parse <EnumSample>(member)); }
public void Test_GetItems_Validate() { AssertHelper.Throws <InvalidOperationException>(() => { Enum.GetItems <Sample>(); }, "类型 Bing.Tests.Samples.Sample 不是枚举"); }
public void Test_GetDescription_Nullable(object member, string description) { Assert.Equal(description, Enum.GetDescription <EnumSample?>(member)); }
public void Test_GetValue_Nullable(object member, int value) { Assert.Equal(value, Enum.GetValue <EnumSample?>(member)); }
public void Test_GetValue_Validate() { AssertHelper.Throws <ArgumentNullException>(() => Enum.GetValue <EnumSample>(null), "member"); AssertHelper.Throws <ArgumentNullException>(() => Enum.GetValue <EnumSample>(string.Empty), "member"); AssertHelper.Throws <ArgumentNullException>(() => Enum.GetValue <Sample>(string.Empty), "member"); }
public void Test_GetName_Nullable(object member, string name) { Assert.Equal(name, Enum.GetName <EnumSample?>(member)); }
public void Test_GetName_Validate() { Assert.Equal(string.Empty, Enum.GetName(typeof(Sample), 3)); }