Skip to content

Commit b5feaa9

Browse files
committed
#201 - fix env di + testing
1 parent e83a800 commit b5feaa9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Infrastructure/HydraScript.Infrastructure/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static IServiceCollection AddDomain<TGeneratedRegexContainer>(this IServi
2424
services.AddSingleton<ILexer, RegexLexer>();
2525
services.AddSingleton<IParser, TopDownParser>();
2626

27-
services.AddSingleton<IEnvironmentVariableProvider, SystemEnvironmentVariableProvider>();
27+
services.AddSingleton(SystemEnvironmentVariableProvider.Instance);
2828
services.AddSingleton<IOutputWriter, LoggingWriter>();
2929
services.AddSingleton<IVirtualMachine, VirtualMachine>();
3030

tests/HydraScript.IntegrationTests/TestHostFixture.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.IO.Abstractions;
22
using HydraScript.Infrastructure;
33
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.DependencyInjection.Extensions;
45
using Microsoft.Extensions.Logging;
56
using NSubstitute;
67
using Serilog;
@@ -15,6 +16,7 @@ public record Options(
1516
string FileName = ScriptFileName + ".js",
1617
bool Dump = false,
1718
bool MockFileSystem = true,
19+
bool MockEnv = true,
1820
string InMemoryScript = "");
1921

2022
public class Runner(ServiceProvider serviceProvider, Executor executor): IDisposable
@@ -54,7 +56,13 @@ public Runner GetRunner(Options options, Action<IServiceCollection>? configureTe
5456
if (options.MockFileSystem)
5557
{
5658
var fileSystem = Substitute.For<IFileSystem>();
57-
services.AddSingleton(fileSystem);
59+
services.Replace(ServiceDescriptor.Singleton(fileSystem));
60+
}
61+
62+
if (options.MockEnv)
63+
{
64+
var env = Substitute.For<IEnvironmentVariableProvider>();
65+
services.Replace(ServiceDescriptor.Singleton(env));
5866
}
5967

6068
if (!string.IsNullOrWhiteSpace(options.InMemoryScript))

0 commit comments

Comments
 (0)