1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using Microsoft . AspNetCore . Http . Validation ;
5
+ using Microsoft . AspNetCore . Mvc . Testing ;
4
6
using Microsoft . Diagnostics . Monitoring . TestCommon ;
5
7
using Microsoft . Diagnostics . Tools . Monitor ;
6
8
using Microsoft . Diagnostics . Tools . Monitor . Egress ;
7
9
using Microsoft . Diagnostics . Tools . Monitor . Egress . Configuration ;
8
10
using Microsoft . Diagnostics . Tools . Monitor . Egress . FileSystem ;
9
11
using Microsoft . Extensions . Configuration ;
12
+ using Microsoft . Extensions . DependencyInjection ;
10
13
using Microsoft . Extensions . Logging ;
11
14
using Microsoft . Extensions . Options ;
12
15
using Moq ;
22
25
23
26
namespace Microsoft . Diagnostics . Monitoring . Tool . UnitTests
24
27
{
28
+ public class FileSystemEgressExtensionFixture : WebApplicationFactory < Program >
29
+ {
30
+ }
31
+
25
32
[ TargetFrameworkMonikerTrait ( TargetFrameworkMonikerExtensions . CurrentTargetFrameworkMoniker ) ]
26
- public sealed class FileSystemEgressExtensionTests
33
+ public sealed class FileSystemEgressExtensionTests : IClassFixture < FileSystemEgressExtensionFixture >
27
34
{
28
35
const string ProviderName = "TestProvider" ;
29
36
const string ExpectedFileName = "EgressedData.txt" ;
@@ -35,10 +42,12 @@ public sealed class FileSystemEgressExtensionTests
35
42
FileSystemEgressProviderOptions . CopyBufferSize_MaxValue . ToString ( ) ) ;
36
43
37
44
private readonly ITestOutputHelper _outputHelper ;
45
+ private readonly FileSystemEgressExtensionFixture _fixture ;
38
46
39
- public FileSystemEgressExtensionTests ( ITestOutputHelper outputHelper )
47
+ public FileSystemEgressExtensionTests ( ITestOutputHelper outputHelper , FileSystemEgressExtensionFixture fixture )
40
48
{
41
49
_outputHelper = outputHelper ;
50
+ _fixture = fixture ;
42
51
}
43
52
44
53
[ Fact ]
@@ -145,7 +154,7 @@ public async Task FileSystemEgressExtension_IntermediateDirectoryPath_Success()
145
154
Assert . False ( intermediateDirInfo . EnumerateFiles ( ) . Any ( ) , "Intermediate directory should not contain any files." ) ;
146
155
}
147
156
148
- private static IEgressExtension CreateExtension ( Action < ConfigurationSection > callback = null )
157
+ private IEgressExtension CreateExtension ( Action < ConfigurationSection > callback = null )
149
158
{
150
159
List < IConfigurationProvider > configProviders = new ( )
151
160
{
@@ -163,6 +172,8 @@ private static IEgressExtension CreateExtension(Action<ConfigurationSection> cal
163
172
164
173
Mock < ILogger < FileSystemEgressExtension > > mockLogger = new ( ) ;
165
174
Mock < IServiceProvider > mockServiceProvider = new ( ) ;
175
+ mockServiceProvider . Setup ( provider => provider . GetService ( typeof ( IOptions < ValidationOptions > ) ) )
176
+ . Returns ( _fixture . Services . GetRequiredService < IOptions < ValidationOptions > > ( ) ) ;
166
177
167
178
return new FileSystemEgressExtension ( mockServiceProvider . Object , mockConfigurationProvider . Object , mockLogger . Object ) ;
168
179
}
0 commit comments