|
8 | 8 | using Microsoft.Extensions.DependencyInjection.Extensions; |
9 | 9 | using Microsoft.Extensions.FileProviders; |
10 | 10 | using Microsoft.Extensions.Logging; |
| 11 | +using Moq; |
11 | 12 |
|
12 | 13 | namespace EssentialCSharp.Web.Tests; |
13 | 14 |
|
@@ -51,9 +52,11 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) |
51 | 52 | var fileProvider = new PhysicalFileProvider(testDataPath); |
52 | 53 | services.AddSingleton<IListingSourceCodeService>(sp => |
53 | 54 | { |
54 | | - var mockEnv = new TestWebHostEnvironment(testDataPath, fileProvider); |
| 55 | + var mockEnv = new Mock<IWebHostEnvironment>(); |
| 56 | + mockEnv.Setup(m => m.ContentRootPath).Returns(testDataPath); |
| 57 | + mockEnv.Setup(m => m.ContentRootFileProvider).Returns(fileProvider); |
55 | 58 | var logger = sp.GetRequiredService<ILogger<ListingSourceCodeService>>(); |
56 | | - return new ListingSourceCodeService(mockEnv, logger); |
| 59 | + return new ListingSourceCodeService(mockEnv.Object, logger); |
57 | 60 | }); |
58 | 61 | }); |
59 | 62 | } |
@@ -92,22 +95,3 @@ protected override void Dispose(bool disposing) |
92 | 95 | } |
93 | 96 | } |
94 | 97 | } |
95 | | - |
96 | | -/// <summary> |
97 | | -/// Minimal IWebHostEnvironment implementation that redirects ContentRoot to the TestData directory. |
98 | | -/// </summary> |
99 | | -internal sealed class TestWebHostEnvironment : IWebHostEnvironment |
100 | | -{ |
101 | | - public TestWebHostEnvironment(string contentRootPath, IFileProvider contentRootFileProvider) |
102 | | - { |
103 | | - ContentRootPath = contentRootPath; |
104 | | - ContentRootFileProvider = contentRootFileProvider; |
105 | | - } |
106 | | - |
107 | | - public string ContentRootPath { get; set; } |
108 | | - public IFileProvider ContentRootFileProvider { get; set; } |
109 | | - public string WebRootPath { get; set; } = string.Empty; |
110 | | - public IFileProvider WebRootFileProvider { get; set; } = new NullFileProvider(); |
111 | | - public string EnvironmentName { get; set; } = "Testing"; |
112 | | - public string ApplicationName { get; set; } = "EssentialCSharp.Web"; |
113 | | -} |
0 commit comments