Skip to content

Commit

Permalink
[DeviceDiscoveryUI] Added Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Israel Soto committed Sep 8, 2022
1 parent e31683e commit a0bd3bb
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// Unit tests for DDDevicePickerViewController
//
// Authors:
// Israel Soto <[email protected]>
//
// 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__
17 changes: 17 additions & 0 deletions tests/monotouch-test/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,22 @@
<array>
<string>processing</string>
</array>
<key>NSApplicationServices</key>
<dict>
<key>Browses</key>
<array>
<dict>
<key>NSApplicationServiceIdentifier</key>
<string>MyAppService</string>
<key>NSApplicationServicePlatformSupport</key>
<array>
<string>iPadOS</string>
<string>iOS</string>
</array>
<key>NSApplicationServiceUsageDescription</key>
<string>You can control this app using an iOS device.</string>
</dict>
</array>
</dict>
</dict>
</plist>

0 comments on commit a0bd3bb

Please sign in to comment.