Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Flow.Launcher.Core/Flow.Launcher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
<PackageReference Include="squirrel.windows" Version="1.5.2" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
Copy link
Member

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

Copy link
Member Author

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.

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
Expand Down
3 changes: 3 additions & 0 deletions Flow.Launcher.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Flow.Launcher.Test")]
6 changes: 3 additions & 3 deletions Flow.Launcher.Test/Flow.Launcher.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@

<ItemGroup>
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>

</Project>
105 changes: 105 additions & 0 deletions Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs
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);
}
}

}
}