Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 1446fec

Browse files
committed
Refactor VistaDB tests so they don't leave undisposed connections locking the db
1 parent d96920c commit 1446fec

13 files changed

+751
-500
lines changed
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<connectionStrings>
4-
<add name="myVDBConnection"
5-
connectionString="Data Source='|DataDirectory|\Database.vdb5'"
6-
providerName="System.Data.VistaDB5" />
7-
</connectionStrings>
8-
<system.data>
9-
<DbProviderFactories>
10-
<remove invariant="System.Data.VistaDB5" />
11-
<add invariant="System.Data.VistaDB5" name="VistaDB 5 Data Provider"
12-
description="VistaDB 5 ADO.NET Provider for .Net"
13-
type="VistaDB.Provider.VistaDBProviderFactory, VistaDB.5.NET40, Version=5.0.0.0, Culture=neutral, PublicKeyToken=dfc935afe2125461" />
14-
</DbProviderFactories>
15-
</system.data>
3+
<appSettings>
4+
<add key="servicestack:license" value="1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBCdXNpbmVzcyxUeXBlOkJ1c2luZXNzLEhhc2g6UHVNTVRPclhvT2ZIbjQ5MG5LZE1mUTd5RUMzQnBucTFEbTE3TDczVEF4QUNMT1FhNXJMOWkzVjFGL2ZkVTE3Q2pDNENqTkQyUktRWmhvUVBhYTBiekJGUUZ3ZE5aZHFDYm9hL3lydGlwUHI5K1JsaTBYbzNsUC85cjVJNHE5QVhldDN6QkE4aTlvdldrdTgyTk1relY2eis2dFFqTThYN2lmc0JveHgycFdjPSxFeHBpcnk6MjAxMy0wMS0wMX0="/>
5+
</appSettings>
6+
<connectionStrings>
7+
<add name="myVDBConnection"
8+
connectionString="Data Source='|DataDirectory|\Database.vdb5'"
9+
providerName="System.Data.VistaDB5" />
10+
</connectionStrings>
11+
<system.data>
12+
<DbProviderFactories>
13+
<remove invariant="System.Data.VistaDB5" />
14+
<add invariant="System.Data.VistaDB5" name="VistaDB 5 Data Provider"
15+
description="VistaDB 5 ADO.NET Provider for .Net"
16+
type="VistaDB.Provider.VistaDBProviderFactory, VistaDB.5.NET40" />
17+
</DbProviderFactories>
18+
</system.data>
1619
</configuration>

src/ServiceStack.OrmLite.VistaDB.Tests/EnumTests.cs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.Data;
2+
using System.Linq;
23
using NUnit.Framework;
34

45
namespace ServiceStack.OrmLite.VistaDB.Tests
@@ -8,28 +9,31 @@ public class EnumTests : OrmLiteTestBase
89
[Test]
910
public void CanCreateTable()
1011
{
11-
OpenDbConnection().CreateTable<TypeWithEnum>(true);
12+
using (var db = OpenDbConnection())
13+
{
14+
db.CreateTable<TypeWithEnum>(true);
15+
}
1216
}
1317

1418
[Test]
1519
public void CanStoreEnumValue()
1620
{
17-
using(var con = OpenDbConnection())
21+
using(var db = OpenDbConnection())
1822
{
19-
con.CreateTable<TypeWithEnum>(true);
20-
con.Save(new TypeWithEnum {Id = 1, EnumValue = SomeEnum.Value1});
23+
db.CreateTable<TypeWithEnum>(true);
24+
db.Save(new TypeWithEnum {Id = 1, EnumValue = SomeEnum.Value1});
2125
}
2226
}
2327

2428
[Test]
2529
public void CanGetEnumValue()
2630
{
27-
using (var con = OpenDbConnection())
31+
using (var db = OpenDbConnection())
2832
{
29-
con.CreateTable<TypeWithEnum>(true);
33+
db.CreateTable<TypeWithEnum>(true);
3034
var obj = new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 };
31-
con.Save(obj);
32-
var target = con.SingleById<TypeWithEnum>(obj.Id);
35+
db.Save(obj);
36+
var target = db.SingleById<TypeWithEnum>(obj.Id);
3337
Assert.AreEqual(obj.Id, target.Id);
3438
Assert.AreEqual(obj.EnumValue, target.EnumValue);
3539
}
@@ -38,14 +42,14 @@ public void CanGetEnumValue()
3842
[Test]
3943
public void CanQueryByEnumValue_using_select_with_expression()
4044
{
41-
using (var con = OpenDbConnection())
45+
using (var db = OpenDbConnection())
4246
{
43-
con.CreateTable<TypeWithEnum>(true);
44-
con.Save(new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 });
45-
con.Save(new TypeWithEnum { Id = 2, EnumValue = SomeEnum.Value1 });
46-
con.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
47+
db.CreateTable<TypeWithEnum>(true);
48+
db.Save(new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 });
49+
db.Save(new TypeWithEnum { Id = 2, EnumValue = SomeEnum.Value1 });
50+
db.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
4751

48-
var target = con.Select<TypeWithEnum>(q => q.EnumValue == SomeEnum.Value1);
52+
var target = db.Select<TypeWithEnum>(q => q.EnumValue == SomeEnum.Value1);
4953

5054
Assert.AreEqual(2, target.Count());
5155
}
@@ -54,14 +58,14 @@ public void CanQueryByEnumValue_using_select_with_expression()
5458
[Test]
5559
public void CanQueryByEnumValue_using_select_with_string()
5660
{
57-
using (var con = OpenDbConnection())
61+
using (var db = OpenDbConnection())
5862
{
59-
con.CreateTable<TypeWithEnum>(true);
60-
con.Save(new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 });
61-
con.Save(new TypeWithEnum { Id = 2, EnumValue = SomeEnum.Value1 });
62-
con.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
63+
db.CreateTable<TypeWithEnum>(true);
64+
db.Save(new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 });
65+
db.Save(new TypeWithEnum { Id = 2, EnumValue = SomeEnum.Value1 });
66+
db.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
6367

64-
var target = con.SelectFmt<TypeWithEnum>("EnumValue = {0}", SomeEnum.Value1);
68+
var target = db.SelectFmt<TypeWithEnum>("EnumValue = {0}", SomeEnum.Value1);
6569

6670
Assert.AreEqual(2, target.Count());
6771
}
@@ -70,14 +74,14 @@ public void CanQueryByEnumValue_using_select_with_string()
7074
[Test]
7175
public void CanQueryByEnumValue_using_where_with_AnonType()
7276
{
73-
using (var con = OpenDbConnection())
77+
using (var db = OpenDbConnection())
7478
{
75-
con.CreateTable<TypeWithEnum>(true);
76-
con.Save(new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 });
77-
con.Save(new TypeWithEnum { Id = 2, EnumValue = SomeEnum.Value1 });
78-
con.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
79+
db.CreateTable<TypeWithEnum>(true);
80+
db.Save(new TypeWithEnum { Id = 1, EnumValue = SomeEnum.Value1 });
81+
db.Save(new TypeWithEnum { Id = 2, EnumValue = SomeEnum.Value1 });
82+
db.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
7983

80-
var target = con.Where<TypeWithEnum>(new { EnumValue = SomeEnum.Value1 });
84+
var target = db.Where<TypeWithEnum>(new { EnumValue = SomeEnum.Value1 });
8185

8286
Assert.AreEqual(2, target.Count());
8387
}
Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using System.Data;
2+
using NUnit.Framework;
23

34
namespace ServiceStack.OrmLite.VistaDB.Tests.Expressions
45
{
@@ -7,7 +8,7 @@ public class AdditiveExpressionsTest : ExpressionsTestBase
78
[Test]
89
public void Can_select_constant_add_expression()
910
{
10-
var expected = new TestType()
11+
var expected = new TestType
1112
{
1213
IntColumn = 7,
1314
BoolColumn = true,
@@ -16,17 +17,20 @@ public void Can_select_constant_add_expression()
1617

1718
EstablishContext(10, expected);
1819

19-
var actual = OpenDbConnection().Select<TestType>(q => q.IntColumn == 4 + 3);
20+
using (var db = OpenDbConnection())
21+
{
22+
var actual = db.Select<TestType>(q => q.IntColumn == 4 + 3);
2023

21-
Assert.IsNotNull(actual);
22-
Assert.AreEqual(1, actual.Count);
23-
CollectionAssert.Contains(actual, expected);
24+
Assert.IsNotNull(actual);
25+
Assert.AreEqual(1, actual.Count);
26+
CollectionAssert.Contains(actual, expected);
27+
}
2428
}
2529

2630
[Test]
2731
public void Can_select_constant_subtract_expression()
2832
{
29-
var expected = new TestType()
33+
var expected = new TestType
3034
{
3135
IntColumn = 7,
3236
BoolColumn = true,
@@ -35,22 +39,25 @@ public void Can_select_constant_subtract_expression()
3539

3640
EstablishContext(10, expected);
3741

38-
var actual = OpenDbConnection().Select<TestType>(q => q.IntColumn == 10 - 3);
42+
using (var db = OpenDbConnection())
43+
{
44+
var actual = db.Select<TestType>(q => q.IntColumn == 10 - 3);
3945

40-
Assert.IsNotNull(actual);
41-
Assert.AreEqual(1, actual.Count);
42-
CollectionAssert.Contains(actual, expected);
46+
Assert.IsNotNull(actual);
47+
Assert.AreEqual(1, actual.Count);
48+
CollectionAssert.Contains(actual, expected);
49+
}
4350
}
4451

4552
[Test]
4653
public void Can_select_variable_add_expression()
4754
{
48-
// ReSharper disable ConvertToConstant.Local
55+
// ReSharper disable ConvertToConstant.Local
4956
var a = 4;
5057
var b = 3;
51-
// ReSharper restore ConvertToConstant.Local
58+
// ReSharper restore ConvertToConstant.Local
5259

53-
var expected = new TestType()
60+
var expected = new TestType
5461
{
5562
IntColumn = 7,
5663
BoolColumn = true,
@@ -59,11 +66,14 @@ public void Can_select_variable_add_expression()
5966

6067
EstablishContext(10, expected);
6168

62-
var actual = OpenDbConnection().Select<TestType>(q => q.IntColumn == a + b);
69+
using (var db = OpenDbConnection())
70+
{
71+
var actual = db.Select<TestType>(q => q.IntColumn == a + b);
6372

64-
Assert.IsNotNull(actual);
65-
Assert.AreEqual(1, actual.Count);
66-
CollectionAssert.Contains(actual, expected);
73+
Assert.IsNotNull(actual);
74+
Assert.AreEqual(1, actual.Count);
75+
CollectionAssert.Contains(actual, expected);
76+
}
6777
}
6878

6979
[Test]
@@ -74,7 +84,7 @@ public void Can_select_variable_subtract_expression()
7484
var b = 3;
7585
// ReSharper restore ConvertToConstant.Local
7686

77-
var expected = new TestType()
87+
var expected = new TestType
7888
{
7989
IntColumn = 7,
8090
BoolColumn = true,
@@ -83,17 +93,20 @@ public void Can_select_variable_subtract_expression()
8393

8494
EstablishContext(10, expected);
8595

86-
var actual = OpenDbConnection().Select<TestType>(q => q.IntColumn == a - b);
96+
using (var db = OpenDbConnection())
97+
{
98+
var actual = db.Select<TestType>(q => q.IntColumn == a - b);
8799

88-
Assert.IsNotNull(actual);
89-
Assert.AreEqual(1, actual.Count);
90-
CollectionAssert.Contains(actual, expected);
100+
Assert.IsNotNull(actual);
101+
Assert.AreEqual(1, actual.Count);
102+
CollectionAssert.Contains(actual, expected);
103+
}
91104
}
92105

93106
[Test]
94107
public void Can_select_method_add_expression()
95108
{
96-
var expected = new TestType()
109+
var expected = new TestType
97110
{
98111
IntColumn = 7,
99112
BoolColumn = true,
@@ -102,17 +115,20 @@ public void Can_select_method_add_expression()
102115

103116
EstablishContext(10, expected);
104117

105-
var actual = OpenDbConnection().Select<TestType>(q => q.IntColumn == GetValue(4) + GetValue(3));
118+
using (var db = OpenDbConnection())
119+
{
120+
var actual = db.Select<TestType>(q => q.IntColumn == GetValue(4) + GetValue(3));
106121

107-
Assert.IsNotNull(actual);
108-
Assert.AreEqual(1, actual.Count);
109-
CollectionAssert.Contains(actual, expected);
122+
Assert.IsNotNull(actual);
123+
Assert.AreEqual(1, actual.Count);
124+
CollectionAssert.Contains(actual, expected);
125+
}
110126
}
111127

112128
[Test]
113129
public void Can_select_method_subtract_expression()
114130
{
115-
var expected = new TestType()
131+
var expected = new TestType
116132
{
117133
IntColumn = 7,
118134
BoolColumn = true,
@@ -121,11 +137,15 @@ public void Can_select_method_subtract_expression()
121137

122138
EstablishContext(10, expected);
123139

124-
var actual = OpenDbConnection().Select<TestType>(q => q.IntColumn == GetValue(10) - GetValue(3));
140+
using (var db = OpenDbConnection())
141+
{
142+
var actual = db.Select<TestType>(q => q.IntColumn == GetValue(10) - GetValue(3));
143+
144+
Assert.IsNotNull(actual);
145+
Assert.AreEqual(1, actual.Count);
146+
CollectionAssert.Contains(actual, expected);
125147

126-
Assert.IsNotNull(actual);
127-
Assert.AreEqual(1, actual.Count);
128-
CollectionAssert.Contains(actual, expected);
148+
}
129149
}
130150
}
131151
}

0 commit comments

Comments
 (0)