コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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>();
            });
        }
コード例 #4
0
        public static Compilation WithIdNameTable(this Compilation compilation)
        {
            var table = TestData.IdNameTable();

            return(compilation.WithDataContext(DataContext.Default.AddTables(table)));
        }