comparison _test/Test/SQL/Schema.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 6148f89bb7bf
children 4ddb27ff4a0b
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
72 }); 72 });
73 73
74 }; 74 };
75 75
76 test SetPrimaryKey => sub { 76 test SetPrimaryKey => sub {
77 my ($this) = @_; 77 my ($this) = @_;
78 78
79 my $tableUser = $this->schemaDB->GetTable('User'); 79 my $tableUser = $this->schemaDB->GetTable('User');
80 my $tableRole = $this->schemaDB->GetTable('Role'); 80 my $tableRole = $this->schemaDB->GetTable('Role');
81 81
82 $tableUser->AddConstraint( pk => { columns => ['Id'], name => 'PK' }); 82 $tableUser->AddConstraint( pk => { columns => ['Id'], name => 'PK' });
83 $tableRole->SetPrimaryKey('Id'); 83 $tableRole->SetPrimaryKey('Id');
84 84
85 $tableUser->primaryKey->HasColumn('Id') or failed "A primary key of 'User' table should contain 'Id' column"; 85 $tableUser->primaryKey->HasColumn('Id') or failed "A primary key of 'User' table should contain 'Id' column";
86 $tableRole->primaryKey->HasColumn('Id') or failed "A primary key of 'Role' table should contain 'Id' column"; 86 $tableRole->primaryKey->HasColumn('Id') or failed "A primary key of 'Role' table should contain 'Id' column";
87 87
88 }; 88 };
89 89
90 test LinkTables => sub { 90 test LinkTables => sub {
91 my ($this) = @_; 91 my ($this) = @_;
92 92
93 my $tableUser = $this->schemaDB->GetTable('User'); 93 my $tableUser = $this->schemaDB->GetTable('User');
94 my $tableRole = $this->schemaDB->GetTable('Role'); 94 my $tableRole = $this->schemaDB->GetTable('Role');
95 95
96 $tableUser->LinkTo($tableRole,'RoleId'); 96 $tableUser->LinkTo($tableRole,'RoleId');
97 97
98 $tableUser->GetColumnConstraints('RoleId') == 1 or failed "Wrong constraints count for 'RoleId' column", $tableUser->GetColumnConstraints('RoleId'); 98 $tableUser->GetColumnConstraints('RoleId') == 1 or failed "Wrong constraints count for 'RoleId' column", $tableUser->GetColumnConstraints('RoleId');
99 }; 99 };
100 100
101 test AddConstraint => sub { 101 test AddConstraint => sub {
102 my ($this) = @_; 102 my ($this) = @_;
103 103
114 failed "Failed to retrieve a constraint" unless ($table->GetColumnConstraints('ObsoleteId'))[0] == $constraint; 114 failed "Failed to retrieve a constraint" unless ($table->GetColumnConstraints('ObsoleteId'))[0] == $constraint;
115 115
116 }; 116 };
117 117
118 test RemoveConstraint => sub { 118 test RemoveConstraint => sub {
119 my ($this) = @_; 119 my ($this) = @_;
120 120
121 my $table = $this->schemaDB->GetTable('Role') or failed "Failed to get a table"; 121 my $table = $this->schemaDB->GetTable('Role') or failed "Failed to get a table";
122 my $constraint = $table->GetConstraint('Role_ObsoleteId_Uniq'); 122 my $constraint = $table->GetConstraint('Role_ObsoleteId_Uniq');
123 123
124 eval { 124 eval {
125 $table->RemoveColumn('ObsoleteId'); 125 $table->RemoveColumn('ObsoleteId');
126 1; 126 1;
127 } and failed "Should not remove column with constraint"; 127 } and failed "Should not remove column with constraint";
128 128
129 $table->RemoveColumn('ObsoleteId','force'); 129 $table->RemoveColumn('ObsoleteId','force');
130 130
131 failed "A constraint remains alive after column deletion" unless $constraint->isDisposed; 131 failed "A constraint remains alive after column deletion" unless $constraint->isDisposed;
132 132
133 }; 133 };
134 134
135 test RemoveTable => sub { 135 test RemoveTable => sub {
136 my ($this) = @_; 136 my ($this) = @_;
137 137
138 my $table = $this->schemaDB->GetTable('Role') or failed "Failed to get a table"; 138 my $table = $this->schemaDB->GetTable('Role') or failed "Failed to get a table";
139 139
140 $this->schemaDB->RemoveTable('Role'); 140 $this->schemaDB->RemoveTable('Role');
141 141
142 $table->isDisposed or failed "A table remains alive after deletion"; 142 $table->isDisposed or failed "A table remains alive after deletion";
143 143
144 my $table2 = $this->schemaDB->GetTable('User'); 144 my $table2 = $this->schemaDB->GetTable('User');
145 145
146 $table2->GetColumnConstraints('RoleId') == 0 or failed "A foreign key keept alive"; 146 $table2->GetColumnConstraints('RoleId') == 0 or failed "A foreign key keept alive";
147 }; 147 };
148 148
149 test Clone => sub { 149 test Clone => sub {
150 my ($this) = @_; 150 my ($this) = @_;
151 151
152 my $clone1 = $this->schemaDB->Clone(); 152 my $clone1 = $this->schemaDB->Clone();
153 153
154 $clone1->Dispose(); 154 $clone1->Dispose();
155 155
156 $this->schemaDB->isDisposed and failed "An original schema should not be disposed"; 156 $this->schemaDB->isDisposed and failed "An original schema should not be disposed";
157 }; 157 };
158 158
159 test Dispose => sub { 159 test Dispose => sub {
160 my ($this) = @_; 160 my ($this) = @_;
161 161