moved tests to compose_namespace instead of compose_connection, marked compose_connec...
[dbsrgits/DBIx-Class.git] / t / 74mssql.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
9
10 #warn "$dsn $user $pass";
11
12 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test'
13   unless ($dsn);
14
15 plan tests => 4;
16
17 my $storage_type = '::DBI::MSSQL';
18 $storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/;
19 # Add more for others in the future when they exist (ODBC? ADO? JDBC?)
20
21 DBICTest::Schema->storage_type($storage_type);
22 DBICTest::Schema->compose_namespace( 'MSSQLTest' => $dsn, $user, $pass );
23
24 my $dbh = MSSQLTest->schema->storage->dbh;
25
26 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
27     DROP TABLE artist");
28
29 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));");
30
31 MSSQLTest::Artist->load_components('PK::Auto::MSSQL');
32
33 # Test PK
34 my $new = MSSQLTest::Artist->create( { name => 'foo' } );
35 ok($new->artistid, "Auto-PK worked");
36
37 # Test LIMIT
38 for (1..6) {
39     MSSQLTest::Artist->create( { name => 'Artist ' . $_ } );
40 }
41
42 my $it = MSSQLTest::Artist->search( { },
43     { rows     => 3,
44       offset   => 2,
45       order_by => 'artistid'
46     }
47 );
48
49 is( $it->count, 3, "LIMIT count ok" );
50 ok( $it->next->name, "iterator->next ok" );
51 $it->next;
52 $it->next;
53 is( $it->next, undef, "next past end of resultset ok" );
54