How can I test methods containing Application.Current

Shiva799Shiva799 Member ✭✭

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);

Best Answer

Answers

  • Shiva799Shiva799 Member ✭✭

    I need this so as to increase code coverage.

  • NMackayNMackay GBInsider, University mod

    Code coverage is often misunderstood...90% code coverage means nothing if your having to fudge your tests to get there because your having to touch UI stuff. Fairly common dilemma these days.

  • Shiva799Shiva799 Member ✭✭

    Yes but thats a requirement here :s

Sign In or Register to comment.