Skip to content

Commit

Permalink
Plugin interface (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar committed Sep 15, 2023
1 parent 679ce3f commit 163a462
Show file tree
Hide file tree
Showing 64 changed files with 2,544 additions and 303 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main", "feature/*" ]
branches: [ "main", "feature/*", "bug/*" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
Expand All @@ -28,7 +17,7 @@ jobs:
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
runs-on: windows-latest
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/GCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public string CommentStripped(bool replaceVariables)
return Result;

if (Result.StartsWith(CharSemiColon))
Result = Result.Substring(1);
Result = Result[1..];
else if (Result.StartsWith(CharOpeningBracket) && Result.EndsWith(CharClosingBracket))
Result = Result[1..^1];

Expand Down
6 changes: 5 additions & 1 deletion src/GCATests/GSendTests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -26,6 +28,8 @@
<ProjectReference Include="..\GCSService\GSendService.csproj" />
<ProjectReference Include="..\GCSShared\GSendShared.csproj" />
<ProjectReference Include="..\GSendApi\GSendApi.csproj" />
<ProjectReference Include="..\GSendControls\GSendControls.csproj" />
<ProjectReference Include="..\Plugins\GrblTuning\GrblTuningWizard.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
46 changes: 46 additions & 0 deletions src/GCATests/Mocks/MockLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using PluginManager;
using PluginManager.Abstractions;

namespace GSendTests.Mocks
{
internal class MockLogger : ILogger
{
public List<string> LogItems { get; } = new List<string>();

public void AddToLog(in LogLevel logLevel, in string data)
{
LogItems.Add($"{logLevel} - {data}");
}

public void AddToLog(in LogLevel logLevel, in Exception exception)
{
throw new NotImplementedException();
}

public void AddToLog(in LogLevel logLevel, in Exception exception, string data)
{
throw new NotImplementedException();
}

public void AddToLog(in LogLevel logLevel, in string moduleName, in string data)
{
throw new NotImplementedException();
}

public void AddToLog(in LogLevel logLevel, in string moduleName, in Exception exception)
{
throw new NotImplementedException();
}

public void AddToLog(in LogLevel logLevel, in string moduleName, in Exception exception, string data)
{
throw new NotImplementedException();
}
}
}
2 changes: 2 additions & 0 deletions src/GCATests/Mocks/MockPluginClassesService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand All @@ -11,6 +12,7 @@

namespace GSendTests.Mocks
{
[ExcludeFromCodeCoverage]
internal class MockPluginClassesService : IPluginClassesService
{
public object[] GetParameterInstances(Type type)
Expand Down
67 changes: 67 additions & 0 deletions src/GCATests/Mocks/MockPluginMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Drawing;

using GSendShared.Models;
using GSendShared.Plugins;

namespace GSendTests.Mocks
{
internal sealed class MockPluginMenu : IPluginMenu
{
private ISenderPluginHost _senderPluginHost;

public MockPluginMenu(string name, int index, MenuType menuType, MenuParent menuParent)
{
Text = name;
Index = index;
MenuType = menuType;
ParentMenu = menuParent;
}

public MockPluginMenu(string name, MenuType menuType, MenuParent menuParent)
: this(name, -1, menuType, menuParent)
{

}

public string Text { get; set; }

public int Index { get; set; }

public Image MenuImage => null;

public MenuType MenuType { get; set; }

public MenuParent ParentMenu { get; set; }

public bool IsEnabled()
{
return true;
}

public bool IsChecked()
{
return false;
}

public void Clicked()
{
throw new NotImplementedException();
}

public void MachineStatusChanged(MachineStateModel machineStateModel)
{
throw new NotImplementedException();
}

public void UpdateHost<T>(T senderPluginHost)
{
_senderPluginHost = senderPluginHost as ISenderPluginHost;
}

public bool GetShortcut(out string groupName, out string shortcutName)
{
throw new NotImplementedException();
}
}
}
43 changes: 43 additions & 0 deletions src/GCATests/Mocks/MockPluginToolbarButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;

using GSendShared.Models;
using GSendShared.Plugins;

namespace GSendTests.Mocks
{
[ExcludeFromCodeCoverage]
internal class MockPluginToolbarButton : IPluginToolbarButton
{
public MockPluginToolbarButton(string text, int index)
{
Text = text;
Index = index;
}

public ButtonType ButtonType => ButtonType.Button;

public Image Picture => null;

public string Text { get; private set; }

public int Index { get; private set; }

public void Clicked()
{
// not used in this context
}

public bool IsEnabled() => true;

public void MachineStatusChanged(MachineStateModel machineStateModel)
{
// not used in this context
}

public void UpdateHost<T>(T senderPluginHost)
{
// not used in this context
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using GrblTuningWizard;

using GSendShared.Interfaces;
using GSendShared.Plugins;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GSendTests.Plugins.GrblTuningWizardTests
{
[TestClass]
[ExcludeFromCodeCoverage]
public sealed class GSendProTuningWizardPluginTests
{
[TestMethod]
public void Create_ValidInstance_Success()
{
GSendProTuningWizardPlugin sut = new();
Assert.IsNotNull(sut);
Assert.AreEqual("GRBL Tuning Wizard", sut.Name);
Assert.AreEqual(1u, sut.Version);
Assert.AreEqual(PluginHosts.Sender, sut.Host);
Assert.AreEqual(PluginOptions.HasMenuItems, sut.Options);
}

[TestMethod]
public void Validate_MenuItems_Success()
{
GSendProTuningWizardPlugin sut = new();

IReadOnlyList<IPluginMenu> menuItems = sut.MenuItems;

Assert.AreEqual(1, menuItems.Count);
Assert.AreEqual("Tuning Wizard", menuItems[0].Text);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Diagnostics.CodeAnalysis;

using GrblTuningWizard;

using GSendShared.Plugins;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GSendTests.Plugins.GrblTuningWizardTests
{
[TestClass]
[ExcludeFromCodeCoverage]
public class TuningWizardMenuTests
{
[TestMethod]
public void ConstructValidInstance_Success()
{
TuningWizardMenuItem sut = new TuningWizardMenuItem();
Assert.AreEqual("Tuning Wizard", sut.Text);
Assert.AreEqual(-1, sut.Index);
Assert.AreEqual(MenuType.MenuItem, sut.MenuType);
Assert.AreEqual(MenuParent.Tools, sut.ParentMenu);
}
}
}
Loading

0 comments on commit 163a462

Please sign in to comment.