Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BodyAsFile .json files interferes with WatchStaticMappings #179

Closed
markdebruijne opened this issue Aug 12, 2018 · 3 comments
Closed

BodyAsFile .json files interferes with WatchStaticMappings #179

markdebruijne opened this issue Aug 12, 2018 · 3 comments

Comments

@markdebruijne
Copy link

  • Configure ReadStaticMappings(myMappingsFolder) to import request matchers from static .json files
  • Also Configure FileWatchers for that folder: WatchStaticMappings(myMappingsFolder)
  • Configure one of those requests to respond based on a BodyAsFile
"Response": {
    "StatusCode": 200,
    "BodyAsFile": "mappings/myResponseBodyFile.json"
  }
  • Run the application, which will monitor all files in that folder
  • Update myResponseBodyFile.json

Result: Unhandled exception occurs

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null.
  Source=WireMock.Net
  StackTrace:
   at WireMock.Validation.Check.NotNull[T](T value, String parameterName) in D:\data\inetpub\WireMock.Net\src\WireMock.Net\Validation\Check.cs:line 44
   at WireMock.Server.FluentMockServer.DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Nullable`1 guid, String path) in D:\data\inetpub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs:line 415
   at WireMock.Server.FluentMockServer.ReadStaticMappingAndAddOrUpdate(String path) in D:\data\inetpub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs:line 202
   at WireMock.Server.FluentMockServer.<WatchStaticMappings>b__12_1(Object sender, FileSystemEventArgs args) in D:\data\inetpub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs:line 164
   at WireMock.Util.EnhancedFileSystemWatcher.OnChanged(FileSystemEventArgs e) in D:\data\inetpub\WireMock.Net\src\WireMock.Net\Util\EnhancedFileSystemWatcher.cs:line 128
   at WireMock.Util.EnhancedFileSystemWatcher.OnChanged(Object sender, FileSystemEventArgs e) in D:\data\inetpub\WireMock.Net\src\WireMock.Net\Util\EnhancedFileSystemWatcher.cs:line 224
   at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(WatcherChangeTypes changeType, String name)
   at System.IO.FileSystemWatcher.ParseEventBufferAndNotifyForEach(Byte[] buffer)
   at System.IO.FileSystemWatcher.ReadDirectoryChangesCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

It breaks because the .json file only contains the Body of the response, while the deserializer is expecting both a Request: {} and Response: {} element

This feels like a bug because I want to have my request .json and responseBody .json stored close together on my file system. Is there another approach to store them differently which is compatible with the file watchers. I do want (during development) want to be able to watch both.

@StefH
Copy link
Collaborator

StefH commented Aug 12, 2018

The ReadStaticMappings and WatchStaticMappings are meant to be used for the complete mappings. A complete mapping contains both the request and the response. For an example, see https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#__adminmappings-1.

If you want to use BodyAsFile, you could just try to use a file with another extension, like .response. That kind of files will not be read or watched.

Note that you probably need to set caching to false, (BodyAsFileIsCached = false) for that specific mapping.

@StefH
Copy link
Collaborator

StefH commented Sep 11, 2018

@markdebruijne does above text answer your question? Or do you still have more questions?

@StefH
Copy link
Collaborator

StefH commented Oct 12, 2018

@markdebruijne Closing this issue.

If you still have questions, comment here or create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants