-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNowPlayingPluginTest.cs
93 lines (88 loc) · 3.35 KB
/
NowPlayingPluginTest.cs
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
using System;
using System.IO.Pipes;
using System.IO;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Threading;
using System.Linq;
using System.Reflection;
using NowPlayingCore.NowPlaying;
using Xunit;
namespace NowPlayingV2UTest
{
public class NowPlayingPluginTest
{
[Trait("Category", "PluginTest")]
[Fact]
public void GetJsonTest()
{
var stream = new NamedPipeServerStream("NowPlayingTunesV2PIPE");
var memstream = new MemoryStream();
stream.WaitForConnection();
int readret = -1;
while (readret != 0)
{
var buffer = new byte[1024];
readret = stream.Read(buffer, 0, buffer.Length);
memstream.Write(buffer, 0, readret);
}
stream.Close();
var bary = memstream.ToArray();
var rawjson = System.Text.Encoding.UTF8.GetString(bary);
//Console.WriteLine(rawjson);
dynamic json = JsonConvert.DeserializeObject(rawjson);
foreach (JProperty kvp in (json as IEnumerable<object>))
{
if (kvp.Name != "albumart") Console.WriteLine($"{kvp.Name}:{kvp.Value}");
}
}
[Trait("Category", "PluginTest")]
[Fact]
public void TestEventListener()
{
var waitHandle = new ManualResetEvent(false);
PipeListener.MkStaticInstance();
PipeListener.StaticPipeListener.OnMusicPlay += (songinfo) =>
{
Assert.NotNull(songinfo.Album);
Assert.NotNull(songinfo.AlbumArtBase64);
Assert.NotNull(songinfo.AlbumArtist);
Assert.NotNull(songinfo.Title);
Assert.NotNull(songinfo.TrackCount);
Assert.NotNull(songinfo.Year);
Assert.NotNull(songinfo.Composer);
songinfo.GetType().GetProperties().ToList().ForEach(itm =>
{
if (itm.GetValue(songinfo) is string str && itm.Name != "AlbumArtBase64")
Console.WriteLine($"{itm.Name} : {str}");
});
waitHandle.Set();
};
waitHandle.WaitOne(Timeout.Infinite);
PipeListener.StaticPipeListener.StopPipeListener();
}
[Trait("Category", "PluginTest")]
[Fact]
public void TestImageDecoder()
{
var waitHandle = new ManualResetEvent(false);
PipeListener.MkStaticInstance();
PipeListener.StaticPipeListener.OnMusicPlay += (songinfo) =>
{
if (songinfo.IsAlbumArtAvaliable())
{
Console.WriteLine($"Image Width : {songinfo.GetAlbumArt().Width}");
Console.WriteLine($"Image Height : {songinfo.GetAlbumArt().Height}");
}
Assert.True(songinfo.AlbumArtBase64.Length == 0 || songinfo.IsAlbumArtAvaliable());
songinfo.GetType().GetProperties().ToList()
.ForEach(itm => Console.WriteLine($"{itm.Name} : {itm.GetValue(songinfo)}"));
waitHandle.Set();
};
waitHandle.WaitOne(Timeout.Infinite);
PipeListener.StaticPipeListener.StopPipeListener();
}
}
}