Skip to content

Commit d34ad66

Browse files
committed
initial JsonRPCPlugin Unit Test
1 parent d6ec4b5 commit d34ad66

File tree

6 files changed

+107
-9
lines changed

6 files changed

+107
-9
lines changed

Flow.Launcher.Core/Flow.Launcher.Core.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
<PackageReference Include="squirrel.windows" Version="1.5.2" />
5959
</ItemGroup>
6060

61-
<ItemGroup>
62-
<Folder Include="Properties\" />
63-
</ItemGroup>
64-
6561
<ItemGroup>
6662
<ProjectReference Include="..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
6763
<ProjectReference Include="..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Flow.Launcher")]
4+
[assembly: InternalsVisibleTo("Flow.Launcher.Test")]

Flow.Launcher.Test/Flow.Launcher.Test.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949

5050
<ItemGroup>
5151
<PackageReference Include="Moq" Version="4.14.1" />
52-
<PackageReference Include="nunit" Version="3.12.0" />
53-
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
52+
<PackageReference Include="nunit" Version="3.13.2" />
53+
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0">
5454
<PrivateAssets>all</PrivateAssets>
5555
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5656
</PackageReference>
57-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
57+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
5858
</ItemGroup>
5959

6060
</Project>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using NUnit;
2+
using NUnit.Framework;
3+
using Flow.Launcher.Core.Plugin;
4+
using Flow.Launcher.Plugin;
5+
using System.Threading.Tasks;
6+
using System.IO;
7+
using System.Threading;
8+
using System.Text;
9+
using System.Text.Json;
10+
using System.Linq;
11+
using System.Collections.Generic;
12+
13+
namespace Flow.Launcher.Test.Plugins
14+
{
15+
[TestFixture]
16+
// ReSharper disable once InconsistentNaming
17+
internal class JsonRPCPluginTest : JsonRPCPlugin
18+
{
19+
public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable;
20+
21+
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
22+
{
23+
throw new System.NotImplementedException();
24+
}
25+
26+
protected override string ExecuteContextMenu(Result selectedResult)
27+
{
28+
throw new System.NotImplementedException();
29+
}
30+
31+
protected override Task<Stream> ExecuteQueryAsync(Query query, CancellationToken token)
32+
{
33+
var byteInfo = Encoding.UTF8.GetBytes(query.RawQuery);
34+
35+
var resultStream = new MemoryStream(byteInfo);
36+
return Task.FromResult((Stream)resultStream);
37+
}
38+
39+
[TestCase("{\"result\":[],\"DebugMessage\":null}", Description = "Empty Result")]
40+
[TestCase("{\"result\":[{\"JsonRPCAction\":null,\"Title\":null,\"SubTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null}],\"DebugMessage\":null}", Description = "One Result with Pascal Case")]
41+
[TestCase("{\"result\":[{\"jsonRPCAction\":null,\"title\":null,\"subTitle\":\"\",\"actionKeywordAssigned\":null,\"icoPath\":null}],\"debugMessage\":null}", Description = "One Result with camel Case")]
42+
[TestCase("{\"result\":[{\"JsonRPCAction\":null,\"Title\":null,\"SubTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null},{\"JsonRPCAction\":null,\"Title\":null,\"SubTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null}],\"DebugMessage\":null}", Description = "Two Result with Pascal Case")]
43+
public async Task BasicQueryTestAsync(string resultText)
44+
{
45+
var results = await QueryAsync(new Query
46+
{
47+
RawQuery = resultText
48+
}, default);
49+
50+
Assert.IsNotNull(results);
51+
52+
foreach (var result in results)
53+
{
54+
Assert.IsNotNull(result);
55+
Assert.IsNotNull(result.Action);
56+
}
57+
58+
}
59+
60+
public static List<JsonRPCQueryResponseModel> ResponseModelsSource = new()
61+
{
62+
new()
63+
{
64+
Result = new()
65+
},
66+
new()
67+
{
68+
Result = new()
69+
{
70+
new JsonRPCResult
71+
{
72+
Title = "Test1",
73+
SubTitle = "Test2"
74+
}
75+
}
76+
}
77+
};
78+
79+
[TestCaseSource(typeof(JsonRPCPluginTest), nameof(ResponseModelsSource))]
80+
public async Task QueryTestPropertyMatchAsync(JsonRPCQueryResponseModel model)
81+
{
82+
var pascalText = JsonSerializer.Serialize(model);
83+
84+
var results = await QueryAsync(new Query { RawQuery = pascalText, }, default);
85+
86+
Assert.IsNotNull(results);
87+
88+
foreach (var (result1, result2) in results.Zip(model.Result))
89+
{
90+
Assert.IsNotNull(result1);
91+
Assert.IsNotNull(result1.Action);
92+
Assert.AreEqual(result1.Title, result2.Title);
93+
Assert.AreEqual(result1.SubTitle, result2.SubTitle);
94+
}
95+
}
96+
97+
}
98+
}

Flow.Launcher.Test/Plugins/PluginInitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PluginInitTest
1111
[Test]
1212
public void PublicAPIIsNullTest()
1313
{
14-
//Assert.Throws(typeof(Flow.LauncherFatalException), () => PluginManager.Initialize(null));
14+
//Ap[ssert.Throws(typeof(Flow.LauncherFatalException), () => PluginManager.Initialize(null));
1515
}
1616
}
1717
}

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "5.0.100",
3+
"version": "5.0.300",
44
"rollForward": "latestFeature"
55
}
66
}

0 commit comments

Comments
 (0)