forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderHelperTest.cs
More file actions
118 lines (102 loc) · 3.9 KB
/
ProviderHelperTest.cs
File metadata and controls
118 lines (102 loc) · 3.9 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Data;
using Simple.Data.Ado.Schema;
using System.ComponentModel.Composition;
namespace Simple.Data.Ado.Test
{
[TestFixture]
public class ProviderHelperTest
{
[Test]
public void ShouldNotRequestExportableTypeFromServiceProvider()
{
var helper = new ProviderHelper();
var connectionProvider = new StubConnectionAndServiceProvider();
var actual = helper.GetCustomProvider<ITestInterface>(connectionProvider);
Assert.IsNull(connectionProvider.RequestedServiceType);
}
[Test]
public void ShouldRequestNonExportedTypeFromServiceProvider()
{
var helper = new ProviderHelper();
var connectionProvider = new StubConnectionAndServiceProvider();
var actual = helper.GetCustomProvider<IQueryPager>(connectionProvider);
Assert.AreEqual(typeof(IQueryPager), connectionProvider.RequestedServiceType);
}
[Test]
public void ShouldReturnNonExportedTypeFromServiceProvider()
{
var helper = new ProviderHelper();
var connectionProvider = new StubConnectionAndServiceProvider();
var actual = helper.GetCustomProvider<IQueryPager>(connectionProvider);
Assert.IsInstanceOf(typeof(IQueryPager), actual);
}
[Test]
public void ShouldFindProviderUsingAssemblyAttribute()
{
IConnectionProvider provider;
Assert.True(ProviderHelper.TryLoadAssemblyUsingAttribute("Test", null, out provider));
Assert.IsNotNull(provider);
Assert.IsInstanceOf<StubConnectionProvider>(provider);
}
public class StubConnectionAndServiceProvider : IConnectionProvider, IServiceProvider
{
public void SetConnectionString(string connectionString)
{
throw new NotImplementedException();
}
public IDbConnection CreateConnection()
{
throw new NotImplementedException();
}
public ISchemaProvider GetSchemaProvider()
{
throw new NotImplementedException();
}
public string ConnectionString
{
get { throw new NotImplementedException(); }
}
public bool SupportsCompoundStatements
{
get { throw new NotImplementedException(); }
}
public string GetIdentityFunction()
{
throw new NotImplementedException();
}
public bool SupportsStoredProcedures
{
get { throw new NotImplementedException(); }
}
public IProcedureExecutor GetProcedureExecutor(AdoAdapter adapter, ObjectName procedureName)
{
throw new NotImplementedException();
}
public Type RequestedServiceType { get; private set; }
public Object GetService(Type serviceType)
{
this.RequestedServiceType = serviceType;
return new StubQueryPager();
}
}
public class StubQueryPager : IQueryPager
{
public IEnumerable<string> ApplyLimit(string sql, int take)
{
throw new NotImplementedException();
}
public IEnumerable<string> ApplyPaging(string sql, string[] keys, int skip, int take)
{
throw new NotImplementedException();
}
}
public interface ITestInterface { }
[Export(typeof(ITestInterface))]
public class TestClass : ITestInterface { }
}
}