16
16
namespace NHibernate . Test . NHSpecificTest . GH1180
17
17
{
18
18
using System . Threading . Tasks ;
19
+ [ KnownBug ( "NH-3847 (GH-1180)" ) ]
19
20
[ TestFixture ]
20
21
public class ByCodeFixtureAsync : TestCaseMappingByCode
21
22
{
@@ -33,55 +34,63 @@ protected override HbmMapping GetMappings()
33
34
return mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
34
35
}
35
36
37
+ protected override void OnTearDown ( )
38
+ {
39
+ using ( var session = OpenSession ( ) )
40
+ using ( var transaction = session . BeginTransaction ( ) )
41
+ {
42
+ session . CreateQuery ( "delete from System.Object" ) . ExecuteUpdate ( ) ;
43
+ transaction . Commit ( ) ;
44
+ }
45
+ }
46
+
36
47
[ Test ]
37
48
public async Task StringTypesAsync ( )
38
49
{
39
50
using ( var session = OpenSession ( ) )
40
51
using ( var transaction = session . BeginTransaction ( ) )
41
52
{
42
53
// data
43
- {
44
- await ( session . SaveAsync ( new Entity { Name = "Alpha" } ) ) ;
45
- await ( session . SaveAsync ( new Entity { Name = "Beta" } ) ) ;
46
- await ( session . SaveAsync ( new Entity { Name = "Gamma" } ) ) ;
47
- }
54
+ await ( session . SaveAsync ( new Entity { Name = "Alpha" } ) ) ;
55
+ await ( session . SaveAsync ( new Entity { Name = "Beta" } ) ) ;
56
+ await ( session . SaveAsync ( new Entity { Name = "Gamma" } ) ) ;
48
57
49
- await ( session . FlushAsync ( ) ) ;
50
-
51
- // whenTrue is constant, whenFalse is property -> works even before the fix
52
- {
53
- ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
54
-
55
- var conditionalProjection = Projections . Conditional (
56
- Restrictions . Not (
57
- Restrictions . Like ( nameof ( Entity . Name ) , "B%" ) ) ,
58
- Projections . Constant ( "other" ) ,
59
- Projections . Property ( nameof ( Entity . Name ) ) ) ;
60
- tagCriteria . SetProjection ( conditionalProjection ) ;
58
+ await ( transaction . CommitAsync ( ) ) ;
59
+ }
61
60
62
- // run query
61
+ // whenTrue is constant, whenFalse is property -> works even before the fix
62
+ using ( var session = OpenSession ( ) )
63
+ {
64
+ ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
63
65
64
- var results = await ( tagCriteria . ListAsync ( ) ) ;
66
+ var conditionalProjection = Projections . Conditional (
67
+ Restrictions . Not (
68
+ Restrictions . Like ( nameof ( Entity . Name ) , "B%" ) ) ,
69
+ Projections . Constant ( "other" ) ,
70
+ Projections . Property ( nameof ( Entity . Name ) ) ) ;
71
+ tagCriteria . SetProjection ( conditionalProjection ) ;
65
72
66
- Assert . That ( results , Is . EquivalentTo ( new [ ] { "other" , "Beta" , "other" } ) ) ;
67
- }
73
+ // run query
74
+ var results = await ( tagCriteria . ListAsync ( ) ) ;
68
75
69
- // whenTrue is property, whenFalse is constant -> fails before the fix
70
- {
71
- ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
76
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { "other" , "Beta" , "other" } ) ) ;
77
+ }
72
78
73
- var conditionalProjection = Projections . Conditional (
74
- Restrictions . Like ( nameof ( Entity . Name ) , "B%" ) ,
75
- Projections . Property ( nameof ( Entity . Name ) ) ,
76
- Projections . Constant ( "other" ) ) ;
77
- tagCriteria . SetProjection ( conditionalProjection ) ;
79
+ // whenTrue is property, whenFalse is constant -> fails before the fix
80
+ using ( var session = OpenSession ( ) )
81
+ {
82
+ ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
78
83
79
- // run query
84
+ var conditionalProjection = Projections . Conditional (
85
+ Restrictions . Like ( nameof ( Entity . Name ) , "B%" ) ,
86
+ Projections . Property ( nameof ( Entity . Name ) ) ,
87
+ Projections . Constant ( "other" ) ) ;
88
+ tagCriteria . SetProjection ( conditionalProjection ) ;
80
89
81
- var results = await ( tagCriteria . ListAsync ( ) ) ;
90
+ // run query
91
+ var results = await ( tagCriteria . ListAsync ( ) ) ;
82
92
83
- Assert . That ( results , Is . EquivalentTo ( new [ ] { "other" , "Beta" , "other" } ) ) ;
84
- }
93
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { "other" , "Beta" , "other" } ) ) ;
85
94
}
86
95
}
87
96
@@ -91,50 +100,48 @@ public async Task DecimalTypesAsync()
91
100
using ( var session = OpenSession ( ) )
92
101
using ( var transaction = session . BeginTransaction ( ) )
93
102
{
94
- // data
95
- {
96
- await ( session . SaveAsync ( new Entity { Amount = 3.14m } ) ) ;
97
- await ( session . SaveAsync ( new Entity { Amount = 42.13m } ) ) ;
98
- await ( session . SaveAsync ( new Entity { Amount = 17.99m } ) ) ;
99
- }
103
+ await ( session . SaveAsync ( new Entity { Amount = 3.14m } ) ) ;
104
+ await ( session . SaveAsync ( new Entity { Amount = 42.13m } ) ) ;
105
+ await ( session . SaveAsync ( new Entity { Amount = 17.99m } ) ) ;
100
106
101
- await ( session . FlushAsync ( ) ) ;
102
-
103
- // whenTrue is constant, whenFalse is property -> works even before the fix
104
- {
105
- ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
106
-
107
- var conditionalProjection = Projections . Conditional (
108
- Restrictions . Not (
109
- Restrictions . Ge ( nameof ( Entity . Amount ) , 20m ) ) ,
110
- Projections . Constant ( 20m ) ,
111
- Projections . Property ( nameof ( Entity . Amount ) ) ) ;
112
- tagCriteria . SetProjection ( conditionalProjection ) ;
107
+ await ( transaction . CommitAsync ( ) ) ;
108
+ }
113
109
114
- // run query
110
+ // whenTrue is constant, whenFalse is property -> works even before the fix
111
+ using ( var session = OpenSession ( ) )
112
+ {
113
+ ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
115
114
116
- var results = await ( tagCriteria . ListAsync ( ) ) ;
115
+ var conditionalProjection = Projections . Conditional (
116
+ Restrictions . Not (
117
+ Restrictions . Ge ( nameof ( Entity . Amount ) , 20m ) ) ,
118
+ Projections . Constant ( 20m ) ,
119
+ Projections . Property ( nameof ( Entity . Amount ) ) ) ;
120
+ tagCriteria . SetProjection ( conditionalProjection ) ;
117
121
118
- Assert . That ( results , Is . EquivalentTo ( new [ ] { 20m , 42.13m , 20m } ) ) ;
119
- }
122
+ // run query
123
+ var results = await ( tagCriteria . ListAsync ( ) ) ;
120
124
121
- // whenTrue is property, whenFalse is constant -> fails before the fix
122
- {
123
- ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
125
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { 20m , 42.13m , 20m } ) ) ;
126
+ }
124
127
125
- var conditionalProjection = Projections . Conditional (
126
- Restrictions . Ge ( nameof ( Entity . Amount ) , 20m ) ,
127
- Projections . Property ( nameof ( Entity . Amount ) ) ,
128
- Projections . Constant ( 20m ) ) ;
129
- tagCriteria . SetProjection ( conditionalProjection ) ;
128
+ // whenTrue is property, whenFalse is constant -> fails before the fix
129
+ using ( var session = OpenSession ( ) )
130
+ {
131
+ ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
130
132
131
- // run query
133
+ var conditionalProjection = Projections . Conditional (
134
+ Restrictions . Ge ( nameof ( Entity . Amount ) , 20m ) ,
135
+ Projections . Property ( nameof ( Entity . Amount ) ) ,
136
+ Projections . Constant ( 20m ) ) ;
137
+ tagCriteria . SetProjection ( conditionalProjection ) ;
132
138
133
- var results = await ( tagCriteria . ListAsync ( ) ) ;
139
+ // run query
140
+ var results = await ( tagCriteria . ListAsync ( ) ) ;
134
141
135
- Assert . That ( results , Is . EquivalentTo ( new [ ] { 20m , 42.13m , 20m } ) ) ;
136
- }
142
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { 20m , 42.13m , 20m } ) ) ;
137
143
}
138
144
}
139
145
}
140
146
}
147
+
0 commit comments