Skip to content

Commit c03b144

Browse files
committed
Tests Clean up
1 parent 3440be0 commit c03b144

File tree

2 files changed

+146
-134
lines changed

2 files changed

+146
-134
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH1180/FixtureByCode.cs

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace NHibernate.Test.NHSpecificTest.GH1180
1717
{
1818
using System.Threading.Tasks;
19+
[KnownBug("NH-3847 (GH-1180)")]
1920
[TestFixture]
2021
public class ByCodeFixtureAsync : TestCaseMappingByCode
2122
{
@@ -33,55 +34,63 @@ protected override HbmMapping GetMappings()
3334
return mapper.CompileMappingForAllExplicitlyAddedEntities();
3435
}
3536

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+
3647
[Test]
3748
public async Task StringTypesAsync()
3849
{
3950
using (var session = OpenSession())
4051
using (var transaction = session.BeginTransaction())
4152
{
4253
// 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-
}
48-
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+
await (session.SaveAsync(new Entity {Name = "Alpha"}));
55+
await (session.SaveAsync(new Entity {Name = "Beta"}));
56+
await (session.SaveAsync(new Entity {Name = "Gamma"}));
5457

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+
}
6160

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));
6365

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);
6572

66-
Assert.That(results, Is.EquivalentTo(new[] { "other", "Beta", "other" }));
67-
}
73+
// run query
74+
var results = await (tagCriteria.ListAsync());
6875

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+
}
7278

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));
7883

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);
8089

81-
var results = await (tagCriteria.ListAsync());
90+
// run query
91+
var results = await (tagCriteria.ListAsync());
8292

83-
Assert.That(results, Is.EquivalentTo(new[] { "other", "Beta", "other" }));
84-
}
93+
Assert.That(results, Is.EquivalentTo(new[] {"other", "Beta", "other"}));
8594
}
8695
}
8796

@@ -91,49 +100,46 @@ public async Task DecimalTypesAsync()
91100
using (var session = OpenSession())
92101
using (var transaction = session.BeginTransaction())
93102
{
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-
}
100-
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));
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}));
106106

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+
}
113109

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));
115114

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);
117121

118-
Assert.That(results, Is.EquivalentTo(new[] { 20m, 42.13m, 20m }));
119-
}
122+
// run query
123+
var results = await (tagCriteria.ListAsync());
120124

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+
}
124127

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));
130132

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);
132138

133-
var results = await (tagCriteria.ListAsync());
139+
// run query
140+
var results = await (tagCriteria.ListAsync());
134141

135-
Assert.That(results, Is.EquivalentTo(new[] { 20m, 42.13m, 20m }));
136-
}
142+
Assert.That(results, Is.EquivalentTo(new[] {20m, 42.13m, 20m}));
137143
}
138144
}
139145
}

src/NHibernate.Test/NHSpecificTest/GH1180/FixtureByCode.cs

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace NHibernate.Test.NHSpecificTest.GH1180
77
{
8+
[KnownBug("NH-3847 (GH-1180)")]
89
[TestFixture]
910
public class ByCodeFixture : TestCaseMappingByCode
1011
{
@@ -22,55 +23,63 @@ protected override HbmMapping GetMappings()
2223
return mapper.CompileMappingForAllExplicitlyAddedEntities();
2324
}
2425

26+
protected override void OnTearDown()
27+
{
28+
using (var session = OpenSession())
29+
using (var transaction = session.BeginTransaction())
30+
{
31+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
32+
transaction.Commit();
33+
}
34+
}
35+
2536
[Test]
2637
public void StringTypes()
2738
{
2839
using (var session = OpenSession())
2940
using (var transaction = session.BeginTransaction())
3041
{
3142
// data
32-
{
33-
session.Save(new Entity { Name = "Alpha" });
34-
session.Save(new Entity { Name = "Beta" });
35-
session.Save(new Entity { Name = "Gamma" });
36-
}
37-
38-
session.Flush();
39-
40-
// whenTrue is constant, whenFalse is property -> works even before the fix
41-
{
42-
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
43+
session.Save(new Entity {Name = "Alpha"});
44+
session.Save(new Entity {Name = "Beta"});
45+
session.Save(new Entity {Name = "Gamma"});
4346

44-
var conditionalProjection = Projections.Conditional(
45-
Restrictions.Not(
46-
Restrictions.Like(nameof(Entity.Name), "B%")),
47-
Projections.Constant("other"),
48-
Projections.Property(nameof(Entity.Name)));
49-
tagCriteria.SetProjection(conditionalProjection);
47+
transaction.Commit();
48+
}
5049

51-
// run query
50+
// whenTrue is constant, whenFalse is property -> works even before the fix
51+
using (var session = OpenSession())
52+
{
53+
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
5254

53-
var results = tagCriteria.List();
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);
5461

55-
Assert.That(results, Is.EquivalentTo(new[] { "other", "Beta", "other" }));
56-
}
62+
// run query
63+
var results = tagCriteria.List();
5764

58-
// whenTrue is property, whenFalse is constant -> fails before the fix
59-
{
60-
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
65+
Assert.That(results, Is.EquivalentTo(new[] {"other", "Beta", "other"}));
66+
}
6167

62-
var conditionalProjection = Projections.Conditional(
63-
Restrictions.Like(nameof(Entity.Name), "B%"),
64-
Projections.Property(nameof(Entity.Name)),
65-
Projections.Constant("other"));
66-
tagCriteria.SetProjection(conditionalProjection);
68+
// whenTrue is property, whenFalse is constant -> fails before the fix
69+
using (var session = OpenSession())
70+
{
71+
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
6772

68-
// run query
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);
6978

70-
var results = tagCriteria.List();
79+
// run query
80+
var results = tagCriteria.List();
7181

72-
Assert.That(results, Is.EquivalentTo(new[] { "other", "Beta", "other" }));
73-
}
82+
Assert.That(results, Is.EquivalentTo(new[] {"other", "Beta", "other"}));
7483
}
7584
}
7685

@@ -80,49 +89,46 @@ public void DecimalTypes()
8089
using (var session = OpenSession())
8190
using (var transaction = session.BeginTransaction())
8291
{
83-
// data
84-
{
85-
session.Save(new Entity { Amount = 3.14m });
86-
session.Save(new Entity { Amount = 42.13m });
87-
session.Save(new Entity { Amount = 17.99m });
88-
}
89-
90-
session.Flush();
91-
92-
// whenTrue is constant, whenFalse is property -> works even before the fix
93-
{
94-
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
92+
session.Save(new Entity {Amount = 3.14m});
93+
session.Save(new Entity {Amount = 42.13m});
94+
session.Save(new Entity {Amount = 17.99m});
9595

96-
var conditionalProjection = Projections.Conditional(
97-
Restrictions.Not(
98-
Restrictions.Ge(nameof(Entity.Amount), 20m)),
99-
Projections.Constant(20m),
100-
Projections.Property(nameof(Entity.Amount)));
101-
tagCriteria.SetProjection(conditionalProjection);
96+
transaction.Commit();
97+
}
10298

103-
// run query
99+
// whenTrue is constant, whenFalse is property -> works even before the fix
100+
using (var session = OpenSession())
101+
{
102+
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
104103

105-
var results = tagCriteria.List();
104+
var conditionalProjection = Projections.Conditional(
105+
Restrictions.Not(
106+
Restrictions.Ge(nameof(Entity.Amount), 20m)),
107+
Projections.Constant(20m),
108+
Projections.Property(nameof(Entity.Amount)));
109+
tagCriteria.SetProjection(conditionalProjection);
106110

107-
Assert.That(results, Is.EquivalentTo(new[] { 20m, 42.13m, 20m }));
108-
}
111+
// run query
112+
var results = tagCriteria.List();
109113

110-
// whenTrue is property, whenFalse is constant -> fails before the fix
111-
{
112-
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
114+
Assert.That(results, Is.EquivalentTo(new[] {20m, 42.13m, 20m}));
115+
}
113116

114-
var conditionalProjection = Projections.Conditional(
115-
Restrictions.Ge(nameof(Entity.Amount), 20m),
116-
Projections.Property(nameof(Entity.Amount)),
117-
Projections.Constant(20m));
118-
tagCriteria.SetProjection(conditionalProjection);
117+
// whenTrue is property, whenFalse is constant -> fails before the fix
118+
using (var session = OpenSession())
119+
{
120+
ICriteria tagCriteria = session.CreateCriteria(typeof(Entity));
119121

120-
// run query
122+
var conditionalProjection = Projections.Conditional(
123+
Restrictions.Ge(nameof(Entity.Amount), 20m),
124+
Projections.Property(nameof(Entity.Amount)),
125+
Projections.Constant(20m));
126+
tagCriteria.SetProjection(conditionalProjection);
121127

122-
var results = tagCriteria.List();
128+
// run query
129+
var results = tagCriteria.List();
123130

124-
Assert.That(results, Is.EquivalentTo(new[] { 20m, 42.13m, 20m }));
125-
}
131+
Assert.That(results, Is.EquivalentTo(new[] {20m, 42.13m, 20m}));
126132
}
127133
}
128134
}

0 commit comments

Comments
 (0)