-
-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathDialogTests.cs
More file actions
142 lines (118 loc) · 5.11 KB
/
DialogTests.cs
File metadata and controls
142 lines (118 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Threading.Tasks;
using NUnit.Framework;
namespace LibVLCSharp.Tests
{
[TestFixture]
public class DialogTests : BaseSetup
{
const string UrlRequireAuth = "http://httpbin.org/basic-auth/user/passwd";
const string Username = "username";
const string Password = "password";
[Test]
[Retry(3)]
[Ignore("requires network calls that may fail when run from CI")]
public async Task PostLogin()
{
var tcs = new TaskCompletionSource<bool>();
_libVLC.SetDialogHandlers((dialog, title, text, username, store, token) =>
{
// show UI dialog
// On "OK" call PostLogin
dialog.PostLogin(Username, Password, false);
tcs.TrySetResult(true);
return Task.CompletedTask;
},
(dialog, title, text, type, cancelText, actionText, secondActionText, token) => Task.CompletedTask,
(dialog, title, text, indeterminate, position, cancelText, token) => Task.CompletedTask,
(dialog, position, text) => Task.CompletedTask);
var mp = new MediaPlayer(_libVLC)
{
Media = new Media(UrlRequireAuth, FromType.FromLocation)
};
mp.Play();
await tcs.Task;
Assert.True(tcs.Task.Result);
}
[Test]
[Retry(3)]
[Ignore("requires network calls that may fail when run from CI")]
public async Task ShouldThrowIfPostLoginsTwice()
{
var tcs = new TaskCompletionSource<bool>();
_libVLC.SetDialogHandlers((dialog, title, text, username, store, token) =>
{
dialog.PostLogin(Username, Password, false);
Assert.Throws<VLCException>(() => dialog.PostLogin(Username, Password, false), "Calling method on dismissed Dialog instance");
tcs.TrySetResult(true);
return Task.CompletedTask;
},
(dialog, title, text, type, cancelText, actionText, secondActionText, token) => Task.CompletedTask,
(dialog, title, text, indeterminate, position, cancelText, token) => Task.CompletedTask,
(dialog, position, text) => Task.CompletedTask);
var mp = new MediaPlayer(_libVLC)
{
Media = new Media(UrlRequireAuth, FromType.FromLocation)
};
mp.Play();
await tcs.Task;
Assert.True(tcs.Task.Result);
}
[Test]
[Retry(3)]
[Ignore("requires network calls that may fail when run from CI")]
public async Task ShouldNotThrowAndReturnFalseIfDimissingTwice()
{
var tcs = new TaskCompletionSource<bool>();
_libVLC.SetDialogHandlers((dialog, title, text, username, store, token) =>
{
var result = dialog.Dismiss();
Assert.IsTrue(result);
result = dialog.Dismiss();
Assert.IsFalse(result);
tcs.TrySetResult(true);
return Task.CompletedTask;
},
(dialog, title, text, type, cancelText, actionText, secondActionText, token) => Task.CompletedTask,
(dialog, title, text, indeterminate, position, cancelText, token) => Task.CompletedTask,
(dialog, position, text) => Task.CompletedTask);
var mp = new MediaPlayer(_libVLC)
{
Media = new Media(UrlRequireAuth, FromType.FromLocation)
};
mp.Play();
await tcs.Task;
Assert.True(tcs.Task.Result);
}
[Test]
public void ShouldUnsetDialogHandlersWhenInstanceDisposed()
{
_libVLC.SetDialogHandlers((dialog, title, text, username, store, token) => Task.CompletedTask,
(dialog, title, text, type, cancelText, actionText, secondActionText, token) => Task.CompletedTask,
(dialog, title, text, indeterminate, position, cancelText, token) => Task.CompletedTask,
(dialog, position, text) => Task.CompletedTask);
Assert.True(_libVLC.DialogHandlersSet);
_libVLC.Dispose();
Assert.False(_libVLC.DialogHandlersSet);
}
//[Test]
//public async Task ShouldRaiseErrorCallback()
//{
// const string errorUrl = "https://zzz.mp4";
// var tcs = new TaskCompletionSource<bool>();
// _libVLC.SetErrorDialogCallback(DisplayError);
// using var media = new Media(new Uri(errorUrl));
// using var mp = new MediaPlayer(_libVLC, media);
// mp.Play();
// Task DisplayError(string title, string error)
// {
// Assert.AreEqual(title, "Your input can't be opened");
// Assert.AreEqual(error, $"VLC is unable to open the MRL '{errorUrl}/'. Check the log for details.");
// tcs.TrySetResult(true);
// return Task.CompletedTask;
// }
// await tcs.Task;
// Assert.True(tcs.Task.Result);
//}
}
}