You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The response.file configuration should be able to resolve relative path instead of absolute path to app root. It's useful when we try to restructure the mocks folder and move the mock files often.
To Reproduce
Create this mock under [app]/Mocks folder
Assuming signin.html file requires many resource files (images, javascript, css, etc), I grab those from HAR file. Because this page requires many files, so let's structure the folder and create SignIn folder under Mocks folder and move this mock file along with other mocks. Updating from Mocks/signin.html to Mocks/SignIn/signin.html is easy. But updating the rest of the mocks takes time.
Expected behavior
Introduce relative path strategy, i.e. ./ or ../ let's assume it's relative to the mock (.json) file
Screenshots
[10:11:33 ERR] 0HM6407H0SUU4:00000011 Error generating mocked response
System.IO.FileNotFoundException: Could not find file 'C:\Application\Mockaco\signin-1.html'.
File name: 'C:\Application\Mockaco\signin.html'
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.ReadAllBytesAsync(String path, CancellationToken cancellationToken)
at Mockaco.BinaryResponseBodyStrategy.GetFileBytes(String path)
at Mockaco.BinaryResponseBodyStrategy.GetResponseBodyBytesFromTemplate(ResponseTemplate responseTemplate)
at Mockaco.ResponseMockingMiddleware.PrepareResponse(HttpResponse httpResponse, Template transformedTemplate, IResponseBodyFactory responseBodyFactory, MockacoOptions options)
at Mockaco.ResponseMockingMiddleware.Invoke(HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext, IResponseBodyFactory responseBodyFactory, IOptionsSnapshot`1 options)
at Mockaco.RequestMatchingMiddleware.Invoke(HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext, IMockProvider mockProvider, ITemplateTransformer templateTransformer, IEnumerable`1 requestMatchers)
at Mockaco.ResponseDelayMiddleware.Invoke(HttpContext httpContext, IMockacoContext mockacoContext, ILogger`1 logger)
at Mockaco.ErrorHandlingMiddleware.Invoke(HttpContext httpContext, IMockacoContext mockacoContext, IOptionsSnapshot`1 statusCodeOptions, IMockProvider mockProvider, ILogger`1 logger)
The text was updated successfully, but these errors were encountered:
Currently, the file param is relative to Mocks folder. How can we distinguish between relative to Mocks folder and mock file (.json). We have several options here:
if it's starter with ./ or ../, then it's relative to json mock file, otherwise, relative to Mocks folder. Cons: inconsistent configuration, need to document that
always treat as relative to json mock file, of course, we will support ./ and ../ syntax. Cons: not backward compatible.
What do you think?
always treat as relative to json mock file, of course, we will support ./ and ../ syntax
but if the file is not found relative to the .json, search it relative to the Mock root path as a fallback, hence keeping backward compatibility.
Although it may cause some confusion in rare cases, I don't think such fallback could cause big problems at all.
Going further: Maybe it could also have a list of "hint paths" just like Visual Studio, a list of paths ordered by priority to search for mocks, when the absolute path is not known (maybe a little too much)
Describe the bug
The
response.file
configuration should be able to resolve relative path instead of absolute path to app root. It's useful when we try to restructure the mocks folder and move the mock files often.To Reproduce
Create this mock under [app]/Mocks folder
Assuming signin.html file requires many resource files (images, javascript, css, etc), I grab those from HAR file. Because this page requires many files, so let's structure the folder and create SignIn folder under Mocks folder and move this mock file along with other mocks. Updating from Mocks/signin.html to Mocks/SignIn/signin.html is easy. But updating the rest of the mocks takes time.
Expected behavior
Introduce relative path strategy, i.e.
./
or../
let's assume it's relative to the mock (.json) fileScreenshots
The text was updated successfully, but these errors were encountered: