Reading An Asset In A Xamarin Nunit Test Class
I want to read a mock RSS feed file to test against in a Xamarin NUnit test for an Android app. The test class has no context so I can't put the file in the Assets folder and do th
Solution 1:
The test class has no context so I can't put the file in the Assets folder and do this:
Is there a reason you need to use Android Assets? Using .NET Embedded Resources by setting the file's Build action to EmbeddedResource
permits greater portability -- it's present on all .NET platforms -- and neatly sidesteps the Android Context issue.
If you need to use Android Assets, then you can use the Android.App.Application.Context property, which is equivalent to the Context.ApplicationContext property, except static and available everywhere.
Solution 2:
Check properties of the file. I had to set "Build Action" to AndroidAsset and than you can use instanceOfAssetManager.Open(feedFile);
Post a Comment for "Reading An Asset In A Xamarin Nunit Test Class"