Closed fcogutierrez closed 8 years ago
You would just need to implement a different version of ISettings and then return it when you want to use that mock.
@jamesmontemagno, thanks but...how can I set my ISettings implementation instead of using CrossSettings.Current?
private static ISettings SettingsRepository
{
get { return CrossSettings.Current; }
}
Simply implement it in a new class and then return it?
Yes, but how can I replace the CrossSettings.Current by my implementation?
private static ISettings SettingsRepository
{
get { return new YourImplementation(); }
}
Ok @jamesmontemagno , so I have my AppSettings class and my AppSettingsMock class:
However, in my ViewModel (subject under test) I am doing:
//some operations...
Email = AppSettings.Email;
Password = AppSettings.Password;
//more operations...
And my question is...how can I use my AppSettingsMock instead of the AppSettings class in my test?
Thank you a lot for your help mr James :-) :+1: :+1:
@fcogutierrez I believe you need to setup a form of iOC. For example in MVVMCross you could do this:
public static string Email
{
get {
var settingsSvc = Mvx.Resolve<ISettingsService>();
return settingsSvc.GetValueOrDefault<string>(EmailKey, string.Empty);
}
set {
var settingsSvc = Mvx.Resolve<ISettingsService>();
settingsSvc .AddOrUpdateValue<string>(EmailKey, value);
}
}
Which plugin does this impact:
Question:
How can I mock my static AppSettings class in my Unit tests?
I am doing this:
Thanks a lot.