Reputation: 11
I am using BaseViewModel to check Internet Connectivity and it is acting as a base class. other view models are extracting that BaseViewModel.
When I am trying to mocking the BaseViewModel it gives the above error ( mentioned in title ).
BaseViewModel.cs
public partial class BaseViewModel : ObservableObject
{
[ObservableProperty]
private bool _internetConnected = true;
public BaseViewModel()
{
if(Connectivity.NetworkAccess != NetworkAccess.Internet)
{
InternetConnected = false;
}
Connectivity.ConnectivityChanged += ConnectivityHandler;
}
public void ConnectivityHandler(object sender, ConnectivityChangedEventArgs e)
{
if (Connectivity.NetworkAccess == NetworkAccess.Internet)
{
InternetConnected = true;
}
else
{
InternetConnected = false;
}
}
}
I am facing error when it is executing constructor.
I am attaching the screenshot of error.
I tried mocking the base class constructor and also tried to skip a base class constructor call. It didn't work.
Any help would be greatly appreciated.
Upvotes: 0
Views: 230
Reputation: 1
Is this for windows desktop development?, if so I would suggest to letting go of MAUI as it is great for multi-platform development, but not so much if you are just doing Windows desktop development. If it is for Windows development, then I would suggest you go with WPF for my development effort dollar (a WPF .net 8 core project); if you are into that multi-platform and WPF is not good enough, then I would suggest using an Avalonia project for multiple platform development efforts and then having one project created just for my windows development and having something like AvaloniaDialogs for all the basics on how to display the dialogs on your windows as message boxes, and Avalonia.ReactiveUI and System.Reactive for my observable objects (and/or observable as properties). Also for interactions and other windows specific classes, I needed to use Mvvm.CommonInteractions.Avalonia which has some basic services and common interactions that get set at the startup builder (services) setup. If you are stuck with MAUI, I know you have to specify the type of executable's framework and/or platform on the project's file. But I did come here because I had the same issue that you were having, someone said "Use Avalonia.Essentials" which became "Maui.Essentials" and that is how I got into the issue you are having, you can add Reactive to either one of those projects. Hope this helps a bit. Good luck.
Upvotes: 0