@@ -117,9 +117,10 @@ And then the following tests:
117
117
public void Example_test_with_concrete_type_provided ()
118
118
{
119
119
const int val = 3 ;
120
- var autoSubstitute = new AutoSubstitute ();
120
+ using var autoSubstitute = AutoSubstitute .Configure ()
121
+ .Provide <IDependency2 , Dependency2 >(out _ )
122
+ .Build ();
121
123
autoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val ); // This shouldn't do anything because of the next line
122
- autoSubstitute .Provide <IDependency2 , Dependency2 >();
123
124
autoSubstitute .Resolve <IDependency1 >().SomeMethod (Arg .Any <int >()).Returns (c => c .Arg <int >());
124
125
125
126
var result = autoSubstitute .Resolve <MyClass >().AMethod ();
@@ -132,9 +133,10 @@ public void Example_test_with_concrete_object_provide()
132
133
{
133
134
const int val1 = 3 ;
134
135
const int val2 = 2 ;
135
- var autoSubstitute = new AutoSubstitute ();
136
+ using var autoSubstitute = AutoSubstitute .Configure ()
137
+ .Provide (new ConcreteClass (val2 ))
138
+ .Build ();
136
139
autoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val1 );
137
- autoSubstitute .Provide (new ConcreteClass (val2 ));
138
140
139
141
var result = autoSubstitute .Resolve <MyClassWithConcreteDependency >().AMethod ();
140
142
@@ -151,9 +153,10 @@ public void Example_test_with_substitute_for_concrete()
151
153
const int val1 = 3 ;
152
154
const int val2 = 2 ;
153
155
const int val3 = 10 ;
154
- var autoSubstitute = new AutoSubstitute ();
156
+ using var autoSubstitute = AutoSubstitute .Configure ()
157
+ .SubstituteFor <ConcreteClass >(val2 ).Configure (c => c .Add (Arg .Any <int >()).Returns (val3 ))
158
+ .Build ();
155
159
autoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val1 );
156
- autoSubstitute .SubstituteFor <ConcreteClass >(val2 ).Add (Arg .Any <int >()).Returns (val3 );
157
160
158
161
var result = autoSubstitute .Resolve <MyClassWithConcreteDependency >().AMethod ();
159
162
@@ -206,10 +209,9 @@ public void Example_test_with_substitute_for_concrete_resolved_from_autofac()
206
209
const int val1 = 2 ;
207
210
const int val2 = 3 ;
208
211
const int val3 = 4 ;
209
- var AutoSubstitute = new AutoSubstitute ();
210
- // Much better / more maintainable than:
211
- // AutoSubstitute.SubstituteFor<ConcreteClassWithDependency>(AutoSubstitute.Resolve<IDependency1>(), val1);
212
- AutoSubstitute .ResolveAndSubstituteFor <ConcreteClassWithDependency >(new TypedParameter (typeof (int ), val1 ));
212
+ using var AutoSubstitute = AutoSubstitute .Configure ()
213
+ .ResolveAndSubstituteFor <ConcreteClassWithDependency >(new TypedParameter (typeof (int ), val1 ))
214
+ .Build ();
213
215
AutoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val2 );
214
216
AutoSubstitute .Resolve <IDependency1 >().SomeMethod (val1 ).Returns (val3 );
215
217
0 commit comments