Can I use Xamarin.Forms.DependencyService in Visual Studio Unit Test (class library) project?
Date : March 29 2020, 07:55 AM
it should still fix some issue You have to assign a class that implements IPlatformServices to Device.PlatformServices static property. Now, that is tricky because both IPlatformServices interface and Device.PlatformServices are internal. But it is doable. Name your unittest assembly as "Xamarin.Forms.Core.UnitTests" because internals are visible to assembly named like that (among few other names). public class PlatformServicesMock: IPlatformServices
{
void IPlatformServices.BeginInvokeOnMainThread(Action action)
{
throw new NotImplementedException();
}
ITimer IPlatformServices.CreateTimer(Action<object> callback)
{
throw new NotImplementedException();
}
ITimer IPlatformServices.CreateTimer(Action<object> callback, object state, int dueTime, int period)
{
throw new NotImplementedException();
}
ITimer IPlatformServices.CreateTimer(Action<object> callback, object state, long dueTime, long period)
{
throw new NotImplementedException();
}
ITimer IPlatformServices.CreateTimer(Action<object> callback, object state, TimeSpan dueTime, TimeSpan period)
{
throw new NotImplementedException();
}
ITimer IPlatformServices.CreateTimer(Action<object> callback, object state, uint dueTime, uint period)
{
throw new NotImplementedException();
}
Assembly[] IPlatformServices.GetAssemblies()
{
return new Assembly[0];
}
Task<Stream> IPlatformServices.GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
IIsolatedStorageFile IPlatformServices.GetUserStoreForApplication()
{
throw new NotImplementedException();
}
void IPlatformServices.OpenUriAction(Uri uri)
{
throw new NotImplementedException();
}
void IPlatformServices.StartTimer(TimeSpan interval, Func<bool> callback)
{
throw new NotImplementedException();
}
bool IPlatformServices.IsInvokeRequired
{
get
{
throw new NotImplementedException();
}
}
}
var platformServicesProperty = typeof(Device).GetProperty("PlatformServices", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
platformServicesProperty.SetValue(null, new PlatformServicesMock());
|
Unit Test Passes, Project Crashes, the Unit Test Fails
Tag : chash , By : Jesenko Mehmedbasic
Date : March 29 2020, 07:55 AM
I hope this helps you . By default, you're limited on the number of ExeucteMultipleRequests you are running to 2, so the first step is to ensure that you aren't doing more than that. Another thing to try is to make sure that you're not multi-threading your connections to CRM. By default, .Net only allows 2 http Requests per app. This is controlled by a configuration setting.
|
In Visual Studio native unit test, is it possible to couple unit test to a project?
Date : March 29 2020, 07:55 AM
help you fix your problem Contrary to the accepted answer, I'd say to definitely put your test code into a separate project. Whether you create a single or multiple test projects is a matter of opinion, but there are good reasons to not put your test code into your release code. The main reason is that you don't want to link unit test libraries into release code. That's simply unacceptable in my book and as far as I know Visual Studio has a clear "1 project = 1 library" approach so I don't see how you'd avoid that.
|
Rebuild fails after adding reference in Unit Test App Nunit Lite Xamarin to Xamarin Service
Date : March 29 2020, 07:55 AM
hop of those help? For me the solution was: NameOfTheProject -> Properties -> AndroidOptions -> Linking: None
|
Error when adding SQL Server Unit Test item to a Unit Test Project in visual studio 2017
Date : March 29 2020, 07:55 AM
|