Using Xamarin Essentials in Xamarin UI Test project - xamarin

I am trying to open Browser with a link inside my test method (application is launched prior to that). I installed Xamarin essentials Nuget, and per my current understanding I am not able to use this package outside xamarin project. I found some solutions (see below, using Mock object) but this does not seem to work.
var mockLaunch = new Mock();
IBrowser open = mockLaunch.Object;
open.OpenAsync("https://i389l.app.link/JFsYo6d1Y37", BrowserLaunchMode.SystemPreferred);
Does anyone have solution how to open browser (using real Android device) inside my test method? Thank you.

Related

HttpRequest.TransportInformation not available in UWP app

I need to validate SSL certificate of a website in my UWP app, and I am following the method described at this URL: https://learn.microsoft.com/en-us/windows/uwp/security/intro-to-secure-windows-app-development, but there is no TransportInformation property available under RequestMessage class in my IDE, and the intellisense complains about it too. I'm using VS2017, .NetCore 5.3.3, target Version 15063 min version 10586. Please help!
Make sure you're using Windows.Web.Http.HttpRequestMessage and not System.Net.Http.HttpRequestMessage. TransportInformation is a member of the Windows.Web version only.
You can use Visual Studio's object browser to help find which class a property is in. Browse "My Solution", search for TransportInformation, and the Object Browser will point you to Windows.Web.Http.HttpRequestMessage.

In which package can I find Xamarin IDevice

I am writing a Xamarin Forms PCL application (both iOS and Android)
I have to pick an image from phone gallery.
I have read some documentation about this plugin:
Labs.Platform.Services.Media.MediaPicker
In my Common project, i have to put this code:
var device = Resolver.Resolve<IDevice>();
picker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
But I have an error on the first line: IDevice and Resolver Objects are not know. I think I am missing a reference or a using clause.
Thanks
You need to install the following Nuget package in all of your projects in the solution (i.e. PCL core project, iOS project, and the Android Project, and UWP project if using it):
https://www.nuget.org/packages/XLabs.Forms/
And you will need to add the following using statements:
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;

Accessing resources XML from another library project in Xamarin.Android

I am trying to create a Xamarin.Android Component to send to the Xamarin Component Store, and I need to bundle my Colors.xml with it, so it is accessible to everyone using my component. I am setting the build action for the Colors.xml tp "AndroidResource".
So I created an Android sample application, when I add a reference to my library project's dll, I am able to use the colors defined, my project compiles and it runs, but I get no intellisense on Xamarin Studio. So that would be a bad thing for anyone using my library, as they would not be able to even see that the colors are available to use. You can see in this picture the colors defined are not available in the suggestions box.
If I add the Colors.xml directly into my project, I get Intellisense support, like this:
Is there a way to achieve the same result above when adding just the dll reference? Did I do something wrong or Xamarin.Android/Xamarin Studio doesn't support this kind of scenario?
EDIT: To be clear, I know this is a problem with Intellisense not being able to pick up the values, but is there anything I can do to make it work?

Xamarin - Read Assets from Shared Project

I am using Xamarin for Android / iOS development. I have added a Shared Project within Xamarin solution. One of the functionality in the Shared project would be read assets within Android. However, AssetManager or Assets is not available from the Shared project. Any clue on how this can be used?
Maybe a bit late - hope it still helps somebody.
You can use
https://github.com/juergenkoller/PCLStorage
It has a GetFileFromAppBundleAsync function. You can place your file inside the asset folder of your Android project and do something like this:
var file = await FileSystem.Current.GetFileFromAppBundleAsync("your file.xyz", new CancellationToken(false));
var content = await file.ReadAllTextAsync ();

Console app template missing

I want to test out XMLReader but I just want the output to be simple like the console app template, but this seems to be missing from Visual Studio express for windows mobile.
Is there a way to test things simply just to see if my code is working.
Can you create class libraries? If so, use NUnit and write your test code in a unit test method body.
Im a little late to the party but in VS you need create as Console App when first creating website. You cant create a console app after you've created the website

Resources