From a0bd3bbb7c6b3991cab230c483d28359c5538960 Mon Sep 17 00:00:00 2001 From: Israel Soto Date: Thu, 8 Sep 2022 16:08:59 -0500 Subject: [PATCH] [DeviceDiscoveryUI] Added Unit tests --- .../DDDevicePickerViewControllerTest.cs | 86 +++++++++++++++++++ tests/monotouch-test/Info.plist | 17 ++++ 2 files changed, 103 insertions(+) create mode 100644 tests/monotouch-test/DeviceDiscoveryUI/DDDevicePickerViewControllerTest.cs diff --git a/tests/monotouch-test/DeviceDiscoveryUI/DDDevicePickerViewControllerTest.cs b/tests/monotouch-test/DeviceDiscoveryUI/DDDevicePickerViewControllerTest.cs new file mode 100644 index 000000000000..d1307e9dca13 --- /dev/null +++ b/tests/monotouch-test/DeviceDiscoveryUI/DDDevicePickerViewControllerTest.cs @@ -0,0 +1,86 @@ +// +// Unit tests for DDDevicePickerViewController +// +// Authors: +// Israel Soto +// +// Copyright 2022 Microsoft Corporation. +// + +#if __TVOS__ + +using System; +using Foundation; +using CoreGraphics; +using EventKit; +using ObjCRuntime; +using NUnit.Framework; +using Xamarin.Utils; + +namespace MonoTouchFixtures.DeviceDiscoveryUI { + + [TestFixture] + [Preserve (AllMembers = true)] + public class DDDevicePickerViewControllerTest { + + const string serviceName = "MyAppService"; + + [OneTimeSetUp] + public void Init () => TestRuntime.AssertXcodeVersion (14, 0); + + [Test] + public void IsSupportedTest () + { + var browserDescriptor = NWBrowserDescriptor.CreateApplicationServiceName (serviceName); + var parameters = NWParameters.CreateApplicationService (); + var isSupported = DDDevicePickerViewController.IsSupported (browserDescriptor, parameters); + + // DDDevicePickerViewController seems to work only for devices + if (TestRuntime.IsSimulator) + Assert.IsFalse (isSupported, "IsSupported"); + else + Assert.IsTrue (isSupported, "IsSupported"); + } + + [Test] + public void InitWithBrowseDescriptorAndParametersTest () + { + // DDDevicePickerViewController seems to work only for devices + TestRuntime.AssertNotSimulator (); + + var browserDescriptor = NWBrowserDescriptor.CreateApplicationServiceName (serviceName); + var parameters = NWParameters.CreateApplicationService (); + var isSupported = DDDevicePickerViewController.IsSupported (browserDescriptor, parameters); + + // If this fails, please, double check that MyAppService is registered within the Info.plist + // https://developer.apple.com/documentation/bundleresources/information_property_list/nsapplicationservices + Assert.IsTrue (isSupported, $"The {serviceName} key might not be registered in the Info.plist."); + + Assert.DoesNotThrow (() => { var devicePicker = new DDDevicePickerViewController (browserDescriptor, parameters); }, + "InitWithBrowseDescriptorAndParameters"); + } + + [Test] + public void SetDevicePickerTest () + { + // DDDevicePickerViewController seems to work only for devices + TestRuntime.AssertNotSimulator (); + + var browserDescriptor = NWBrowserDescriptor.CreateApplicationServiceName (serviceName); + var parameters = NWParameters.CreateApplicationService (); + var isSupported = DDDevicePickerViewController.IsSupported (browserDescriptor, parameters); + + // If this fails, please, double check that MyAppService is registered within the Info.plist + // https://developer.apple.com/documentation/bundleresources/information_property_list/nsapplicationservices + Assert.IsTrue (isSupported, $"The {serviceName} key might not be registered in the Info.plist."); + + Assert.DoesNotThrow (() => { + var devicePicker = new DDDevicePickerViewController (browserDescriptor, parameters); + devicePicker.SetDevicePicker ((endpoint, error) => { }); + }, + "SetDevicePicker"); + } + } +} + +#endif // __TVOS__ diff --git a/tests/monotouch-test/Info.plist b/tests/monotouch-test/Info.plist index 10d4a54ba822..b17fc1fafbbc 100644 --- a/tests/monotouch-test/Info.plist +++ b/tests/monotouch-test/Info.plist @@ -62,5 +62,22 @@ processing + NSApplicationServices + + Browses + + + NSApplicationServiceIdentifier + MyAppService + NSApplicationServicePlatformSupport + + iPadOS + iOS + + NSApplicationServiceUsageDescription + You can control this app using an iOS device. + + +