comparison _test/Test/SQL/Traits.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
10 use IMPL::SQL::Schema; 10 use IMPL::SQL::Schema;
11 use IMPL::SQL::Schema::Traits; 11 use IMPL::SQL::Schema::Traits;
12 use IMPL::SQL::Types qw(Integer Varchar DateTime); 12 use IMPL::SQL::Types qw(Integer Varchar DateTime);
13 13
14 BEGIN { 14 BEGIN {
15 shared public property schema => prop_all; 15 shared public property schema => prop_all;
16 } 16 }
17 17
18 sub StartUnit { 18 sub StartUnit {
19 return { 19 return {
20 schema => new IMPL::SQL::Schema( name => 'testTraits', version => 1 ) 20 schema => new IMPL::SQL::Schema( name => 'testTraits', version => 1 )
21 }; 21 };
22 } 22 }
23 23
24 test CreateTable => sub { 24 test CreateTable => sub {
25 my ($this) = @_; 25 my ($this) = @_;
26 26
27 my $table = $this->schema->AddTable( 27 my $table = $this->schema->AddTable(
28 new IMPL::SQL::Schema::Traits::Table( 28 new IMPL::SQL::Schema::Traits::Table(
29 'user' 29 'user'
30 ) 30 )
31 ) or failed "Failed to create table"; 31 ) or failed "Failed to create table";
32 32
33 $this->schema->GetTable('user') or failed "Can't get a created table"; 33 $this->schema->GetTable('user') or failed "Can't get a created table";
34 34
35 }; 35 };
36 36
37 test InsertColumn => sub { 37 test InsertColumn => sub {
38 my ($this) = @_; 38 my ($this) = @_;
39 39
40 my $table = $this->schema->GetTable('user'); 40 my $table = $this->schema->GetTable('user');
41 41
42 $table->InsertColumn( 42 $table->InsertColumn(
43 new IMPL::SQL::Schema::Traits::Column( 43 new IMPL::SQL::Schema::Traits::Column(
44 id => Integer, tag => { auto_increment => 1 } 44 id => Integer, tag => { auto_increment => 1 }
45 ) 45 )
46 ); 46 );
47 47
48 my $column = $table->GetColumn('id') or failed "Column not found"; 48 my $column = $table->GetColumn('id') or failed "Column not found";
49 49
50 assert( $column->name eq 'id'); 50 assert( $column->name eq 'id');
51 assert( $column->type->SameValue(Integer()) ); 51 assert( $column->type->SameValue(Integer()) );
52 assert( not $column->isNullable ); 52 assert( not $column->isNullable );
53 assert( $column->tag->{auto_increment} ); 53 assert( $column->tag->{auto_increment} );
54 54
55 $table->InsertColumn( 55 $table->InsertColumn(
56 new IMPL::SQL::Schema::Traits::Column( 56 new IMPL::SQL::Schema::Traits::Column(
57 name => Varchar(255), isNullable => 1 57 name => Varchar(255), isNullable => 1
58 ) 58 )
59 ); 59 );
60 60
61 $column = $table->GetColumn('name'); 61 $column = $table->GetColumn('name');
62 62
63 assert($column); 63 assert($column);
64 assert($column->name eq 'name'); 64 assert($column->name eq 'name');
65 assert($column->type->SameValue(Varchar(255))); 65 assert($column->type->SameValue(Varchar(255)));
66 assert($column->isNullable); 66 assert($column->isNullable);
67 }; 67 };
68 68
69 test CreateTableWithColumns => sub { 69 test CreateTableWithColumns => sub {
70 my ($this) = @_; 70 my ($this) = @_;
71 71
72 my $table = $this->schema->AddTable( 72 my $table = $this->schema->AddTable(
73 new IMPL::SQL::Schema::Traits::Table( 73 new IMPL::SQL::Schema::Traits::Table(
74 session => [ 74 session => [
75 new IMPL::SQL::Schema::Traits::Column( id => Varchar(64)), 75 new IMPL::SQL::Schema::Traits::Column( id => Varchar(64)),
76 new IMPL::SQL::Schema::Traits::Column( expires => DateTime ), 76 new IMPL::SQL::Schema::Traits::Column( expires => DateTime ),
77 new IMPL::SQL::Schema::Traits::Column( role => Varchar(64), defaultValue => 'user' ) 77 new IMPL::SQL::Schema::Traits::Column( role => Varchar(64), defaultValue => 'user' )
78 ] 78 ]
79 ) 79 )
80 ) or failed "Failed to create table"; 80 ) or failed "Failed to create table";
81 81
82 assert( $table->ColumnsCount == 3 ); 82 assert( $table->ColumnsCount == 3 );
83 83
84 assert( my $column = $table->GetColumn('id') ); 84 assert( my $column = $table->GetColumn('id') );
85 assert($column->type->SameValue(Varchar(64))); 85 assert($column->type->SameValue(Varchar(64)));
86 assert(not $column->isNullable); 86 assert(not $column->isNullable);
87 87
88 assert( $column = $table->GetColumn('role') ); 88 assert( $column = $table->GetColumn('role') );
89 assert( $column->defaultValue eq 'user' ); 89 assert( $column->defaultValue eq 'user' );
90 }; 90 };
91 91
92 sub FinishUnit { 92 sub FinishUnit {
93 my ($self,$session) = @_; 93 my ($self,$session) = @_;
94 94
95 $self->supercall::FinishUnit(); 95 $self->supercall::FinishUnit();
96 96
97 $session->{schema}->Dispose(); 97 $session->{schema}->Dispose();
98 } 98 }
99 99
100 1; 100 1;