@@ -67,6 +67,7 @@ public void Expression(string commandText, string name, object value)
6767 [ DataRow ( "select 1 from systypes" , 34 , 1 , 1 ) ]
6868 [ DataRow ( "select 1 from systypes as s" , 34 , 1 , 1 ) ]
6969 [ DataRow ( "select name from systypes" , 34 , 34 , "image" ) ]
70+ [ DataRow ( "select 1 + 1 from systypes" , 34 , 1 , 2 ) ]
7071 public void ExpressionFromTable ( string commandText , int minimumRows , int uniqueRows , object value )
7172 {
7273 using var reader = new Simulation ( ) . ExecuteReader ( commandText ) ;
@@ -87,6 +88,7 @@ public void ExpressionFromTable(string commandText, int minimumRows, int uniqueR
8788 [ DataRow ( "select name as c from systypes as s" , 34 , 34 , "c" , "image" ) ]
8889 [ DataRow ( "select systypes.name from systypes" , 34 , 34 , "name" , "image" ) ]
8990 [ DataRow ( "select s.name from systypes as s" , 34 , 34 , "name" , "image" ) ]
91+ [ DataRow ( "select 1 + 1 as c from systypes" , 34 , 1 , "c" , 2 ) ]
9092 public void NamedExpressionFromTable ( string commandText , int minimumRows , int uniqueRows , string name , object value )
9193 {
9294 using var reader = new Simulation ( ) . ExecuteReader ( commandText ) ;
@@ -106,6 +108,29 @@ public void NamedExpressionFromTable(string commandText, int minimumRows, int un
106108 Assert . AreEqual ( value , results [ 0 ] ) ;
107109 }
108110
111+ [ TestMethod ]
112+ [ DataRow ( "select 1 + 1 as x, name as c from systypes" , 34 , "x" , 2 , "c" , "image" ) ]
113+ [ DataRow ( "select 1 + 1, name as c from systypes" , 34 , "" , 2 , "c" , "image" ) ]
114+ public void NamedExpressionAndColumnFromTable ( string commandText , int minimumRows , string name0 , object value0 , string name1 , object value1 )
115+ {
116+ using var reader = new Simulation ( ) . ExecuteReader ( commandText ) ;
117+
118+ var results = reader
119+ . EnumerateRecords ( )
120+ . Take ( minimumRows ) // There might be more someday, but there won't be less.
121+ . Select ( reader =>
122+ {
123+ Assert . AreEqual ( name0 , reader . GetName ( 0 ) ) ;
124+ Assert . AreEqual ( name1 , reader . GetName ( 1 ) ) ;
125+ return ( C0 : reader [ 0 ] , C1 : reader [ 1 ] ) ;
126+ } )
127+ . ToArray ( ) ;
128+
129+ Assert . HasCount ( minimumRows , results ) ;
130+ Assert . AreEqual ( value0 , results [ 0 ] . C0 ) ;
131+ Assert . AreEqual ( value1 , results [ 0 ] . C1 ) ;
132+ }
133+
109134 [ TestMethod ]
110135 public void Select1Comma2 ( )
111136 {
@@ -147,6 +172,21 @@ public void SelectSyntaxErrorsAreCorrect(string commandText, string nearSyntax)
147172 new Simulation ( ) . ValidateSyntaxError ( commandText , nearSyntax ) ;
148173
149174 [ TestMethod ]
150- public void SelectFromDerivedTable ( ) =>
151- Assert . AreEqual ( 1 , new Simulation ( ) . ExecuteScalar ( "select x from ( select 1 as x ) as x" ) ) ;
175+ [ DataRow ( "select x from ( select 1 as x ) as x" , "x" , 1 ) ]
176+ [ DataRow ( "select x from ( select 1 + 1 as x ) as x" , "x" , 2 ) ]
177+ public void DerivedTable ( string commandText , string name , object value )
178+ {
179+ using var reader = new Simulation ( ) . ExecuteReader ( commandText ) ;
180+
181+ var result = reader
182+ . EnumerateRecords ( )
183+ . Select ( reader =>
184+ {
185+ Assert . AreEqual ( name , reader . GetName ( 0 ) ) ;
186+ return reader [ 0 ] ;
187+ } )
188+ . SingleOrDefault ( ) ;
189+
190+ Assert . AreEqual ( value , result ) ;
191+ }
152192}
0 commit comments