i have a xamarin.form project and try to add unit test, nut having an issue which made me crazy,
this is my viewmodel
public class ClientsViewModel : XamarinViewModel
{
private readonly IClientAppService _clientAppService;
...
}
in my test class when I reach to second line it throw null refrence error,
_mockClientAppService = new Mock<IClientAppService>();
var viewModel = new ClientsViewModel(_mockClientAppService.Object);
this is my XamarinViewModel constructor
protected XamarinViewModel()
{
NavigationService = DependencyResolver.Resolve<INavigationService>();
LoginInfoSaveService = DependencyResolver.Resolve<ILoginInfoSaveService>();
ObjectMapper = NullObjectMapper.Instance;
}
the exact error happens on DependencyResolver.Resolve, which throw null refrenc because ApplicationBootstrapper is null
public static class DependencyResolver
{
public static IIocManager IocManager => ApplicationBootstrapper.AbpBootstrapper.IocManager;
public static T Resolve<T>()
{
return ApplicationBootstrapper.AbpBootstrapper.IocManager.Resolve<T>();
}
...
}
Message:
Initialization method WGMobileUnitTest.Client.ClientsViewModelTests.Setup threw exception. System.NullReferenceException: Object reference not set to an instance of an object..
Stack Trace:
DependencyResolver.ResolveT line 12
ClientsViewModelTests.Setup() line 43