Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How can I test methods containing Application.Current

$
0
0

There are few methods which have Application.Current.Properties and Application.Current.SavePropertiesAsync methods. So how do i test methods having these two in them? I'm stuck after trying to use Unity container for them but its only working for Properties not SavePropertiesAsync. how can i implement it? How i have implemented it is:

public interface IAppProperties { IDictionary<string, object> Properties { get; set; } }
`public class AppProperty:IAppProperties
{
public const string AppPropertiesName = "AppProperties";

    public IDictionary<string, object> Properties { get; set; }

    public AppProperty(IDictionary<string, object> appProperties)
    {
        Properties = appProperties;
    }
}`

In App xaml.cs
UnityContainer container = new UnityContainer(); if (!IsUnitTestCase) { container.RegisterInstance<IDictionary<string, object>>(AppProperty.AppPropertiesName, Application.Current.Properties); } else { container.RegisterInstance<IDictionary<string, object>>(AppProperty.AppPropertiesName, new Dictionary<string,object>()); } container.RegisterType<IAppProperties,AppProperty>(); Application.Current.Resources.Add("Unity", container);


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>