Skip to content

Commit

Permalink
Code tidy (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar authored Sep 15, 2023
1 parent 163a462 commit 0d98109
Show file tree
Hide file tree
Showing 71 changed files with 366 additions and 382 deletions.
2 changes: 1 addition & 1 deletion src/GCAAnalyser/GCodeAnalyses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void RecursivelyRetrieveAllCommands(List<IGCodeCommand> Result, IReadOnl
}
else
{
if (first || command.LineNumber != Result[Result.Count - 1].LineNumber)
if (first || command.LineNumber != Result[^1].LineNumber)
{
lineNumber++;
first = false;
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/GCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return base.GetHashCode();
return HashCode.Combine(Command, CommandValueString, Comment);
}

public override string ToString()
Expand Down
18 changes: 18 additions & 0 deletions src/GCAAnalyser/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "<Pending>", Scope = "type", Target = "~T:GSendAnalyzer.Analyzers.AnalyzeM630_1RunParameters")]
[assembly: SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "<Pending>", Scope = "type", Target = "~T:GSendAnalyzer.Analyzers.AnalyzeM631_2ReturnCode")]
[assembly: SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "<Pending>", Scope = "type", Target = "~T:GSendAnalyzer.Analyzers.AnalyzeM631_1RunParameters")]
[assembly: SuppressMessage("Major Code Smell", "S2589:Boolean expressions should not be gratuitous", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.Internal.GCodeParser.ParseVariableBlockss(GSendAnalyzer.GCodeAnalyses,System.Collections.Generic.List{GSendShared.IGCodeVariableBlock},System.Int32,System.String)~System.Decimal")]
[assembly: SuppressMessage("Major Code Smell", "S108:Nested blocks of code should not be left empty", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.Internal.GCodeParser.InternalParseGCode(GSendAnalyzer.GCodeAnalyses,System.Byte[],System.Int32)~GSendAnalyzer.GCodeAnalyses")]
[assembly: SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.GCodeAnalyses.AllSpecificCommands(System.Char)~System.Collections.Generic.IReadOnlyList{GSendShared.IGCodeCommand}")]
[assembly: SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "<Pending>", Scope = "member", Target = "~P:GSendAnalyzer.GCodeAnalyses.AllCommands")]
[assembly: SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.GCodeAnalyses.AddOptions(GSendShared.AnalysesOptions)")]
[assembly: SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.Analyzers.AnalyzeM630RunProgram.ValidExtension(System.String)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.Analyzers.AnalyzeM62XComPorts.IsComPortCommand(System.Decimal)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "<Pending>", Scope = "member", Target = "~M:GSendAnalyzer.Analyzers.AnalyzeCoordinateSystemsUsed.IsCoordCommand(System.Decimal)~System.Boolean")]
12 changes: 0 additions & 12 deletions src/GCATests/GCSDB/GSendProviderTests.cs

This file was deleted.

6 changes: 1 addition & 5 deletions src/GCATests/GCService/LiveTestsWithArduino.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ public void HomeAndPause()
}
};

Assert.IsTrue(unlocked);
sut.Connect();
Assert.IsTrue(sut.IsConnected);

sut.WriteLine("$H");
Thread.Sleep(500);
sut.WriteLine("~");

if (unlocked)
{
// do nothing
}

for (int i = 0; i < 10; i++)
{
Thread.Sleep(1000);
Expand Down
171 changes: 54 additions & 117 deletions src/GCATests/GCService/PluginInitializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,129 +1,66 @@
using System.Diagnostics.CodeAnalysis;

using GSendService;

using GSendTests.Mocks;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;

using PluginManager.Abstractions;

using SharedPluginFeatures;

namespace GSendTests.GCService
{
[TestClass]
[ExcludeFromCodeCoverage]
public class PluginInitializationTests
{
//private const string TestsCategory = "Initialization Tests";

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void ExtendsIPluginAndIInitialiseEvents()
//{
// PluginInitialization sut = new PluginInitialization();

// Assert.IsInstanceOfType(sut, typeof(IPlugin));
// Assert.IsInstanceOfType(sut, typeof(IInitialiseEvents));
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void GetVersion_ReturnsCurrentVersion_Success()
//{
// PluginInitialization sut = new PluginInitialization();

// Assert.AreEqual((ushort)1, sut.GetVersion());
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void Initialize_DoesNotAddItemsToLogger()
//{
// PluginInitialization sut = new PluginInitialization();
// MockLogger testLogger = new MockLogger();

// sut.Initialise(testLogger);

// Assert.AreEqual(0, testLogger.Logs.Count);
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void AfterConfigure_DoesNotConfigurePipeline_Success()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();

// sut.AfterConfigure(testApplicationBuilder);

// Assert.IsFalse(testApplicationBuilder.UseCalled);
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void Configure_DoesNotConfigurePipeline_Success()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();

// sut.Configure(testApplicationBuilder);

// Assert.IsFalse(testApplicationBuilder.UseCalled);
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void BeforeConfigure_DoesRegisterApplicationServices()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();

// sut.BeforeConfigure(testApplicationBuilder);

// Assert.IsTrue(testApplicationBuilder.UseCalled);
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void Configure_DoesNotRegisterApplicationServices()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();

// sut.Configure(testApplicationBuilder);

// Assert.IsFalse(testApplicationBuilder.UseCalled);
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void Finalise_DoesNotThrowException()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();
// Assert.IsNotNull(sut);

// sut.Finalise();
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void BeforeConfigureServices_DoesNotThrowException()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();
// MockServiceCollection mockServiceCollection = new MockServiceCollection();

// sut.BeforeConfigureServices(mockServiceCollection);

// Assert.AreEqual(0, mockServiceCollection.ServicesRegistered);
//}

//[TestMethod]
//[TestCategory(TestsCategory)]
//public void ConfigureServices_DoesNotThrowException()
//{
// MockApplicationBuilder testApplicationBuilder = new MockApplicationBuilder();
// PluginInitialization sut = new PluginInitialization();
// MockServiceCollection mockServiceCollection = new MockServiceCollection();

// sut.ConfigureServices(mockServiceCollection);

// Assert.AreEqual(0, mockServiceCollection.ServicesRegistered);
//}
private const string TestsCategory = "Initialization Tests";

[TestMethod]
[TestCategory(TestsCategory)]
public void ExtendsIPluginAndIInitialiseEvents()
{
PluginInitialization sut = new PluginInitialization();

Assert.IsInstanceOfType(sut, typeof(IPlugin));
Assert.IsInstanceOfType(sut, typeof(IInitialiseEvents));
}

[TestMethod]
[TestCategory(TestsCategory)]
public void GetVersion_ReturnsCurrentVersion_Success()
{
PluginInitialization sut = new PluginInitialization();

Assert.AreEqual((ushort)1, sut.GetVersion());
}

[TestMethod]
[TestCategory(TestsCategory)]
public void Initialize_DoesNotAddItemsToLogger()
{
PluginInitialization sut = new PluginInitialization();
MockLogger testLogger = new MockLogger();

sut.Initialise(testLogger);

Assert.AreEqual(0, testLogger.LogItems.Count);
}

[TestMethod]
[TestCategory(TestsCategory)]
public void Finalise_DoesNotThrowException()
{
PluginInitialization sut = new PluginInitialization();
Assert.IsNotNull(sut);

sut.Finalise();
}
}
}
4 changes: 0 additions & 4 deletions src/GCATests/GSendAnalyzerTests/AnalyzeM605PlaySoundTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class AnalyzeM605PlaySoundTests
[TestMethod]
public void Analyze_M605CodeNotFound_Returns_WithNoErrorsOrWarnings()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M604");

Expand All @@ -37,7 +36,6 @@ public void Analyze_M605CodeNotFound_Returns_WithNoErrorsOrWarnings()
[TestMethod]
public void Analyze_M605CodMultipleItemsFoundOnSameLine_Adds_Error()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M605 M605;");

Expand All @@ -56,7 +54,6 @@ public void Analyze_M605CodMultipleItemsFoundOnSameLine_Adds_Error()
[TestMethod]
public void Analyze_M605Code_SoundFileNotFound_Adds_Warning()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M605;e:\\sounds\\mysound.wav");

Expand All @@ -74,7 +71,6 @@ public void Analyze_M605Code_SoundFileNotFound_Adds_Warning()
[TestMethod]
public void Process_M605CodeFound_SoundFileExists_ContainsNoErrorAndNoWarnings()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M605;c:\\windows\\media\\alarm01.wav");

Expand Down
Loading

0 comments on commit 0d98109

Please sign in to comment.