From d0142b33348f0b26dfd866e8493bd0a162b301df Mon Sep 17 00:00:00 2001 From: AliReZa Sabouri Date: Fri, 6 Dec 2024 22:34:36 +0100 Subject: [PATCH] test: fix broken tests --- tests/HuskyTest/Cli/ExecCommandTests.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/HuskyTest/Cli/ExecCommandTests.cs b/tests/HuskyTest/Cli/ExecCommandTests.cs index e4194e2..f017fd4 100644 --- a/tests/HuskyTest/Cli/ExecCommandTests.cs +++ b/tests/HuskyTest/Cli/ExecCommandTests.cs @@ -1,7 +1,7 @@ using System.Collections.Immutable; using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; using System.Reflection; -using System.Text; using CliFx.Exceptions; using CliFx.Infrastructure; using FluentAssertions; @@ -145,13 +145,15 @@ public async Task Exec_CachedScript_ShouldThrowWithNonZeroExitCode() const string filePath = "fake_file.csx"; const string stringContent = @" return 1; - "; + "; + _io.Path.GetDirectoryName(Arg.Any()).Returns(Directory.GetCurrentDirectory()); _io.File.Exists(Arg.Any()).Returns(true); _io.Directory.Exists(Arg.Any()).Returns(true); _io.File.ReadAllTextAsync(Arg.Any()).Returns(stringContent); - await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(stringContent)); - _io.FileStream.Create(Arg.Any(), FileMode.Open).Returns(stream); + + var mockFileSystem = new MockFileSystem(new Dictionary { { filePath, new MockFileData(stringContent) } }); + _io.FileStream.New(filePath, FileMode.Open).Returns(mockFileSystem.File.Create(filePath)); var opts = ScriptOptions.Default .WithSourceResolver(new SourceFileResolver(ImmutableArray.Empty, null)) @@ -160,7 +162,7 @@ public async Task Exec_CachedScript_ShouldThrowWithNonZeroExitCode() var compilation = script.GetCompilation(); await using var assemblyStream = new MemoryStream(); - var _ = compilation.Emit(assemblyStream); + _ = compilation.Emit(assemblyStream); _assembly.LoadFile(Arg.Any()).Returns(Assembly.Load(assemblyStream.ToArray())); var command = new ExecCommand(_io, _git, _assembly) { Path = filePath, Arguments = new List { "test" }, NoCache = false };