using System;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[TestFixture]
public class HRTests
{
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
Xamarin.Forms.Internals.Registrar.RegisterAll(new Type[0]);
Application.Current = null;
}
[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
XamlLoader.FallbackTypeResolver = null;
XamlLoader.ValueCreatedCallback = null;
XamlLoader.InstantiationFailedCallback = null;
Forms.Internals.ResourceLoader.ExceptionHandler2 = null;
#pragma warning disable 0618
Internals.XamlLoader.DoNotThrowOnExceptions = false;
#pragma warning restore 0618
Application.ClearCurrent();
}
[Test]
public void LoadResources()
{
var app = @"
HotPink
";
Assert.That(Application.Current, Is.Null);
var mockApplication = new MockApplication();
var rd = XamlLoader.LoadResources(app, mockApplication);
Assert.That(rd, Is.TypeOf());
Assert.That(((ResourceDictionary)rd).Count, Is.EqualTo(1));
//check that the live app hasn't ben modified
Assert.That(Application.Current, Is.EqualTo(mockApplication));
Assert.That(Application.Current.Resources.Count, Is.EqualTo(0));
}
[Test]
public void LoadMultipleResources()
{
var app = @"
HotPink
Chartreuse
";
Assert.That(Application.Current, Is.Null);
var mockApplication = new MockApplication();
var rd = XamlLoader.LoadResources(app, mockApplication);
Assert.That(rd, Is.TypeOf());
Assert.That(((ResourceDictionary)rd).Count, Is.EqualTo(2));
//check that the live app hasn't ben modified
Assert.That(Application.Current, Is.EqualTo(mockApplication));
Assert.That(Application.Current.Resources.Count, Is.EqualTo(0));
}
[Test]
public void LoadSingleImplicitResources()
{
var app = @"
HotPink
";
Assert.That(Application.Current, Is.Null);
var mockApplication = new MockApplication();
var rd = XamlLoader.LoadResources(app, mockApplication);
Assert.That(rd, Is.TypeOf());
Assert.That(((ResourceDictionary)rd).Count, Is.EqualTo(1));
//check that the live app hasn't ben modified
Assert.That(Application.Current, Is.EqualTo(mockApplication));
Assert.That(Application.Current.Resources.Count, Is.EqualTo(0));
}
}
}