Added tests template

This commit is contained in:
Mikhail Shahovalov
2025-05-08 00:42:38 +03:00
parent 8757c60396
commit 876dcf9b24
7 changed files with 120 additions and 5 deletions

View File

@@ -0,0 +1,32 @@

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-windows</TargetFramework>
<Platforms>x64;ARM64</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="NLog" Version="5.0.4" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Community.PowerToys.Run.Plugin.YandexGPT\Community.PowerToys.Run.Plugin.YandexGPT.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64'">
<Reference Include="..\libs\x64\Wox.Plugin.dll" />
<Reference Include="..\libs\x64\PowerToys.Settings.UI.Lib.dll" />
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'ARM64'">
<Reference Include="..\libs\ARM64\Wox.Plugin.dll" />
<Reference Include="..\libs\ARM64\PowerToys.Settings.UI.Lib.dll" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,72 @@
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Community.PowerToys.Run.Plugin.YandexGPT.UnitTests;
[TestClass]
public class MainTests
{
private Main _subject = null!;
[TestInitialize]
public void TestInitialize()
{
_subject = new Main();
}
[TestMethod]
public void Query_should_calculate_the_number_of_words()
{
var results = _subject.Query(new(""),true);
Assert.AreEqual("Words: 0", results[0].Title);
results = _subject.Query(new("Hello World"), true);
Assert.AreEqual("Words: 2", results[0].Title);
}
[TestMethod]
public void Query_should_calculate_the_number_of_characters()
{
var results = _subject.Query(new(""),true);
Assert.AreEqual("Characters: 0", results[1].Title);
results = _subject.Query(new("Hello World"), true);
Assert.AreEqual("Characters: 10", results[1].Title);
}
[TestMethod]
public void LoadContextMenus_should_return_buttons_for_words_result()
{
var results = _subject.LoadContextMenus(new() { ContextData = (2, TimeSpan.FromSeconds(3)) });
Assert.AreEqual(2, results.Count);
Assert.AreEqual("Copy (Enter)", results[0].Title);
Assert.AreEqual("Copy time (Ctrl+Enter)", results[1].Title);
}
[TestMethod]
public void LoadContextMenus_should_return_button_for_characters_result()
{
var results = _subject.LoadContextMenus(new() { ContextData = 10 });
Assert.AreEqual(1, results.Count);
Assert.AreEqual("Copy (Enter)", results[0].Title);
}
[TestMethod]
public void AdditionalOptions_should_return_option_for_CountSpaces()
{
var options = _subject.AdditionalOptions;
Assert.AreEqual(1, options.Count());
Assert.AreEqual("CountSpaces", options.ElementAt(0).Key);
Assert.AreEqual(false, options.ElementAt(0).Value);
}
[TestMethod]
public void UpdateSettings_should_set_CountSpaces()
{
_subject.UpdateSettings(new() { AdditionalOptions = [new() { Key = "Token", Value = true }] });
var results = _subject.Query(new("Hello World"), true);
Assert.AreEqual("Characters: 11", results[1].Title);
}
}

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net9.0-windows</TargetFramework>
<Platforms>x64;ARM64</Platforms> <Platforms>x64;ARM64</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget> <PlatformTarget>$(Platform)</PlatformTarget>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>

View File

@@ -7,7 +7,7 @@ using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.YandexGPT; namespace Community.PowerToys.Run.Plugin.YandexGPT;
public class Main : IPlugin, IContextMenu, ISettingProvider, IDisposable public class Main : IDelayedExecutionPlugin, IContextMenu, ISettingProvider, IDisposable
{ {
#region Plugin Info #region Plugin Info
public static string PluginId => "C2218AB0D86F4345B55C60F9418A811C"; public static string PluginId => "C2218AB0D86F4345B55C60F9418A811C";
@@ -40,16 +40,21 @@ public class Main : IPlugin, IContextMenu, ISettingProvider, IDisposable
//UpdateIconPath(Context.API.GetCurrentTheme()); //UpdateIconPath(Context.API.GetCurrentTheme());
} }
public List<Result> Query(Query query) public List<Result> Query(Query query, bool delayedExecution)
{ {
Log.Info("Query: " + query.Search, GetType()); Log.Info("Query: " + query.Search, GetType());
if (query.ActionKeyword != Token)
return [];
var search = query.Search;
return [ return [
new() new()
{ {
QueryTextDisplay = query.Search, QueryTextDisplay = query.Search,
IcoPath = IconPath, IcoPath = IconPath,
Title = $"YandexGPT: Чет такое", Title = $"YandexGPT: Чет такое {search}",
SubTitle = $"Ответ: иди туда!", SubTitle = $"Ответ: иди туда!",
ToolTipData = new ToolTipData("Ответы", $"Тут ответ\nИ тут ответ"), ToolTipData = new ToolTipData("Ответы", $"Тут ответ\nИ тут ответ"),
ContextData = Token, ContextData = Token,

View File

@@ -2,7 +2,7 @@
"ID": "C2218AB0D86F4345B55C60F9418A811C", "ID": "C2218AB0D86F4345B55C60F9418A811C",
"ActionKeyword": "YandexGPT", "ActionKeyword": "YandexGPT",
"IsGlobal": false, "IsGlobal": false,
"Name": "YandexGPT", "Name": "Yandex GPT",
"Author": "MikhailRaw", "Author": "MikhailRaw",
"Version": "1.0.0", "Version": "1.0.0",
"Language": "csharp", "Language": "csharp",

View File

@@ -7,6 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Items", "Items", "{4A6F7084
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.YandexGPT", "Community.PowerToys.Run.Plugin.YandexGPT\Community.PowerToys.Run.Plugin.YandexGPT.csproj", "{B65D8913-4679-46A0-84EA-DF11C641DDF5}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.YandexGPT", "Community.PowerToys.Run.Plugin.YandexGPT\Community.PowerToys.Run.Plugin.YandexGPT.csproj", "{B65D8913-4679-46A0-84EA-DF11C641DDF5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.YandexGPT.UnitTests", "Community.PowerToys.Run.Plugin.YandexGPT.UnitTests\Community.PowerToys.Run.Plugin.YandexGPT.UnitTests.csproj", "{93DA4312-9C61-4291-8746-C20907616752}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -17,5 +19,9 @@ Global
{B65D8913-4679-46A0-84EA-DF11C641DDF5}.Debug|Any CPU.Build.0 = Debug|Any CPU {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B65D8913-4679-46A0-84EA-DF11C641DDF5}.Release|Any CPU.ActiveCfg = Release|Any CPU {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B65D8913-4679-46A0-84EA-DF11C641DDF5}.Release|Any CPU.Build.0 = Release|Any CPU {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Release|Any CPU.Build.0 = Release|Any CPU
{93DA4312-9C61-4291-8746-C20907616752}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93DA4312-9C61-4291-8746-C20907616752}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93DA4312-9C61-4291-8746-C20907616752}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93DA4312-9C61-4291-8746-C20907616752}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

BIN
readme.md

Binary file not shown.