1
+ using System ;
2
+ using System . Collections ;
3
+ using System . Collections . Generic ;
4
+ using System . IO ;
5
+ using System . Reflection ;
6
+ using NHibernate . Cfg ;
7
+ using NHibernate . Criterion ;
8
+ using NHibernate . Engine ;
9
+ using NHibernate . Tool . hbm2ddl ;
10
+ using NUnit . Framework ;
11
+
12
+ namespace NHibernate . Test . NHSpecificTest . NH1274ExportExclude
13
+ {
14
+ [ TestFixture ]
15
+ public class NH1274ExportExcludeFixture
16
+ {
17
+
18
+ [ Test ]
19
+ public void SchemaExport_Drop_CreatesDropScript ( )
20
+ {
21
+ Configuration configuration = GetConfiguration ( ) ;
22
+ SchemaExport export = new SchemaExport ( configuration ) ;
23
+ TextWriter tw = new StringWriter ( ) ;
24
+ Console . SetOut ( tw ) ;
25
+ export . Drop ( true , false ) ;
26
+ string s = tw . ToString ( ) ;
27
+ Assert . IsTrue ( s . Contains ( "drop table Home_Drop" ) ) ;
28
+ Assert . IsTrue ( s . Contains ( "drop table Home_All" ) ) ;
29
+ }
30
+
31
+ [ Test ]
32
+ public void SchemaExport_Export_CreatesExportScript ( )
33
+ {
34
+ Configuration configuration = GetConfiguration ( ) ;
35
+ SchemaExport export = new SchemaExport ( configuration ) ;
36
+ TextWriter tw = new StringWriter ( ) ;
37
+ Console . SetOut ( tw ) ;
38
+ export . Create ( true , false ) ;
39
+ string s = tw . ToString ( ) ;
40
+ Assert . IsTrue ( s . Contains ( "drop table Home_Drop" ) ) ;
41
+ Assert . IsTrue ( s . Contains ( "drop table Home_All" ) ) ;
42
+ Assert . IsTrue ( s . Contains ( "create table Home_All" ) ) ;
43
+ Assert . IsTrue ( s . Contains ( "create table Home_Export" ) ) ;
44
+ }
45
+
46
+ [ Test ]
47
+ public void SchemaExport_Update_CreatesUpdateScript ( )
48
+ {
49
+ Configuration configuration = GetConfiguration ( ) ;
50
+ SchemaUpdate update = new SchemaUpdate ( configuration ) ;
51
+ TextWriter tw = new StringWriter ( ) ;
52
+ Console . SetOut ( tw ) ;
53
+ update . Execute ( true , false ) ;
54
+
55
+ string s = tw . ToString ( ) ;
56
+ Assert . IsTrue ( s . Contains ( "create table Home_Update" ) ) ;
57
+ Assert . IsTrue ( s . Contains ( "create table Home_All" ) ) ;
58
+ }
59
+
60
+ [ Test ]
61
+ public void SchemaExport_Validate_CausesValidateException ( )
62
+ {
63
+ Configuration configuration = GetConfiguration ( ) ;
64
+ SchemaValidator validator = new SchemaValidator ( configuration ) ;
65
+ try
66
+ {
67
+ validator . Validate ( ) ;
68
+ }
69
+ catch ( HibernateException he )
70
+ {
71
+ Assert . IsTrue ( he . Message . Contains ( "Home_Validate" ) ) ;
72
+ return ;
73
+ }
74
+ throw new Exception ( "Should not get to this exception" ) ;
75
+ }
76
+
77
+ private Configuration GetConfiguration ( )
78
+ {
79
+ Configuration cfg = new Configuration ( ) ;
80
+ if ( TestConfigurationHelper . hibernateConfigFile != null )
81
+ cfg . Configure ( TestConfigurationHelper . hibernateConfigFile ) ;
82
+
83
+ Assembly assembly = Assembly . Load ( MappingsAssembly ) ;
84
+
85
+ foreach ( string file in Mappings )
86
+ {
87
+ cfg . AddResource ( MappingsAssembly + "." + file , assembly ) ;
88
+ }
89
+ return cfg ;
90
+ }
91
+
92
+
93
+ protected static string MappingsAssembly
94
+ {
95
+ get { return "NHibernate.Test" ; }
96
+ }
97
+
98
+ public virtual string BugNumber
99
+ {
100
+ get
101
+ {
102
+ string ns = GetType ( ) . Namespace ;
103
+ return ns . Substring ( ns . LastIndexOf ( '.' ) + 1 ) ;
104
+ }
105
+ }
106
+
107
+ protected IList Mappings
108
+ {
109
+ get
110
+ {
111
+ return new string [ ]
112
+ {
113
+ "NHSpecificTest." + BugNumber + ".Mappings.hbm.xml"
114
+ } ;
115
+ }
116
+ }
117
+ }
118
+ }
0 commit comments