-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeviceDiscoveryUI] Added Unit tests
- Loading branch information
Israel Soto
committed
Sep 8, 2022
1 parent
e31683e
commit a0bd3bb
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
tests/monotouch-test/DeviceDiscoveryUI/DDDevicePickerViewControllerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters