Skip to content

Commit 0874641

Browse files
committed
Tweaked tests to work in NCrunch by forcing load of assembly under test.
1 parent c943af1 commit 0874641

File tree

7 files changed

+54
-5
lines changed

7 files changed

+54
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Simple.Data.sln.DotSettings.user
2424
Simple.Data/Simple.Data.idc
2525
.DS_Store
2626
mono-release-*
27+
*ncrunch*

Simple.Data.SqlCe40Test/ConnectionProviderTest.cs

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

66
namespace Simple.Data.SqlCe40Test
77
{
8+
using System.Diagnostics;
89
using Ado;
910
using NUnit.Framework;
1011
using SqlCe40;
@@ -27,4 +28,15 @@ public void SqlCeDoesNotSupportCompoundStatements()
2728
Assert.IsFalse(target.SupportsCompoundStatements);
2829
}
2930
}
31+
32+
[SetUpFixture]
33+
public class Setup
34+
{
35+
[SetUp]
36+
public void ForceLoadOfSimpleDataSqlCe40()
37+
{
38+
var provider = new SqlCe40.SqlCe40ConnectionProvider();
39+
Trace.Write("Loaded provider.");
40+
}
41+
}
3042
}

Simple.Data.SqlTest/BulkInsertTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Simple.Data.SqlTest
22
{
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using NUnit.Framework;
56

67
[TestFixture]

Simple.Data.SqlTest/DatabaseHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static dynamic Open()
2424

2525
public static void Reset()
2626
{
27+
var provider = new SqlServer.SqlConnectionProvider();
2728
using (var cn = new SqlConnection(ConnectionString))
2829
{
2930
cn.Open();

Simple.Data.SqlTest/SetupFixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88

99
namespace Simple.Data.SqlTest
1010
{
11+
using System.Diagnostics;
12+
1113
[SetUpFixture]
1214
public class SetupFixture
1315
{
1416
[SetUp]
1517
public void CreateStoredProcedures()
1618
{
19+
var provider = new SqlServer.SqlConnectionProvider();
20+
Trace.Write("Loaded provider " + provider.GetType().Name);
21+
1722
using (var cn = new SqlConnection(Properties.Settings.Default.ConnectionString))
1823
{
1924
cn.Open();

Simple.Data.SqlTest/UpsertTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public void TestMultiUpsertWithStaticTypeObjectsAndNoReturn()
176176
new User { Name = "Wowbagger", Password = "teatime", Age = int.MaxValue }
177177
};
178178

179+
//IList<User> actuals = db.Users.Upsert(users).ToList<User>();
179180
db.Users.Upsert(users);
180181

181182
var slartibartfast = db.Users.FindByName("Slartibartfast");

Simple.Data/MefHelper.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ namespace Simple.Data
1212

1313
class MefHelper : Composer
1414
{
15+
private static readonly Assembly ThisAssembly = typeof (MefHelper).Assembly;
16+
1517
public override T Compose<T>()
1618
{
17-
using (var container = CreateContainer())
19+
using (var container = CreateAppDomainContainer())
20+
{
21+
var exports = container.GetExports<T>().ToList();
22+
if (exports.Count == 1)
23+
{
24+
return exports.Single().Value;
25+
}
26+
}
27+
using (var container = CreateFolderContainer())
1828
{
1929
var exports = container.GetExports<T>().ToList();
2030
if (exports.Count == 0) throw new SimpleDataException("No ADO Provider found.");
@@ -27,7 +37,15 @@ public override T Compose<T>(string contractName)
2737
{
2838
try
2939
{
30-
using (var container = CreateContainer())
40+
using (var container = CreateAppDomainContainer())
41+
{
42+
var exports = container.GetExports<T>(contractName).ToList();
43+
if (exports.Count == 1)
44+
{
45+
return exports.Single().Value;
46+
}
47+
}
48+
using (var container = CreateFolderContainer())
3149
{
3250
var exports = container.GetExports<T>(contractName).ToList();
3351
if (exports.Count == 0) throw new SimpleDataException("No ADO Provider found.");
@@ -55,7 +73,7 @@ public static T GetAdjacentComponent<T>(Type knownSiblingType)
5573

5674
static string GetThisAssemblyPath()
5775
{
58-
var path = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("file://", "//");
76+
var path = ThisAssembly.CodeBase.Replace("file:///", "").Replace("file://", "//");
5977
path = Path.GetDirectoryName(path);
6078
if (path == null) throw new ArgumentException("Unrecognised file.");
6179
if (!Path.IsPathRooted(path))
@@ -65,11 +83,11 @@ static string GetThisAssemblyPath()
6583
return path;
6684
}
6785

68-
private static CompositionContainer CreateContainer()
86+
private static CompositionContainer CreateFolderContainer()
6987
{
7088
var path = GetThisAssemblyPath ();
7189

72-
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
90+
var assemblyCatalog = new AssemblyCatalog(ThisAssembly);
7391
var aggregateCatalog = new AggregateCatalog(assemblyCatalog);
7492
foreach (string file in System.IO.Directory.GetFiles(path, "Simple.Data.*.dll"))
7593
{
@@ -78,5 +96,15 @@ private static CompositionContainer CreateContainer()
7896
}
7997
return new CompositionContainer(aggregateCatalog);
8098
}
99+
100+
private static CompositionContainer CreateAppDomainContainer()
101+
{
102+
var aggregateCatalog = new AggregateCatalog();
103+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.GlobalAssemblyCache))
104+
{
105+
aggregateCatalog.Catalogs.Add(new AssemblyCatalog(assembly));
106+
}
107+
return new CompositionContainer(aggregateCatalog);
108+
}
81109
}
82110
}

0 commit comments

Comments
 (0)