@@ -318,9 +318,13 @@ public void TypeProperty_CaseInsensitiveProperty()
318318
319319 // === OBJECTPROPERTYEX ===
320320
321+ /// <summary>
322+ /// OBJECTPROPERTYEX projects sql_variant; the boolean Is-X properties
323+ /// carry an int inner base type, which SqlClient unwraps to an int.
324+ /// </summary>
321325 [ TestMethod ]
322326 public void ObjectPropertyEx_IsTable_OnTable_Returns1 ( )
323- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
327+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
324328 "create table t (id int); " +
325329 "select objectpropertyex(object_id('t'), 'IsTable')" ) ) ;
326330
@@ -346,88 +350,128 @@ public void ObjectPropertyEx_BaseType_Procedure_Returns_P()
346350 AreEqual ( "P " , sim . ExecuteScalar ( "select objectpropertyex(object_id('p'), 'BaseType')" ) ) ;
347351 }
348352
353+ /// <summary>
354+ /// SchemaId's inner base type is int.
355+ /// </summary>
349356 [ TestMethod ]
350357 public void ObjectPropertyEx_SchemaId_Dbo_Returns1 ( )
351- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
358+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
352359 "create table t (id int); " +
353360 "select objectpropertyex(object_id('t'), 'SchemaId')" ) ) ;
354361
362+ /// <summary>
363+ /// Cardinality's inner base type is bigint, which unwraps to a long.
364+ /// </summary>
355365 [ TestMethod ]
356366 public void ObjectPropertyEx_Cardinality_EmptyTable_Returns0 ( )
357- => AreEqual ( "0" , new Simulation ( ) . ExecuteScalar (
367+ => AreEqual ( 0L , new Simulation ( ) . ExecuteScalar (
358368 "create table t (id int); " +
359369 "select objectpropertyex(object_id('t'), 'Cardinality')" ) ) ;
360370
361371 [ TestMethod ]
362372 public void ObjectPropertyEx_Cardinality_ThreeRows_Returns3 ( )
363- => AreEqual ( "3" , new Simulation ( ) . ExecuteScalar (
373+ => AreEqual ( 3L , new Simulation ( ) . ExecuteScalar (
364374 "create table t (id int); " +
365375 "insert t values (1), (2), (3); " +
366376 "select objectpropertyex(object_id('t'), 'Cardinality')" ) ) ;
367377
368378 [ TestMethod ]
369379 public void ObjectPropertyEx_TableHasIdentity_WithIdentity_Returns1 ( )
370- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
380+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
371381 "create table t (id int identity(1,1) primary key); " +
372382 "select objectpropertyex(object_id('t'), 'TableHasIdentity')" ) ) ;
373383
374384 [ TestMethod ]
375385 public void ObjectPropertyEx_TableHasIdentity_NoIdentity_Returns0 ( )
376- => AreEqual ( "0" , new Simulation ( ) . ExecuteScalar (
386+ => AreEqual ( 0 , new Simulation ( ) . ExecuteScalar (
377387 "create table t (id int); " +
378388 "select objectpropertyex(object_id('t'), 'TableHasIdentity')" ) ) ;
379389
380390 [ TestMethod ]
381391 public void ObjectPropertyEx_TableHasPrimaryKey_WithPK_Returns1 ( )
382- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
392+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
383393 "create table t (id int primary key); " +
384394 "select objectpropertyex(object_id('t'), 'TableHasPrimaryKey')" ) ) ;
385395
386396 [ TestMethod ]
387397 public void ObjectPropertyEx_TableHasPrimaryKey_NoPK_Returns0 ( )
388- => AreEqual ( "0" , new Simulation ( ) . ExecuteScalar (
398+ => AreEqual ( 0 , new Simulation ( ) . ExecuteScalar (
389399 "create table t (id int); " +
390400 "select objectpropertyex(object_id('t'), 'TableHasPrimaryKey')" ) ) ;
391401
392402 [ TestMethod ]
393403 public void ObjectPropertyEx_TableHasUniqueCnst_WithUnique_Returns1 ( )
394- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
404+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
395405 "create table t (id int, name varchar(50), constraint uq unique (name)); " +
396406 "select objectpropertyex(object_id('t'), 'TableHasUniqueCnst')" ) ) ;
397407
398408 [ TestMethod ]
399409 public void ObjectPropertyEx_TableHasCheckCnst_WithCheck_Returns1 ( )
400- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
410+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
401411 "create table t (id int, check (id > 0)); " +
402412 "select objectpropertyex(object_id('t'), 'TableHasCheckCnst')" ) ) ;
403413
404414 [ TestMethod ]
405415 public void ObjectPropertyEx_TableHasForeignKey_WithFK_Returns1 ( )
406- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
416+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
407417 "create table p (id int primary key); " +
408418 "create table c (id int primary key, p_id int references p(id)); " +
409419 "select objectpropertyex(object_id('c'), 'TableHasForeignKey')" ) ) ;
410420
411421 [ TestMethod ]
412422 public void ObjectPropertyEx_TableHasForeignRef_WithIncoming_Returns1 ( )
413- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
423+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
414424 "create table p (id int primary key); " +
415425 "create table c (id int primary key, p_id int references p(id)); " +
416426 "select objectpropertyex(object_id('p'), 'TableHasForeignRef')" ) ) ;
417427
418428 [ TestMethod ]
419429 public void ObjectPropertyEx_TableHasIndex_WithIndex_Returns1 ( )
420- => AreEqual ( "1" , new Simulation ( ) . ExecuteScalar (
430+ => AreEqual ( 1 , new Simulation ( ) . ExecuteScalar (
421431 "create table t (id int, name varchar(50)); " +
422432 "create index ix on t(name); " +
423433 "select objectpropertyex(object_id('t'), 'TableHasIndex')" ) ) ;
424434
425435 [ TestMethod ]
426436 public void ObjectPropertyEx_TableHasRowGuidCol_AlwaysZero ( )
427- => AreEqual ( "0" , new Simulation ( ) . ExecuteScalar (
437+ => AreEqual ( 0 , new Simulation ( ) . ExecuteScalar (
428438 "create table t (id int); " +
429439 "select objectpropertyex(object_id('t'), 'TableHasRowGuidCol')" ) ) ;
430440
441+ [ TestMethod ]
442+ public void ObjectPropertyEx_ProjectsSqlVariant ( )
443+ {
444+ using var reader = new Simulation ( ) . ExecuteReader (
445+ "create table t (id int); " +
446+ "select objectpropertyex(object_id('t'), 'SchemaId')" ) ;
447+ IsTrue ( reader . Read ( ) ) ;
448+ AreEqual ( "sql_variant" , reader . GetDataTypeName ( 0 ) ) ;
449+ }
450+
451+ [ TestMethod ]
452+ public void ObjectPropertyEx_BaseType_InnerBaseTypeIsChar ( )
453+ => AreEqual ( "char" , new Simulation ( ) . ExecuteScalar (
454+ "create table t (id int); " +
455+ "select sql_variant_property(objectpropertyex(object_id('t'), 'BaseType'), 'BaseType')" ) ) ;
456+
457+ [ TestMethod ]
458+ public void ObjectPropertyEx_SchemaId_InnerBaseTypeIsInt ( )
459+ => AreEqual ( "int" , new Simulation ( ) . ExecuteScalar (
460+ "create table t (id int); " +
461+ "select sql_variant_property(objectpropertyex(object_id('t'), 'SchemaId'), 'BaseType')" ) ) ;
462+
463+ [ TestMethod ]
464+ public void ObjectPropertyEx_Cardinality_InnerBaseTypeIsBigInt ( )
465+ => AreEqual ( "bigint" , new Simulation ( ) . ExecuteScalar (
466+ "create table t (id int); " +
467+ "select sql_variant_property(objectpropertyex(object_id('t'), 'Cardinality'), 'BaseType')" ) ) ;
468+
469+ [ TestMethod ]
470+ public void ObjectPropertyEx_TableHasIdentity_InnerBaseTypeIsInt ( )
471+ => AreEqual ( "int" , new Simulation ( ) . ExecuteScalar (
472+ "create table t (id int identity(1,1)); " +
473+ "select sql_variant_property(objectpropertyex(object_id('t'), 'TableHasIdentity'), 'BaseType')" ) ) ;
474+
431475 [ TestMethod ]
432476 public void ObjectPropertyEx_UnknownProperty_ReturnsNull ( )
433477 => AreEqual ( DBNull . Value , new Simulation ( ) . ExecuteScalar (
0 commit comments