99using Fritz . StreamTools . StartupServices ;
1010using Microsoft . Extensions . Configuration ;
1111using Microsoft . Extensions . DependencyInjection ;
12+ using Microsoft . Extensions . FileProviders ;
1213using Microsoft . Extensions . Hosting ;
1314using Microsoft . Extensions . Logging ;
1415using Microsoft . Extensions . Logging . Abstractions ;
@@ -25,12 +26,14 @@ public void Execute_ShouldRegitserService_WhenAllRequiredConfigurationDone()
2526 new Dictionary < string , string > ( )
2627 {
2728 { "FakeConfiguration:PropertyOne" , "RandomValue" } ,
28- { "FakeConfiguration:PropertyTwo" , "RandomValue" }
29+ { "FakeConfiguration:PropertyTwo" , "RandomValue" } ,
30+ { "AzureServices:HatDetection:ProjectId" , Guid . NewGuid ( ) . ToString ( ) }
2931 } ) . Build ( ) ;
3032
3133 var serviceCollection = new ServiceCollection ( ) ;
3234 serviceCollection . AddSingleton < IConfiguration > ( configuration ) ;
3335 serviceCollection . AddSingleton < ILogger > ( NullLogger . Instance ) ;
36+ serviceCollection . AddSingleton < IHostEnvironment > ( new FakeHostEnvironment ( ) ) ;
3437
3538
3639 var serviceRequriedConfiguration = new Dictionary < Type , string [ ] > ( )
@@ -51,11 +54,13 @@ public void Execute_ShouldSkipRegisterServices_IfAnyOfRequiredConfigurationNotPa
5154 new Dictionary < string , string > ( )
5255 {
5356 { "FakeConfiguration:PropertyOne" , "RandomValue" } ,
57+ { "AzureServices:HatDetection:ProjectId" , Guid . NewGuid ( ) . ToString ( ) }
5458 } ) . Build ( ) ;
5559
5660 var serviceCollection = new ServiceCollection ( ) ;
5761 serviceCollection . AddSingleton < IConfiguration > ( configuration ) ;
5862 serviceCollection . AddSingleton < ILogger > ( NullLogger . Instance ) ;
63+ serviceCollection . AddSingleton < IHostEnvironment > ( new FakeHostEnvironment ( ) ) ;
5964
6065
6166 var serviceRequriedConfiguration = new Dictionary < Type , string [ ] > ( )
@@ -80,6 +85,7 @@ public void Execute_RegisterStreamServicesWithVariousConfigurations_ReturnExpect
8085 serviceCollection . AddSingleton < ILoggerFactory > ( new LoggerFactory ( ) ) ;
8186 serviceCollection . AddSingleton < IConfiguration > ( configuration ) ;
8287 serviceCollection . AddSingleton < ILogger > ( NullLogger . Instance ) ;
88+ serviceCollection . AddSingleton < IHostEnvironment > ( new FakeHostEnvironment ( ) ) ;
8389
8490 // act
8591 ConfigureServices . Execute ( serviceCollection , configuration , new Dictionary < Type , string [ ] > ( ) ) ;
@@ -109,7 +115,8 @@ private static Dictionary<string, string> MakeFakeConfiguration(string twitchCli
109115 { "StreamServices:Twitch:ClientId" , twitchClientId } ,
110116 { "StreamServices:Mixer:Channel" , mixerClientId } ,
111117 { "StreamServices:Fake:Enabled" , enableFake . ToString ( ) } ,
112- { "FritzBot:ServerUrl" , "http://localhost:80" }
118+ { "FritzBot:ServerUrl" , "http://localhost:80" } ,
119+ { "AzureServices:HatDetection:ProjectId" , Guid . NewGuid ( ) . ToString ( ) }
113120 } ;
114121 }
115122
@@ -125,5 +132,13 @@ public Task StopAsync(CancellationToken cancellationToken)
125132 return null ;
126133 }
127134 }
128- }
135+
136+ private class FakeHostEnvironment : IHostEnvironment
137+ {
138+ public string ApplicationName { get ; set ; }
139+ public IFileProvider ContentRootFileProvider { get ; set ; }
140+ public string ContentRootPath { get ; set ; }
141+ public string EnvironmentName { get ; set ; }
142+ }
143+ }
129144}
0 commit comments