ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
using iWareCommon.Utils;
using iWareSql.DBModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareUnitTest
{
    [TestClass]
    public class CSharpTest
    {
        [TestMethod]
        public void Test_EF_OrderBy()
        {
            Task_Main a1 = new Task_Main();
            a1.Id = 1;
            a1.CreateTime = Convert.ToDateTime("2022-05-21 08:55:01.000");
            a1.TaskSequence = 55;
 
            Task_Main a2 = new Task_Main();
            a2.Id = 2;
            a2.CreateTime = Convert.ToDateTime("2022-05-21 08:55:02.000");
            a2.TaskSequence = 55;
 
            Task_Main a3 = new Task_Main();
            a3.Id = 3;
            a3.CreateTime = Convert.ToDateTime("2022-05-21 08:56:01.000");
            a3.TaskSequence = 55;
 
 
            Task_Main a4 = new Task_Main();
            a4.Id = 4;
            a4.CreateTime = Convert.ToDateTime("2022-05-21 08:56:00.000");
            a4.TaskSequence = 51;
 
            Task_Main a5 = new Task_Main();
            a5.Id = 5;
            a5.CreateTime = Convert.ToDateTime("2022-05-21 08:56:01.000");
            a5.TaskSequence = 57;
 
            List<Task_Main> mainList = new List<Task_Main>();
            mainList.Add(a1);
            mainList.Add(a2);
            mainList.Add(a3);
            mainList.Add(a4);
            mainList.Add(a5);
 
            var bb = mainList.OrderBy(x => x.TaskSequence).ThenBy(x => x.CreateTime).ToList();
            /*
             *  证明排序是 先按照TaskSequence排序,如果TaskSequence相等,就按照CreateTime内部小排序。
             */
            string zz = JsonConvert.SerializeObject(bb);
            Assert.IsFalse(false);
 
        }
 
        [TestMethod]
        public void Test_ExecPercentRetInt()
        {
            int i = CSharpHelper.ExecPercentRetInt(22, 24);
 
            Assert.IsFalse(false);
        }
        [TestMethod]
        public void TestDictionary()
        {
            //C#求获取一个Dictionary中value最小的key
            Dictionary<string, int> dict = new Dictionary<string, int>();
            dict.Add("1", 1);
            dict.Add("2", 2);
            dict.Add("3", 3);
            dict.Add("4", 4);
            dict.Add("5", 1);
 
            var minKey = (from d in dict orderby d.Value ascending select d.Key).First();
            //考虑到不止一条的情况,分两步查询最小值的所有Key,这样的写法可能更好看懂
            var allMinKeys = (from d in dict where d.Value == dict[minKey] select d.Key).ToArray();
 
            var minkey = dict.Keys.Select(x => new { x, y = dict[x] }).OrderBy(x => x.y).First().x;
 
 
            var bb = dict.OrderBy(d => d.Value).Select(d => d.Key).FirstOrDefault();
 
 
            Assert.IsFalse(false);
        }
 
 
        [TestMethod]
        public void TestNull()
        {
            int? aa = null;
            int b = 1 + (int)aa;
            Assert.IsFalse(false);
        }
 
        [TestMethod]
        public void TestList()
        {
            List<string> sList = new List<string>();
            sList.Add("zzz");
            sList.Add("888");
            string cc = JsonConvert.SerializeObject(sList);
        }
    }
}