-
-
Notifications
You must be signed in to change notification settings - Fork 455
Json rpc unit test #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Json rpc unit test #562
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d34ad66
initial JsonRPCPlugin Unit Test
taooceros dd8cbbb
Merge remote-tracking branch 'upstream/dev' into JsonRPCUnitTest
taooceros 7e95cab
Merge remote-tracking branch 'upstream/dev' into JsonRPCUnitTest
taooceros a3a6e0e
Additional Test Cases
taooceros c35232a
Revert two unexpected change
taooceros 11ce7cb
rename test
taooceros 9eaa025
remove unused InternalsVisibleTo
jjw24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("Flow.Launcher.Test")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| using NUnit; | ||
| using NUnit.Framework; | ||
| using Flow.Launcher.Core.Plugin; | ||
| using Flow.Launcher.Plugin; | ||
| using System.Threading.Tasks; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Linq; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Flow.Launcher.Test.Plugins | ||
| { | ||
| [TestFixture] | ||
| // ReSharper disable once InconsistentNaming | ||
| internal class JsonRPCPluginTest : JsonRPCPlugin | ||
| { | ||
| public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable; | ||
|
|
||
| protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest) | ||
| { | ||
| throw new System.NotImplementedException(); | ||
| } | ||
|
|
||
| protected override string ExecuteContextMenu(Result selectedResult) | ||
| { | ||
| throw new System.NotImplementedException(); | ||
| } | ||
|
|
||
| protected override Task<Stream> ExecuteQueryAsync(Query query, CancellationToken token) | ||
| { | ||
| var byteInfo = Encoding.UTF8.GetBytes(query.RawQuery); | ||
|
|
||
| var resultStream = new MemoryStream(byteInfo); | ||
| return Task.FromResult((Stream)resultStream); | ||
| } | ||
|
|
||
| [TestCase("{\"result\":[],\"DebugMessage\":null}", Description = "Empty Result")] | ||
| [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")] | ||
| public async Task GivenVariousJsonText_WhenVariousNamingCase_ThenExpectNotNullResults_Async(string resultText) | ||
| { | ||
| var results = await QueryAsync(new Query | ||
| { | ||
| RawQuery = resultText | ||
| }, default); | ||
|
|
||
| Assert.IsNotNull(results); | ||
|
|
||
| foreach (var result in results) | ||
| { | ||
| Assert.IsNotNull(result); | ||
| Assert.IsNotNull(result.Action); | ||
| Assert.IsNotNull(result.Title); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static List<JsonRPCQueryResponseModel> ResponseModelsSource = new() | ||
| { | ||
| new() | ||
| { | ||
| Result = new() | ||
| }, | ||
| new() | ||
| { | ||
| Result = new() | ||
| { | ||
| new JsonRPCResult | ||
| { | ||
| Title = "Test1", | ||
| SubTitle = "Test2" | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| [TestCaseSource(typeof(JsonRPCPluginTest), nameof(ResponseModelsSource))] | ||
| public async Task GivenModel_WhenSerializeWithDifferentNamingPolicy_ThenExpectSameResult_Async(JsonRPCQueryResponseModel reference) | ||
| { | ||
| var camelText = JsonSerializer.Serialize(reference, new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); | ||
|
|
||
| var pascalText = JsonSerializer.Serialize(reference); | ||
|
|
||
| var results1 = await QueryAsync(new Query { RawQuery = camelText }, default); | ||
| var results2 = await QueryAsync(new Query { RawQuery = pascalText }, default); | ||
|
|
||
| Assert.IsNotNull(results1); | ||
| Assert.IsNotNull(results2); | ||
|
|
||
| foreach (var ((result1, result2), referenceResult) in results1.Zip(results2).Zip(reference.Result)) | ||
| { | ||
| Assert.AreEqual(result1, result2); | ||
| Assert.AreEqual(result1, referenceResult); | ||
|
|
||
| Assert.IsNotNull(result1); | ||
| Assert.IsNotNull(result1.Action); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this removal intended? we still specify compile include at line 48 of the core csproj file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check. I don't know why this is removed.