// // Unit tests for PKPassLibrary // // Authors: // Sebastien Pouliot // // Copyright 2012 Xamarin Inc. All rights reserved. // #if !__TVOS__ using System; #if XAMCORE_2_0 using Foundation; using UIKit; using PassKit; #else using MonoTouch.Foundation; using MonoTouch.PassKit; using MonoTouch.UIKit; #endif using NUnit.Framework; namespace MonoTouchFixtures.PassKit { [TestFixture] [Preserve (AllMembers = true)] public class PassLibraryTest { [Test] public void Defaults () { if (!TestRuntime.CheckSystemAndSDKVersion (6,0)) Assert.Inconclusive ("PassKit is new in 6.0"); // this is yet another case where Apples plays ping-ping with different versions // // newsflash: iOS 8.1 says it's available but won't let you create a PKPassLibrary instance #24747 // but iOS 8.2 (first beta) on an iPad let's you do it // and final iOS 8.2 does not seems to return true anymore #28711 while 8.3 beta works !?! if (!PKPassLibrary.IsAvailable) Assert.Inconclusive ("PassKit is not available"); var library = new PKPassLibrary (); // not null (but empty by default) and there's no API to add them Assert.NotNull (library.GetPasses (), "GetPasses"); // and we can't trick the OS to do it for us using (NSUrl url = new NSUrl (NSBundle.MainBundle.BundleUrl + "/BoardingPass.pkpass")) { #if !__WATCHOS__ Assert.False (UIApplication.SharedApplication.OpenUrl (url), "OpenUrl"); #endif } Assert.Null (library.GetPass (String.Empty, String.Empty), "GetPass"); using (var pass = PassTest.GetBoardingPass ()) { Assert.False (library.Contains (pass), "Contains"); Assert.False (library.Replace (pass), "Replace"); library.Remove (pass); } } [Test] public void Fields () { if (!TestRuntime.CheckSystemAndSDKVersion (6,0)) Assert.Inconclusive ("PassKit is new in 6.0"); Assert.That (PKPassLibraryUserInfoKey.AddedPasses.ToString (), Is.EqualTo ("PKPassLibraryAddedPassesUserInfo"), "AddedPassesUserInfoKey"); Assert.That (PKPassLibraryUserInfoKey.RemovedPassInfos.ToString (), Is.EqualTo ("PKPassLibraryRemovedPassInfosUserInfo"), "RemovedPassInfosUserInfoKey"); Assert.That (PKPassLibraryUserInfoKey.ReplacementPasses.ToString (), Is.EqualTo ("PKPassLibraryReplacementPassesUserInfo"), "ReplacementPassesUserInfoKey"); Assert.That (PKPassLibrary.DidChangeNotification.ToString (), Is.EqualTo ("PKPassLibraryDidChangeNotification"), "DidChangeNotification"); Assert.That (PKPassLibraryUserInfoKey.PassTypeIdentifier.ToString (), Is.EqualTo ("PKPassLibraryPassTypeIdentifierUserInfo"), "PassTypeIdentifierUserInfoKey"); Assert.That (PKPassLibraryUserInfoKey.SerialNumber.ToString (), Is.EqualTo ("PKPassLibrarySerialNumberUserInfo"), "SerialNumberUserInfoKey"); } } } #endif // !__TVOS__