Merge all static runtime libs into libmono-static.
[mono.git] / mcs / tests / gtest-linq-09.cs
1
2
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6
7 class Data
8 {
9         public int Key;
10         public string Value;
11 }
12
13 class Join
14 {
15         public static int Main ()
16         {
17                 Data[] d1 = new Data[] { new Data () { Key = 1, Value = "First" } };
18                 Data[] d2 = new Data[] { 
19                         new Data () { Key = 1, Value = "Second" },
20                         new Data () { Key = 1, Value = "Third" }
21                 };
22
23                 
24                 var e = from a in d1
25                         join b in d2 on a.Key equals b.Key
26                         select new { Result = a.Value + b.Value };
27
28                 var res = e.ToList ();
29                 if (res.Count != 2)
30                         return 1;
31                 
32                 if (res [0].Result != "FirstSecond")
33                         return 2;
34                         
35                 if (res [1].Result != "FirstThird")
36                         return 3;
37                         
38                 e = from Data a in d1
39                         join b in d2 on a.Key equals b.Key
40                         where b.Value == "Second"
41                         select new { Result = a.Value + b.Value };
42                         
43                 res = e.ToList ();
44                 if (res.Count != 1)
45                         return 4;
46                 
47                 if (res [0].Result != "FirstSecond")
48                         return 5;               
49                         
50                 // Explicitly typed
51                 e = from Data a in d1
52             join Data b in d2 on a.Key equals b.Key
53             select new { Result = a.Value + b.Value };
54                 
55                 res = e.ToList ();
56                 if (res.Count != 2)
57                         return 10;
58                 
59                 if (res [0].Result != "FirstSecond")
60                         return 11;
61                         
62                 if (res [1].Result != "FirstThird")
63                         return 12;
64                 
65                 var e2 = from Data a in d1
66                         join b in d2 on a.Key equals b.Key
67                         group b by a.Key;
68
69                 var res2 = e2.ToList ();
70                 if (res2.Count != 1)
71                         return 20;
72                 
73                 if (res2 [0].Key != 1)
74                         return 21;
75                         
76                 Console.WriteLine ("OK");
77                 return 0;
78         }
79 }
80