forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseOpenerMethods.cs
More file actions
76 lines (65 loc) · 2.91 KB
/
DatabaseOpenerMethods.cs
File metadata and controls
76 lines (65 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
namespace Simple.Data
{
using System;
internal class DatabaseOpenerMethods
{
private Func<Database> _openDefault;
private Func<string, Database> _openFile;
private Func<string, Database> _openConnection;
private Func<string, string, Database> _openConnectionWithProvider;
private Func<string, Database> _openNamedConnection;
private Func<string, object, Database> _open;
public Func<Database> OpenDefaultImpl
{
get { return _openDefault ?? DatabaseOpener.OpenDefaultMethod; }
}
public Func<string, Database> OpenFileImpl
{
get { return _openFile ?? DatabaseOpener.OpenFileMethod; }
}
public Func<string, Database> OpenConnectionImpl
{
get { return _openConnection ?? DatabaseOpener.OpenConnectionMethod; }
}
public Func<string, string, Database> OpenConnectionWithProviderImpl
{
get { return _openConnectionWithProvider ?? DatabaseOpener.OpenConnectionMethod; }
}
public Func<string, Database> OpenNamedConnectionImpl
{
get { return _openNamedConnection ?? DatabaseOpener.OpenNamedConnectionMethod; }
}
public Func<string, object, Database> OpenImpl
{
get { return _open ?? DatabaseOpener.OpenMethod; }
}
public void UseMockDatabase(Database database)
{
_openDefault = () => database;
_openFile = _openConnection = _openNamedConnection = ignore => database;
_open = (ignore1, ignore2) => database;
_openConnectionWithProvider = (ignore1, ignore2) => database;
}
public void UseMockAdapter(Adapter adapter)
{
_openDefault = () => new Database(adapter);
_openFile = _openConnection = _openNamedConnection = ignore => new Database(adapter);
_open = (ignore1, ignore2) => new Database(adapter);
_openConnectionWithProvider = (ignore1, ignore2) => new Database(adapter);
}
public void UseMockDatabase(Func<Database> databaseCreator)
{
_openDefault = databaseCreator;
_openFile = _openConnection = _openNamedConnection = ignore => databaseCreator();
_open = (ignore1, ignore2) => databaseCreator();
_openConnectionWithProvider = (ignore1, ignore2) => databaseCreator();
}
public void UseMockAdapter(Func<Adapter> adapterCreator)
{
_openDefault = () => new Database(adapterCreator());
_openFile = _openConnection = _openNamedConnection = ignore => new Database(adapterCreator());
_open = (ignore1, ignore2) => new Database(adapterCreator());
_openConnectionWithProvider = (ignore1, ignore2) => new Database(adapterCreator());
}
}
}