public void Query_ExecuteScalarReturnsNullIfEmpty() { var dataTable = TestData.IdNameTable(); var dataContext = DataContext.Default.AddTables(dataTable); var query = Query.Create(dataContext, "SELECT * FROM Table WHERE FALSE"); var result = query.ExecuteScalar(); Assert.Equal(null, result); }
public void Query_ExecuteScalarReturnsFirstValue() { var dataTable = TestData.IdNameTable(); var dataContext = DataContext.Default.AddTables(dataTable); var query = Query.Create(dataContext, "SELECT * FROM Table"); var result = query.ExecuteScalar(); var expected = dataTable.Rows[0][0]; Assert.Equal(expected, result); }
public void Query_ExecuteScalarOfTThrows_IfTypeDoesNotMatch() { var dataTable = TestData.IdNameTable(); var dataContext = DataContext.Default.AddTables(dataTable); var query = Query.Create(dataContext, "SELECT * FROM Table"); Assert.Throws <InvalidCastException>(() => { query.ExecuteScalar <string>(); }); }
public static Compilation WithIdNameTable(this Compilation compilation) { var table = TestData.IdNameTable(); return(compilation.WithDataContext(DataContext.Default.AddTables(table))); }