9
9
using Fritz . StreamTools . StartupServices ;
10
10
using Microsoft . Extensions . Configuration ;
11
11
using Microsoft . Extensions . DependencyInjection ;
12
+ using Microsoft . Extensions . FileProviders ;
12
13
using Microsoft . Extensions . Hosting ;
13
14
using Microsoft . Extensions . Logging ;
14
15
using Microsoft . Extensions . Logging . Abstractions ;
@@ -25,12 +26,14 @@ public void Execute_ShouldRegitserService_WhenAllRequiredConfigurationDone()
25
26
new Dictionary < string , string > ( )
26
27
{
27
28
{ "FakeConfiguration:PropertyOne" , "RandomValue" } ,
28
- { "FakeConfiguration:PropertyTwo" , "RandomValue" }
29
+ { "FakeConfiguration:PropertyTwo" , "RandomValue" } ,
30
+ { "AzureServices:HatDetection:ProjectId" , Guid . NewGuid ( ) . ToString ( ) }
29
31
} ) . Build ( ) ;
30
32
31
33
var serviceCollection = new ServiceCollection ( ) ;
32
34
serviceCollection . AddSingleton < IConfiguration > ( configuration ) ;
33
35
serviceCollection . AddSingleton < ILogger > ( NullLogger . Instance ) ;
36
+ serviceCollection . AddSingleton < IHostEnvironment > ( new FakeHostEnvironment ( ) ) ;
34
37
35
38
36
39
var serviceRequriedConfiguration = new Dictionary < Type , string [ ] > ( )
@@ -51,11 +54,13 @@ public void Execute_ShouldSkipRegisterServices_IfAnyOfRequiredConfigurationNotPa
51
54
new Dictionary < string , string > ( )
52
55
{
53
56
{ "FakeConfiguration:PropertyOne" , "RandomValue" } ,
57
+ { "AzureServices:HatDetection:ProjectId" , Guid . NewGuid ( ) . ToString ( ) }
54
58
} ) . Build ( ) ;
55
59
56
60
var serviceCollection = new ServiceCollection ( ) ;
57
61
serviceCollection . AddSingleton < IConfiguration > ( configuration ) ;
58
62
serviceCollection . AddSingleton < ILogger > ( NullLogger . Instance ) ;
63
+ serviceCollection . AddSingleton < IHostEnvironment > ( new FakeHostEnvironment ( ) ) ;
59
64
60
65
61
66
var serviceRequriedConfiguration = new Dictionary < Type , string [ ] > ( )
@@ -80,6 +85,7 @@ public void Execute_RegisterStreamServicesWithVariousConfigurations_ReturnExpect
80
85
serviceCollection . AddSingleton < ILoggerFactory > ( new LoggerFactory ( ) ) ;
81
86
serviceCollection . AddSingleton < IConfiguration > ( configuration ) ;
82
87
serviceCollection . AddSingleton < ILogger > ( NullLogger . Instance ) ;
88
+ serviceCollection . AddSingleton < IHostEnvironment > ( new FakeHostEnvironment ( ) ) ;
83
89
84
90
// act
85
91
ConfigureServices . Execute ( serviceCollection , configuration , new Dictionary < Type , string [ ] > ( ) ) ;
@@ -109,7 +115,8 @@ private static Dictionary<string, string> MakeFakeConfiguration(string twitchCli
109
115
{ "StreamServices:Twitch:ClientId" , twitchClientId } ,
110
116
{ "StreamServices:Mixer:Channel" , mixerClientId } ,
111
117
{ "StreamServices:Fake:Enabled" , enableFake . ToString ( ) } ,
112
- { "FritzBot:ServerUrl" , "http://localhost:80" }
118
+ { "FritzBot:ServerUrl" , "http://localhost:80" } ,
119
+ { "AzureServices:HatDetection:ProjectId" , Guid . NewGuid ( ) . ToString ( ) }
113
120
} ;
114
121
}
115
122
@@ -125,5 +132,13 @@ public Task StopAsync(CancellationToken cancellationToken)
125
132
return null ;
126
133
}
127
134
}
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
+ }
129
144
}
0 commit comments