My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System.Reflection;
using NUnit.Framework;

namespace Konstruktor.Tests
{
[TestFixture]
public sealed class ScanAssembly
{
interface InterfaceBase
{}

interface Interface1 : InterfaceBase
{}

[DefaultImplementation]
sealed class MyDefault : Interface1
{
};

Builder b;

[SetUp]
public void setup()
{
b = new Builder();
b.scanAssembly(Assembly.GetExecutingAssembly());
}

[Test]
public void testIfInterface1IsRegistered()
{
using (var scope = b.beginScope())
{
scope.resolve<Interface1>();
}
}

[Test, ExpectedException(typeof(ResolveException))]
public void testIfOnlyInterface1IsRegistered()
{
using (var scope = b.beginScope())
{
scope.resolve<InterfaceBase>();
}
}

interface Interface2 : InterfaceBase
{ }

interface Interface3 : InterfaceBase
{ }

[DefaultImplementation(typeof(Interface3))]
sealed class MyDefault2 : Interface3, Interface2
{ }

[Test]
public void testIfSpecificInterfaceIsRegistered()
{
using (var scope = b.beginScope())
{
scope.resolve<Interface3>();
}
}

[Test, ExpectedException(typeof(ResolveException))]
public void testIfOnlySpecificInterfaceIsRegistered()
{
using (var scope = b.beginScope())
{
scope.resolve<Interface2>();
}
}

interface Interface4
{}

interface Interface5
{}

interface Interface6
{}

[DefaultImplementation(typeof(Interface4))]
[DefaultImplementation(typeof(Interface5))]
sealed class MyDefault3 : Interface4, Interface5, Interface6
{}

[Test]
public void testIfMultipleInterfacesAreRegistered()
{
using (var scope = b.beginScope())
{
var x = scope.resolve<Interface4>();
var y = scope.resolve<Interface5>();
Assert.AreSame(x, y);
}
}

[Test, ExpectedException(typeof(ResolveException))]
public void testIfOnlySpecifiedMultipleInterfacesAreRegistered()
{
using (var scope = b.beginScope())
{
scope.resolve<Interface6>();
}
}

interface Interface7
{ }

interface Interface8
{ }

interface Interface9
{ }

[DefaultImplementation(typeof(Interface7), typeof(Interface8))]
sealed class MyDefault4 : Interface7, Interface8, Interface9
{ }

[Test]
public void testIfMultipleInterfacesAreRegisteredParam()
{
using (var scope = b.beginScope())
{
var x = scope.resolve<Interface7>();
var y = scope.resolve<Interface8>();
Assert.AreSame(x, y);
}
}

[Test, ExpectedException(typeof(ResolveException))]
public void testIfOnlySpecifiedMultipleInterfacesAreRegisteredParam()
{
using (var scope = b.beginScope())
{
scope.resolve<Interface9>();
}
}
}
}

Change log

r42 by paramatrix on Mar 31, 2011   Diff
DefaultImplementation attribute now
supports multiple parameters
Go to: 
Project members, sign in to write a code review

Older revisions

r40 by paramatrix on Mar 31, 2011   Diff
support multiple DefaultImplementation
attributes per class
r39 by paramatrix on Mar 31, 2011   Diff
removed redundant locking of
dictionaries, concrete =>
implementation, new feature:
DefaultImplementation and
Builder.scanAssembly()
All revisions of this file

File info

Size: 2809 bytes, 142 lines

File properties

svn:executable
*
Powered by Google Project Hosting