1
- // Copyright (c) .NET Foundation. All rights reserved.
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the MIT License. See LICENSE in the project root for license information.
3
3
4
4
using System . IO . Abstractions ;
@@ -32,7 +32,7 @@ public async Task GetCustomHandlerExecutable_Throws_When_HostJson_Missing()
32
32
[ Fact ]
33
33
public async Task GetCustomHandlerExecutable_Returns_ExecutablePath_When_Present ( )
34
34
{
35
- var json = @"{""customHandler"":{""description"":{""defaultExecutablePath"":""file.exe""}}}" ;
35
+ var json = @"{""customHandler"":{""description"":{ ""defaultExecutablePath"":""file.exe"" }}}" ;
36
36
var fileSystem = Substitute . For < IFileSystem > ( ) ;
37
37
fileSystem . File . Exists ( Arg . Any < string > ( ) ) . Returns ( true ) ;
38
38
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
56
56
[ Fact ]
57
57
public async Task GetCustomHandlerExecutable_Returns_Empty_When_ExecutablePath_Missing ( )
58
58
{
59
- var json = @"{""customHandler"":{""description"":{}}}" ;
59
+ var json = @"{""customHandler"":{ ""description"":{}}}" ;
60
60
var fileSystem = Substitute . For < IFileSystem > ( ) ;
61
61
fileSystem . File . Exists ( Arg . Any < string > ( ) ) . Returns ( true ) ;
62
62
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
101
101
result . Should ( ) . BeEmpty ( ) ;
102
102
}
103
103
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
+
104
138
public void Dispose ( )
105
139
{
106
140
FileSystemHelpers . Instance = _originalFileSystem ;
0 commit comments