Skip to content

Commit 75d440b

Browse files
committed
adding unit tests
1 parent 6b7ed31 commit 75d440b

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

test/Cli/Func.UnitTests/ActionsTests/StartHostActionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.IO.Abstractions;
@@ -273,7 +273,7 @@ public async Task GetConfigurationSettings_OverwritesAzFuncEnvironment_WhenAlrea
273273
};
274274

275275
var mockSecretsManager = new Mock<ISecretsManager>();
276-
mockSecretsManager.Setup(s => s.GetSecrets())
276+
mockSecretsManager.Setup(s => s.GetSecrets(false))
277277
.Returns(() => new Dictionary<string, string>(secretsDict));
278278

279279
// Return an empty set of connection strings of the expected type

test/Cli/Func.UnitTests/HelperTests/HostHelperTests.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.IO.Abstractions;
@@ -32,7 +32,7 @@ public async Task GetCustomHandlerExecutable_Throws_When_HostJson_Missing()
3232
[Fact]
3333
public async Task GetCustomHandlerExecutable_Returns_ExecutablePath_When_Present()
3434
{
35-
var json = @"{""customHandler"":{""description"":{""defaultExecutablePath"":""file.exe""}}}";
35+
var json = @"{""customHandler"":{""description"":{ ""defaultExecutablePath"":""file.exe"" }}}";
3636
var fileSystem = Substitute.For<IFileSystem>();
3737
fileSystem.File.Exists(Arg.Any<string>()).Returns(true);
3838
fileSystem.File.Open(Arg.Any<string>(), Arg.Any<FileMode>(), Arg.Any<FileAccess>(), Arg.Any<FileShare>())
@@ -56,7 +56,7 @@ public async Task GetCustomHandlerExecutable_Returns_ExecutablePath_When_Present
5656
[Fact]
5757
public async Task GetCustomHandlerExecutable_Returns_Empty_When_ExecutablePath_Missing()
5858
{
59-
var json = @"{""customHandler"":{""description"":{}}}";
59+
var json = @"{""customHandler"":{ ""description"":{}}}";
6060
var fileSystem = Substitute.For<IFileSystem>();
6161
fileSystem.File.Exists(Arg.Any<string>()).Returns(true);
6262
fileSystem.File.Open(Arg.Any<string>(), Arg.Any<FileMode>(), Arg.Any<FileAccess>(), Arg.Any<FileShare>())
@@ -101,6 +101,40 @@ public async Task GetCustomHandlerExecutable_Returns_Empty_When_CustomHandler_Mi
101101
result.Should().BeEmpty();
102102
}
103103

104+
[Fact]
105+
public async Task GetCustomHandlerExecutable_Uses_Provided_Path_To_Read_HostJson()
106+
{
107+
// Arrange
108+
var customRoot = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
109+
var expectedHostJsonPath = Path.Combine(customRoot, Constants.HostJsonFileName);
110+
var json = @"{""customHandler"":{""description"":{ ""defaultExecutablePath"":""file.exe"" }}}";
111+
112+
var fileSystem = Substitute.For<IFileSystem>();
113+
114+
fileSystem.File.Exists(Arg.Any<string>())
115+
.Returns(ci => string.Equals(ci.ArgAt<string>(0), expectedHostJsonPath, StringComparison.OrdinalIgnoreCase));
116+
117+
fileSystem.File.Open(Arg.Any<string>(), Arg.Any<FileMode>(), Arg.Any<FileAccess>(), Arg.Any<FileShare>())
118+
.Returns(ci =>
119+
{
120+
var path = ci.ArgAt<string>(0);
121+
if (string.Equals(path, expectedHostJsonPath, StringComparison.OrdinalIgnoreCase))
122+
{
123+
return json.ToStream();
124+
}
125+
126+
throw new FileNotFoundException(path);
127+
});
128+
129+
FileSystemHelpers.Instance = fileSystem;
130+
131+
// Act
132+
var result = await HostHelpers.GetCustomHandlerExecutable(customRoot);
133+
134+
// Assert
135+
result.Should().Be("file.exe");
136+
}
137+
104138
public void Dispose()
105139
{
106140
FileSystemHelpers.Instance = _originalFileSystem;

0 commit comments

Comments
 (0)