@@ -19,16 +19,44 @@ namespace NHibernate.Test.Tools.hbm2ddl.SchemaValidator
19
19
[ TestFixture ]
20
20
public class SchemaValidateFixtureAsync
21
21
{
22
- [ Test ]
23
- public async Task ShouldVerifySameTableAsync ( )
22
+ private const string _resourcesPrefix = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator." ;
23
+ private const string _version1Resource = _resourcesPrefix + "1_Version.hbm.xml" ;
24
+ private const string _version2Resource = _resourcesPrefix + "2_Version.hbm.xml" ;
25
+ private const string _version3Resource = _resourcesPrefix + "3_Version.hbm.xml" ;
26
+ private Configuration _configuration1 ;
27
+ private SchemaExport _export1 ;
28
+
29
+ [ OneTimeSetUp ]
30
+ public void OneTimeSetUp ( )
31
+ {
32
+ _configuration1 = BuildConfiguration ( _version1Resource ) ;
33
+ }
34
+
35
+ [ SetUp ]
36
+ public void SetUp ( )
24
37
{
25
- const string resource = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml" ;
26
- var cfg = BuildConfiguration ( resource ) ;
38
+ _export1 = new SchemaExport ( _configuration1 ) ;
39
+ _export1 . Create ( true , true ) ;
40
+ }
27
41
28
- await ( new SchemaExport ( cfg ) . ExecuteAsync ( true , true , false ) ) ;
42
+ [ TearDown ]
43
+ public void TearDown ( )
44
+ {
45
+ _export1 . Drop ( true , true ) ;
46
+ }
29
47
30
- var validator = new Tool . hbm2ddl . SchemaValidator ( ( cfg ) ) ;
31
- await ( validator . ValidateAsync ( ) ) ;
48
+ [ Test ]
49
+ public Task ShouldVerifySameTableAsync ( )
50
+ {
51
+ try
52
+ {
53
+ var validator = new Tool . hbm2ddl . SchemaValidator ( ( _configuration1 ) ) ;
54
+ return validator . ValidateAsync ( ) ;
55
+ }
56
+ catch ( System . Exception ex )
57
+ {
58
+ return Task . FromException < object > ( ex ) ;
59
+ }
32
60
}
33
61
34
62
[ Test , SetCulture ( "tr-TR" ) , SetUICulture ( "tr-TR" ) ]
@@ -45,36 +73,49 @@ public async Task ShouldVerifySameTableTurkishAsync()
45
73
var v = new Version ( ) ;
46
74
Assert . That ( v . Id , Is . TypeOf < int > ( ) ) ;
47
75
76
+ var cfg = BuildConfiguration ( _version1Resource ) ;
48
77
49
- const string resource = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml" ;
50
- var cfg = BuildConfiguration ( resource ) ;
78
+ var export = new SchemaExport ( cfg ) ;
79
+ await ( export . CreateAsync ( true , true ) ) ;
80
+ try
81
+ {
82
+ var validator = new Tool . hbm2ddl . SchemaValidator ( cfg ) ;
83
+ await ( validator . ValidateAsync ( ) ) ;
84
+ }
85
+ finally
86
+ {
87
+ await ( export . DropAsync ( true , true ) ) ;
88
+ }
89
+ }
51
90
52
- await ( new SchemaExport ( cfg ) . ExecuteAsync ( true , true , false ) ) ;
91
+ [ Test ]
92
+ public void ShouldNotVerifyModifiedTableAsync ( )
93
+ {
94
+ var cfgV2 = BuildConfiguration ( _version2Resource ) ;
95
+ var validatorV2 = new Tool . hbm2ddl . SchemaValidator ( cfgV2 ) ;
53
96
54
- var validator = new Tool . hbm2ddl . SchemaValidator ( cfg ) ;
55
- await ( validator . ValidateAsync ( ) ) ;
97
+ Assert . That (
98
+ ( ) => validatorV2 . ValidateAsync ( ) ,
99
+ Throws . TypeOf < SchemaValidationException > ( )
100
+ . And . Message . EqualTo ( "Schema validation failed: see list of validation errors" )
101
+ . And . Property ( "ValidationErrors" ) . Some . Contains ( "Missing column: Name in " ) . IgnoreCase . And . Contains ( "Version" ) . IgnoreCase ) ;
56
102
}
57
103
58
104
[ Test ]
59
- public async Task ShouldNotVerifyModifiedTableAsync ( )
105
+ public void ShouldNotVerifyMultiModifiedTableAsync ( )
60
106
{
61
- const string resource1 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml" ;
62
- var cfgV1 = BuildConfiguration ( resource1 ) ;
107
+ var cfg = BuildConfiguration ( _version3Resource ) ;
63
108
64
- const string resource2 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.2_Version.hbm.xml" ;
65
- var cfgV2 = BuildConfiguration ( resource2 ) ;
66
-
67
- await ( new SchemaExport ( cfgV1 ) . ExecuteAsync ( true , true , false ) ) ;
109
+ var validator = new Tool . hbm2ddl . SchemaValidator ( cfg ) ;
68
110
69
- var validatorV2 = new Tool . hbm2ddl . SchemaValidator ( cfgV2 ) ;
70
- try
71
- {
72
- await ( validatorV2 . ValidateAsync ( ) ) ;
73
- }
74
- catch ( HibernateException e )
75
- {
76
- Assert . That ( e . Message , Does . StartWith ( "Missing column: Name" ) ) ;
77
- }
111
+ var error = Assert . ThrowsAsync < SchemaValidationException > ( ( ) => validator . ValidateAsync ( ) ) ;
112
+ Assert . That ( error ,
113
+ Has . Message . EqualTo ( "Schema validation failed: see list of validation errors" )
114
+ . And . Property ( "ValidationErrors" ) . Some . Contains ( "Missing column: Name in " ) . IgnoreCase . And . Contains ( "Version" ) . IgnoreCase ) ;
115
+ Assert . That ( error ,
116
+ Has . Property ( "ValidationErrors" ) . Some . Contains ( "Missing column: Title in " ) . IgnoreCase . And . Contains ( "Version" ) . IgnoreCase ) ;
117
+ Assert . That ( error ,
118
+ Has . Property ( "ValidationErrors" ) . Some . Contains ( "Missing sequence or table: " ) . IgnoreCase . And . Contains ( "id_table" ) . IgnoreCase ) ;
78
119
}
79
120
80
121
private static Configuration BuildConfiguration ( string resource )
0 commit comments