| | 1 | | using System.Collections; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEngine.TestTools; |
| | 4 | |
|
| | 5 | | public class ClipboardTests |
| | 6 | | { |
| | 7 | | [UnityTest] |
| | 8 | | public IEnumerator ReadClipboardPromiseShouldBehaveCorrectly() |
| | 9 | | { |
| 1 | 10 | | ClipboardHandler_Mock mockClipboardHandler = new ClipboardHandler_Mock(); |
| 1 | 11 | | Clipboard clipboard = new Clipboard(mockClipboardHandler); |
| | 12 | |
|
| | 13 | | const string firstText = "sometext"; |
| 1 | 14 | | mockClipboardHandler.MockReadTextRequestResult(0.5f, firstText, false); |
| | 15 | |
|
| 1 | 16 | | var promise = clipboard.ReadText(); |
| 1 | 17 | | promise.Then(value => |
| | 18 | | { |
| 1 | 19 | | Assert.IsNull(promise.error); |
| 1 | 20 | | Assert.IsNotNull(promise.value); |
| 1 | 21 | | Assert.IsTrue(value == firstText); |
| 1 | 22 | | }) |
| | 23 | | .Catch(error => |
| | 24 | | { |
| 0 | 25 | | Assert.Fail("it shouldn't call this"); |
| 0 | 26 | | }); |
| 1 | 27 | | yield return promise; |
| | 28 | |
|
| 1 | 29 | | Assert.IsNull(promise.error); |
| 1 | 30 | | Assert.IsNotNull(promise.value); |
| 1 | 31 | | Assert.IsTrue(promise.value == firstText); |
| | 32 | |
|
| | 33 | | const string errorText = "errortext"; |
| 1 | 34 | | mockClipboardHandler.MockReadTextRequestResult(0, errorText, true); |
| | 35 | |
|
| 1 | 36 | | promise = clipboard.ReadText(); |
| 1 | 37 | | promise.Then(value => |
| | 38 | | { |
| 0 | 39 | | Assert.Fail("it shouldn't call this"); |
| 0 | 40 | | }) |
| | 41 | | .Catch(error => |
| | 42 | | { |
| 1 | 43 | | Assert.IsNull(promise.value); |
| 1 | 44 | | Assert.IsNotNull(promise.error); |
| 1 | 45 | | Assert.IsTrue(error == errorText); |
| 1 | 46 | | }); |
| | 47 | |
|
| 1 | 48 | | Assert.IsNull(promise.value); |
| 1 | 49 | | Assert.IsNotNull(promise.error); |
| 1 | 50 | | Assert.IsTrue(promise.error == errorText); |
| 1 | 51 | | } |
| | 52 | | } |