@@ -117,9 +117,10 @@ And then the following tests:
117117public void Example_test_with_concrete_type_provided ()
118118{
119119 const int val = 3 ;
120- var autoSubstitute = new AutoSubstitute ();
120+ using var autoSubstitute = AutoSubstitute .Configure ()
121+ .Provide <IDependency2 , Dependency2 >(out _ )
122+ .Build ();
121123 autoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val ); // This shouldn't do anything because of the next line
122- autoSubstitute .Provide <IDependency2 , Dependency2 >();
123124 autoSubstitute .Resolve <IDependency1 >().SomeMethod (Arg .Any <int >()).Returns (c => c .Arg <int >());
124125
125126 var result = autoSubstitute .Resolve <MyClass >().AMethod ();
@@ -132,9 +133,10 @@ public void Example_test_with_concrete_object_provide()
132133{
133134 const int val1 = 3 ;
134135 const int val2 = 2 ;
135- var autoSubstitute = new AutoSubstitute ();
136+ using var autoSubstitute = AutoSubstitute .Configure ()
137+ .Provide (new ConcreteClass (val2 ))
138+ .Build ();
136139 autoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val1 );
137- autoSubstitute .Provide (new ConcreteClass (val2 ));
138140
139141 var result = autoSubstitute .Resolve <MyClassWithConcreteDependency >().AMethod ();
140142
@@ -151,9 +153,10 @@ public void Example_test_with_substitute_for_concrete()
151153 const int val1 = 3 ;
152154 const int val2 = 2 ;
153155 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 ();
155159 autoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val1 );
156- autoSubstitute .SubstituteFor <ConcreteClass >(val2 ).Add (Arg .Any <int >()).Returns (val3 );
157160
158161 var result = autoSubstitute .Resolve <MyClassWithConcreteDependency >().AMethod ();
159162
@@ -206,10 +209,9 @@ public void Example_test_with_substitute_for_concrete_resolved_from_autofac()
206209 const int val1 = 2 ;
207210 const int val2 = 3 ;
208211 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 ();
213215 AutoSubstitute .Resolve <IDependency2 >().SomeOtherMethod ().Returns (val2 );
214216 AutoSubstitute .Resolve <IDependency1 >().SomeMethod (val1 ).Returns (val3 );
215217
0 commit comments