Esempio n. 1
0
 public void Test_Parse_MemberIsEmpty(string member)
 {
     AssertHelper.Throws <ArgumentNullException>(() =>
     {
         Enum.Parse <EnumSample>(member);
     }, "member");
 }
Esempio n. 2
0
 public void Test_ParseByDescription_MemberIsEmpty(string desc)
 {
     AssertHelper.Throws <ArgumentNullException>(() =>
     {
         Enum.ParseByDescription <EnumSample>(desc);
     }, "desc");
 }
Esempio n. 3
0
        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]);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 /// <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;
     }
 }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
 public void Test_ParseByDescription_Nullable(string member, EnumSample?sample)
 {
     Assert.Equal(sample, Enum.ParseByDescription <EnumSample?>(member));
 }
Esempio n. 9
0
 public void Test_ParseByDescription(string desc, EnumSample sample)
 {
     Assert.Equal(sample, Enum.ParseByDescription <EnumSample>(desc));
 }
Esempio n. 10
0
 public void Test_Parse(string member, EnumSample sample)
 {
     Assert.Equal(sample, Enum.Parse <EnumSample>(member));
 }
Esempio n. 11
0
 public void Test_GetItems_Validate()
 {
     AssertHelper.Throws <InvalidOperationException>(() => {
         Enum.GetItems <Sample>();
     }, "类型 Bing.Tests.Samples.Sample 不是枚举");
 }
Esempio n. 12
0
 public void Test_GetDescription_Nullable(object member, string description)
 {
     Assert.Equal(description, Enum.GetDescription <EnumSample?>(member));
 }
Esempio n. 13
0
 public void Test_GetValue_Nullable(object member, int value)
 {
     Assert.Equal(value, Enum.GetValue <EnumSample?>(member));
 }
Esempio n. 14
0
 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");
 }
Esempio n. 15
0
 public void Test_GetName_Nullable(object member, string name)
 {
     Assert.Equal(name, Enum.GetName <EnumSample?>(member));
 }
Esempio n. 16
0
 public void Test_GetName_Validate()
 {
     Assert.Equal(string.Empty, Enum.GetName(typeof(Sample), 3));
 }