File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed
IntelliTect.TestTools.TestFramework
IntelliTect.TestTools.TestFramework.Tests
IntelliTect.TestTools.TestFramework Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 11namespace IntelliTect . TestTools . TestFramework . Tests
22{
3- public class ExampleDataThing
3+ public interface IExampleDataInterface
4+ {
5+ string Testing { get ; set ; }
6+ }
7+
8+ public class ExampleDataThing : IExampleDataInterface
49 {
510 public string Testing { get ; set ; } = "Testing" ;
611 }
Original file line number Diff line number Diff line change @@ -105,6 +105,26 @@ public void FetchByServiceForExecuteArg()
105105 . ExecuteTestCase ( ) ;
106106 }
107107
108+ [ Fact ]
109+ public void FetchByImplementationForExecuteArg ( )
110+ {
111+ TestBuilder builder = new TestBuilder ( ) ;
112+ builder
113+ . AddDependencyInstance < IExampleDataInterface > ( new ExampleDataThing ( ) )
114+ . AddTestBlock < ExampleTestBlockWithExecuteArgForInterface > ( )
115+ . ExecuteTestCase ( ) ;
116+ }
117+
118+ [ Fact ]
119+ public void FetchByImplementationAndTypeForExecuteArg ( )
120+ {
121+ TestBuilder builder = new TestBuilder ( ) ;
122+ builder
123+ . AddDependencyService < IExampleDataInterface , ExampleDataThing > ( )
124+ . AddTestBlock < ExampleTestBlockWithExecuteArgForInterface > ( )
125+ . ExecuteTestCase ( ) ;
126+ }
127+
108128 // This test probably isn't necessary. This is MS DI out-of-the-box functionality
109129 [ Fact ]
110130 public void FetchByFactoryForConstructor ( )
@@ -375,6 +395,15 @@ public void Execute(ExampleDataThing input)
375395 }
376396 }
377397
398+ public class ExampleTestBlockWithExecuteArgForInterface : ITestBlock
399+ {
400+ public void Execute ( IExampleDataInterface input )
401+ {
402+ if ( input == null ) throw new ArgumentNullException ( nameof ( input ) ) ;
403+ Assert . Equal ( "Testing" , input . Testing ) ;
404+ }
405+ }
406+
378407 public class ExampleTestBlockWithPropertyForOwnType : ITestBlock
379408 {
380409 public ExampleDataThing Input { get ; set ; }
Original file line number Diff line number Diff line change @@ -79,6 +79,12 @@ public TestBuilder AddDependencyService<T>()
7979 return this ;
8080 }
8181
82+ public TestBuilder AddDependencyService < TServiceType , TImplementationType > ( )
83+ {
84+ Services . AddScoped ( typeof ( TServiceType ) , typeof ( TImplementationType ) ) ;
85+ return this ;
86+ }
87+
8288 /// <summary>
8389 /// Adds an instance of a Type to the container that is needed for a TestBlock to execute
8490 /// </summary>
@@ -92,6 +98,12 @@ public TestBuilder AddDependencyInstance(object objToAdd)
9298 return this ;
9399 }
94100
101+ public TestBuilder AddDependencyInstance < T > ( object objToAdd )
102+ {
103+ Services . AddSingleton ( typeof ( T ) , objToAdd ) ;
104+ return this ;
105+ }
106+
95107 // Are there other cases where we'll need to add something at this level?
96108 // If so, this shouldn't be called "AddLogger".
97109 // Might need to make this scoped. It's behaving oddly when running tests in parallel
You can’t perform that action at this time.
0 commit comments