Skip to content

Commit

Permalink
Feature/custom tab controls (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar authored Jan 13, 2024
1 parent c83f118 commit 359cb26
Show file tree
Hide file tree
Showing 55 changed files with 1,461 additions and 461 deletions.
3 changes: 3 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ dotnet_diagnostic.IDE0305.severity = none
dotnet_diagnostic.IDE0300.severity = none
dotnet_diagnostic.IDE0290.severity = none

# S1168: Empty arrays and collections should be returned instead of null
dotnet_diagnostic.S1168.severity = none

[*.{cs,vb}]
#### Naming styles ####

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM600Pause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m600Commands.Count == 0)
return;

if (m600Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
foreach (IGCodeCommand command in m600Commands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM601Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m601Commands.Count == 0)
return;

if (m601Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
foreach (IGCodeCommand command in m601Commands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM605PlaySounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m605Commands.Count == 0)
return;

if (m605Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
if (!gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.PlaySound))
codeAnalyses.AddOptions(AnalysesOptions.PlaySound);
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM630RunProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m630Commands.Count == 0)
return;

if (m630Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
if (!gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.RunProgram))
codeAnalyses.AddOptions(AnalysesOptions.RunProgram);
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM630_1RunParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (mCommands.Count == 0)
return;

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
List<int> lineNumbers = [];

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM631_1RunParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (mCommands.Count == 0)
return;

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
List<int> lineNumbers = [];

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM631_2ReturnCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (mCommands.Count == 0)
return;

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
foreach (IGCodeCommand command in mCommands)
{
Expand Down
5 changes: 5 additions & 0 deletions src/GCATests/Mocks/MockEditorPluginHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public MockEditorPluginHost()

public IGSendContext GSendContext => throw new NotImplementedException();

public void AddControl(IPluginControl pluginControl)
{
throw new NotImplementedException();
}

public void AddMenu(IPluginMenu pluginMenu)
{
throw new NotImplementedException();
Expand Down
36 changes: 36 additions & 0 deletions src/GCATests/Mocks/MockGSendContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

using GSendShared;
using GSendShared.Abstractions;

namespace GSendTests.Mocks
{
internal class MockGSendContext : IGSendContext
{
public MockGSendContext()
{
}

public MockGSendContext(IServiceProvider serviceProvider)
: this()
{
ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}

public IServiceProvider ServiceProvider { get; set; }

public bool IsClosing => throw new NotImplementedException();

public IGSendSettings Settings => throw new NotImplementedException();

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

public void ShowMachine(IMachine machine)
{
throw new NotImplementedException();
}
}
}
22 changes: 20 additions & 2 deletions src/GCATests/Mocks/MockSenderPluginHost.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;

using GSendControls.Abstractions;

using GSendShared;
using GSendShared.Models;
using GSendShared.Plugins;
Expand All @@ -16,11 +18,22 @@ public MockSenderPluginHost()

}

public MockSenderPluginHost(IGSendContext gSendContext)
{
GSendContext = gSendContext ?? throw new ArgumentNullException(nameof(gSendContext));
}

public MockSenderPluginHost(IPluginMenu parentMenu)
{
_parent = parentMenu;
}

public MockSenderPluginHost(IPluginMenu parentMenu, IGSendContext gSendContext)
: this(gSendContext)
{
_parent = parentMenu;
}

public IMachine Machine { get; set; }

public List<string> Messages { get; } = new();
Expand All @@ -39,7 +52,7 @@ IPluginMenu IPluginHost.GetMenu(MenuParent menuParent)

public void AddMenu(IPluginMenu pluginMenu)
{

}

public void AddMessage(InformationType informationType, string message)
Expand Down Expand Up @@ -84,6 +97,11 @@ public void SendMessage(string message)
Messages.Add(message);
}

public IGSendContext GSendContext => throw new NotImplementedException();
public void AddControl(IPluginControl pluginControl)
{
throw new NotImplementedException();
}

public IGSendContext GSendContext { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/GCATests/Mocks/MockServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using PluginManager.Abstractions;

using Shared.Classes;

namespace GSendTests.Mocks
{
internal class MockServiceProvider : IServiceProvider
Expand All @@ -27,6 +29,10 @@ public object GetService(Type serviceType)
{
return new MockPluginClassesService();
}
else if (serviceType.Equals(typeof(IRunProgram)))
{
return new MockRunProgram();
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Create_ValidInstance_Success()
Assert.AreEqual("GRBL Tuning Wizard", sut.Name);
Assert.AreEqual(1u, sut.Version);
Assert.AreEqual(PluginHosts.Sender, sut.Host);
Assert.AreEqual(PluginOptions.HasMenuItems | PluginOptions.MessageReceived, sut.Options);
Assert.AreEqual(PluginOptions.HasMenuItems, sut.Options);
}

[TestMethod]
Expand Down
48 changes: 48 additions & 0 deletions src/GCATests/Plugins/HeartbeatTests/HeartbeatControlItemTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Diagnostics.CodeAnalysis;

using GSendControls.Abstractions;
using GSendControls.Plugins.InternalPlugins.Hearbeats;

using GSendShared.Plugins;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GSendTests.Plugins.HeartbeatTests
{
[TestClass]
[ExcludeFromCodeCoverage]
public sealed class HeartbeatControlItemTests
{
[TestMethod]
public void Construct_ValidInstance_Success()
{
HeartbeatControlItem sut = new();
Assert.IsNotNull(sut);
Assert.IsInstanceOfType<IPluginControl>(sut);
Assert.AreEqual("Graphs", sut.Name);
Assert.IsNotNull(sut.Control);
Assert.AreEqual(ControlLocation.Secondary, sut.Location);
Assert.AreEqual("Heartbeat Graphs", sut.Text);
Assert.AreEqual(20, sut.Index);
Assert.IsTrue(sut.ReceiveClientMessages);
Assert.IsTrue(sut.IsEnabled());
}

[TestMethod]
public void ClientMessageReceived_DoesNotThrowException()
{
HeartbeatControlItem sut = new();
bool exceptionRaised = false;
try
{
sut.UpdateHost<object>(null);
}
catch
{
exceptionRaised = true;
}

Assert.IsFalse(exceptionRaised);
}
}
}
82 changes: 82 additions & 0 deletions src/GCATests/Plugins/HeartbeatTests/HeartbeatsPluginTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

using GSendControls.Abstractions;
using GSendControls.Plugins.InternalPlugins.Hearbeats;

using GSendShared.Plugins;

using GSendTests.Mocks;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GSendTests.Plugins.HeartbeatTests
{
[TestClass]
[ExcludeFromCodeCoverage]
public sealed class HeartbeatsPluginTests
{
[TestMethod]
public void Construct_ValidInstance_Success()
{
HearbeatsPlugin sut = new();
Assert.IsNotNull(sut);
Assert.IsInstanceOfType<IGSendPluginModule>(sut);
Assert.AreEqual("Heartbeats", sut.Name);
Assert.AreEqual(1u, sut.Version);
Assert.AreEqual(PluginHosts.Sender, sut.Host);
Assert.AreEqual(PluginOptions.HasControls, sut.Options);
Assert.IsNull(sut.MenuItems);
Assert.IsNull(sut.ToolbarItems);
Assert.IsFalse(sut.ReceiveClientMessages);
}

[TestMethod]
public void Validate_ControlItems_Success()
{
IPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null);
MockSenderPluginHost pluginHost = new(parentMenu);

HearbeatsPlugin sut = new();
sut.Initialize(pluginHost);
IReadOnlyList<IPluginControl> controlItems = sut.ControlItems;

Assert.AreEqual(1, controlItems.Count);
Assert.AreEqual("Heartbeat Graphs", controlItems[0].Text);
}

[TestMethod]
public void ClientMessageReceived_DoesNotThrowException()
{
HearbeatsPlugin sut = new();
bool exceptionRaised = false;
try
{
sut.ClientMessageReceived(null);
}
catch
{
exceptionRaised = true;
}

Assert.IsFalse(exceptionRaised);
}

[TestMethod]
public void Initialize_DoesNotThrowException()
{
HearbeatsPlugin sut = new();
bool exceptionRaised = false;
try
{
sut.Initialize(null);
}
catch
{
exceptionRaised = true;
}

Assert.IsFalse(exceptionRaised);
}
}
}
Loading

0 comments on commit 359cb26

Please sign in to comment.