1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
.Generator
.Components
.Tests
18 using System
.Data
.OleDb
;
20 using NUnit
.Framework
;
22 using Castle
.ActiveRecord
.Generator
.Components
.Database
;
26 public class PlainFieldInferenceServiceTestCase
: AbstractContainerTestCase
29 public void BlogPlainFields()
31 Kernel
.AddComponent( "plainfields", typeof(IPlainFieldInferenceService
), typeof(PlainFieldInferenceService
) );
32 Kernel
.AddComponent( "nameService", typeof(INamingService
), typeof(NamingService
) );
33 Kernel
.AddComponent( "typeinf", typeof(ITypeInferenceService
), typeof(TypeInferenceService
) );
35 IPlainFieldInferenceService plainService
= Kernel
[ typeof(IPlainFieldInferenceService
) ] as IPlainFieldInferenceService
;
37 TableDefinition table
= new TableDefinition("blogs", new DatabaseDefinition("alias") );
38 table
.AddColumn( new ColumnDefinition("id", true, false, true, false, OleDbType
.Integer
) );
39 table
.AddColumn( new ColumnDefinition("name", false, false, false, false, OleDbType
.VarChar
) );
40 table
.AddColumn( new ColumnDefinition("authorid", false, true, false, false, OleDbType
.VarChar
) );
42 ActiveRecordPropertyDescriptor
[] descs
= plainService
.InferProperties( table
);
44 Assert
.IsNotNull(descs
);
45 Assert
.AreEqual( 2, descs
.Length
);
47 ActiveRecordPropertyDescriptor desc1
= descs
[0];
48 ActiveRecordPropertyDescriptor desc2
= descs
[1];
50 Assert
.AreEqual( "id", desc1
.ColumnName
);
51 Assert
.AreEqual( "Integer", desc1
.ColumnTypeName
);
52 Assert
.AreEqual( "Id", desc1
.PropertyName
);
53 Assert
.AreEqual( typeof(int), desc1
.PropertyType
);
55 Assert
.AreEqual( "name", desc2
.ColumnName
);
56 Assert
.AreEqual( "VarChar", desc2
.ColumnTypeName
);
57 Assert
.AreEqual( "Name", desc2
.PropertyName
);
58 Assert
.AreEqual( typeof(String
), desc2
.PropertyType
);