@@ -10,7 +10,8 @@ namespace AutofacContrib.NSubstitute.Tests
10
10
public class SubstituteForFixture
11
11
{
12
12
[ Test ]
13
- public void Example_test_with_substitute_for_concrete ( )
13
+ [ Obsolete ]
14
+ public void Example_test_with_substitute_for_concrete_obsolete ( )
14
15
{
15
16
const int val1 = 3 ;
16
17
const int val2 = 2 ;
@@ -27,14 +28,32 @@ public void Example_test_with_substitute_for_concrete()
27
28
Assert . That ( result , Is . EqualTo ( val3 ) ) ;
28
29
}
29
30
31
+ [ Test ]
32
+ public void Example_test_with_substitute_for_concrete ( )
33
+ {
34
+ const int val1 = 3 ;
35
+ const int val2 = 2 ;
36
+ const int val3 = 10 ;
37
+
38
+ using var utoSubstitute = AutoSubstitute . Configure ( )
39
+ . SubstituteFor < ConcreteClass > ( val2 ) . ConfigureSubstitute ( c => c . Add ( Arg . Any < int > ( ) ) . Returns ( val3 ) )
40
+ . Build ( ) ;
41
+
42
+ utoSubstitute . Resolve < IDependency2 > ( ) . SomeOtherMethod ( ) . Returns ( val1 ) ;
43
+
44
+ var result = utoSubstitute . Resolve < MyClassWithConcreteDependency > ( ) . AMethod ( ) ;
45
+
46
+ Assert . That ( result , Is . EqualTo ( val3 ) ) ;
47
+ }
48
+
30
49
[ Test ]
31
50
public void SubstituteForConfigureWithContext ( )
32
51
{
33
52
const int val = 2 ;
34
53
35
54
using var utoSubstitute = AutoSubstitute . Configure ( )
36
- . SubstituteFor < ConcreteClass > ( val ) . Configured ( )
37
- . SubstituteFor < ConcreteClassWithObject > ( ) . Configure ( ( s , ctx ) =>
55
+ . SubstituteFor < ConcreteClass > ( val )
56
+ . SubstituteFor < ConcreteClassWithObject > ( ) . ConfigureSubstitute ( ( s , ctx ) =>
38
57
{
39
58
s . Configure ( ) . GetResult ( ) . Returns ( ctx . Resolve < ConcreteClass > ( ) ) ;
40
59
} )
@@ -50,7 +69,7 @@ public void SubstituteForConfigureWithContext()
50
69
public void BaseCalledOnSubstituteForPartsOf ( )
51
70
{
52
71
using var mock = AutoSubstitute . Configure ( )
53
- . SubstituteForPartsOf < Test1 > ( ) . Configured ( )
72
+ . SubstituteForPartsOf < Test1 > ( )
54
73
. Build ( ) ;
55
74
56
75
var test1 = mock . Resolve < Test1 > ( ) ;
@@ -63,7 +82,7 @@ public void BaseCalledOnSubstituteForPartsOf()
63
82
public void BaseNotCalledOnSubstituteFor ( )
64
83
{
65
84
using var mock = AutoSubstitute . Configure ( )
66
- . SubstituteFor < Test1 > ( ) . Configured ( )
85
+ . SubstituteFor < Test1 > ( )
67
86
. Build ( ) ;
68
87
69
88
var test1 = mock . Resolve < Test1 > ( ) ;
@@ -76,7 +95,7 @@ public void BaseNotCalledOnSubstituteFor()
76
95
public void FailsIfSubstituteTypeIsChanged ( )
77
96
{
78
97
var builder = AutoSubstitute . Configure ( )
79
- . SubstituteFor < Test1 > ( ) . Configured ( ) ;
98
+ . SubstituteFor < Test1 > ( ) ;
80
99
81
100
Assert . Throws < InvalidOperationException > ( ( ) => builder . SubstituteForPartsOf < Test1 > ( ) ) ;
82
101
}
@@ -85,7 +104,7 @@ public void FailsIfSubstituteTypeIsChanged()
85
104
public void FailsIfSubstituteTypeIsChanged2 ( )
86
105
{
87
106
var builder = AutoSubstitute . Configure ( )
88
- . SubstituteForPartsOf < Test1 > ( ) . Configured ( ) ;
107
+ . SubstituteForPartsOf < Test1 > ( ) ;
89
108
90
109
Assert . Throws < InvalidOperationException > ( ( ) => builder . SubstituteFor < Test1 > ( ) ) ;
91
110
}
@@ -95,7 +114,7 @@ public void PropertiesNotSetByDefault()
95
114
{
96
115
using var mock = AutoSubstitute . Configure ( )
97
116
. Provide < IProperty , CustomProperty > ( out _ )
98
- . SubstituteFor < TestWithProperty > ( ) . Configured ( )
117
+ . SubstituteFor < TestWithProperty > ( )
99
118
. Build ( ) ;
100
119
101
120
Assert . IsNull ( mock . Resolve < TestWithProperty > ( ) . PropertySetter ) ;
@@ -109,7 +128,6 @@ public void PropertiesSetIfRequested()
109
128
. Provide < IProperty , CustomProperty > ( out var property )
110
129
. SubstituteFor < TestWithProperty > ( )
111
130
. InjectProperties ( )
112
- . Configured ( )
113
131
. Build ( ) ;
114
132
115
133
Assert . AreEqual ( property . Value , mock . Resolve < TestWithProperty > ( ) . PropertySetter ) ;
@@ -122,7 +140,7 @@ public void PropertiesSetIfGloballyRequested()
122
140
using var mock = AutoSubstitute . Configure ( )
123
141
. InjectProperties ( )
124
142
. Provide < IProperty , CustomProperty > ( out var property )
125
- . SubstituteFor < TestWithProperty > ( ) . Configured ( )
143
+ . SubstituteFor < TestWithProperty > ( )
126
144
. Build ( ) ;
127
145
128
146
Assert . AreEqual ( property . Value , mock . Resolve < TestWithProperty > ( ) . PropertySetter ) ;
0 commit comments