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

workaround for AppContext.BaseDirectory being null on some platforms #293

Merged
merged 1 commit into from
Jul 3, 2019
Merged

workaround for AppContext.BaseDirectory being null on some platforms #293

merged 1 commit into from
Jul 3, 2019

Conversation

eli-darkly
Copy link
Collaborator

@eli-darkly eli-darkly commented Jun 28, 2019

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.

@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #293 into master will decrease coverage by 0.04%.
The diff coverage is 50%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/WireMock.Net/Owin/AspNetCoreSelfHost.cs 89.58% <50%> (-2.73%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ce26ab...eea99ed. Read the comment docs.

@StefH
Copy link
Collaborator

StefH commented Jun 30, 2019

Thanks for this PR.

Is it possible to also create xamarin unit tests? Or is that not supported?

@eli-darkly
Copy link
Collaborator Author

Is it possible to also create xamarin unit tests?

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.

@eli-darkly
Copy link
Collaborator Author

(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.)

@StefH
Copy link
Collaborator

StefH commented Jul 1, 2019

Another idea : Can you also create a simple xamarin android exanple app which uses wiremock.net and place this in the examples folder?

@eli-darkly
Copy link
Collaborator Author

eli-darkly commented Jul 1, 2019

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.)

@StefH
Copy link
Collaborator

StefH commented Jul 1, 2019

Ok. Thanks for the explanation.

@eli-darkly
Copy link
Collaborator Author

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.

@StefH
Copy link
Collaborator

StefH commented Jul 1, 2019

It's not needed.

@StefH StefH merged commit 55a0a6e into WireMock-Net:master Jul 3, 2019
@eli-darkly eli-darkly deleted the NullAppContextBaseDirectoryWorkaround branch July 3, 2019 16:41
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

Successfully merging this pull request may close these issues.

None yet

2 participants