Flow.Launcher/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs

66 lines
3 KiB
C#
Raw Permalink Normal View History

using NUnit.Framework;
using NUnit.Framework.Legacy;
2021-07-03 12:31:26 +00:00
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Plugin;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
using System.Text;
using System.Collections.Generic;
namespace Flow.Launcher.Test.Plugins
{
[TestFixture]
// ReSharper disable once InconsistentNaming
2022-09-01 02:37:29 +00:00
internal class JsonRPCPluginTest : JsonRPCPlugin
2021-07-03 12:31:26 +00:00
{
2021-08-13 05:55:07 +00:00
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
2021-07-03 12:31:26 +00:00
{
throw new System.NotImplementedException();
}
2021-08-13 05:55:07 +00:00
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
2021-07-03 12:31:26 +00:00
{
2021-08-13 05:55:07 +00:00
var byteInfo = Encoding.UTF8.GetBytes(request.Parameters[0] as string ?? string.Empty);
2021-07-03 12:31:26 +00:00
var resultStream = new MemoryStream(byteInfo);
return Task.FromResult((Stream)resultStream);
}
[TestCase("{\"result\":[],\"DebugMessage\":null}", Description = "Empty Result")]
2021-07-05 14:24:51 +00:00
[TestCase("{\"result\":[{\"JsonRPCAction\":null,\"Title\":\"something\",\"SubTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null}],\"DebugMessage\":null}", Description = "One Result with Pascal Case")]
[TestCase("{\"result\":[{\"jsonRPCAction\":null,\"title\":\"something\",\"subTitle\":\"\",\"actionKeywordAssigned\":null,\"icoPath\":null}],\"debugMessage\":null}", Description = "One Result with camel Case")]
[TestCase("{\"result\":[{\"JsonRPCAction\":null,\"Title\":\"iii\",\"SubTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null},{\"JsonRPCAction\":null,\"Title\":\"iii\",\"SubTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null}],\"DebugMessage\":null}", Description = "Two Result with Pascal Case")]
[TestCase("{\"result\":[{\"jsonrpcAction\":null,\"TItLE\":\"iii\",\"Subtitle\":\"\",\"Actionkeywordassigned\":null,\"icoPath\":null},{\"jsonRPCAction\":null,\"tiTle\":\"iii\",\"subTitle\":\"\",\"ActionKeywordAssigned\":null,\"IcoPath\":null}],\"DebugMessage\":null}", Description = "Two Result with Weird Case")]
2021-07-07 04:40:17 +00:00
public async Task GivenVariousJsonText_WhenVariousNamingCase_ThenExpectNotNullResults_Async(string resultText)
2021-07-03 12:31:26 +00:00
{
var results = await QueryAsync(new Query
{
2021-08-13 05:55:07 +00:00
Search = resultText
2021-07-03 12:31:26 +00:00
}, default);
ClassicAssert.IsNotNull(results);
2021-07-03 12:31:26 +00:00
foreach (var result in results)
{
ClassicAssert.IsNotNull(result);
ClassicAssert.IsNotNull(result.AsyncAction);
ClassicAssert.IsNotNull(result.Title);
2021-07-03 12:31:26 +00:00
}
}
public static List<JsonRPCQueryResponseModel> ResponseModelsSource = new()
{
2022-09-01 02:34:47 +00:00
new JsonRPCQueryResponseModel(0, new List<JsonRPCResult>()),
new JsonRPCQueryResponseModel(0, new List<JsonRPCResult>
2021-07-03 12:31:26 +00:00
{
new()
2021-07-03 12:31:26 +00:00
{
2022-09-01 02:34:47 +00:00
Title = "Test1", SubTitle = "Test2"
2021-07-03 12:31:26 +00:00
}
2022-09-01 02:34:47 +00:00
})
2021-07-03 12:31:26 +00:00
};
}
2022-09-01 02:34:47 +00:00
}