-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
workaround for AppContext.BaseDirectory being null on some platforms #293
workaround for AppContext.BaseDirectory being null on some platforms #293
Conversation
Codecov Report
@@ Coverage Diff @@
## master #293 +/- ##
==========================================
- Coverage 79.72% 79.67% -0.05%
==========================================
Files 108 108
Lines 4305 4310 +5
==========================================
+ Hits 3432 3434 +2
- Misses 873 876 +3
Continue to review full report at Codecov.
|
Thanks for this PR. Is it possible to also create xamarin unit tests? Or is that not supported? |
There's no single Xamarin runtime - there's Xamarin Android, Xamarin iOS, etc. - although Xamarin Android is the only one with this issue as far as I know. So you have to actually run the targeted OS, or at least an emulator for it. There is a way to run Xunit tests inside of an Android emulator, I've done it, but it's extremely cumbersome and slow and I don't know how to set it up in Azure. |
(Here's what I mean by "cumbersome": https://gist.github.com/eli-darkly/d3d33aa1cea67a1ce7935e9cb6676e1b - I think it is probably possible to do the equivalent in Windows, which might even be a bit faster since the Android emulator is known to perform very badly on Linux.) |
Another idea : Can you also create a simple xamarin android exanple app which uses wiremock.net and place this in the examples folder? |
@StefH I guess, but it is kind of a weird case. Your example apps are just platform-specific wrappers for a piece of shared test code that writes its output to the console. In an Android app, you wouldn't be able to see this console output in the GUI, so I would need to change the shared code to write to some kind of abstraction that can be redirected to a UI component. (The output also won't appear on the console if you run the Android emulator from the command line - you need to do special magic to extract it from the system log. That's part of why the script I posted in that Gist is so elaborate.) |
Ok. Thanks for the explanation. |
I'm happy to give it a try - I don't like to submit code that has no tests at all (although at least the existing tests should be enough to show that this change didn't break anything for apps that are not using Xamarin Android) - just warning you that it would probably also involve a bit of refactoring of your existing examples. |
It's not needed. |
This addresses #292 which is known to affect Xamarin Android.
I'm not aware of any other platforms where this is a problem, but if there are any, the principle is the same: if AppContext.BaseDirectory is null, then WebHostBuilder won't work without setting ContentRoot. WireMock.Net wouldn't work at all under that condition before, so the workaround can't hurt - and the workaround is only used in that condition, so platforms where WireMock.Net did work are not affected.
I don't know of any way to unit-test this change, since it's not possible to change AppContext.BaseDirectory dynamically in a test. However, I have tested manually in Xamarin Android and it solved the problem for me.