Skip to content

Commit

Permalink
Merge pull request #97 from Rickedb/improvement/interface-segregation
Browse files Browse the repository at this point in the history
Version 5.1.0 - Segregating interfaces to each functionality
  • Loading branch information
Rickedb authored Jan 12, 2023
2 parents 9c59e68 + 5661718 commit 0498a46
Show file tree
Hide file tree
Showing 166 changed files with 892 additions and 256 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build
name: dotnetcore

on:
pull_request:
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/net-framework.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: .Net Framework

on:
pull_request:
paths:
- 'src/*'
push:
branches-ignore:
- master

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- name: Setup .Net Framework
uses: actions/setup-dotnet@master
- name: build
run: |
dotnet msbuild src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj -t:restore
dotnet msbuild src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj -p:Configuration=Release
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- name: Build and run .net core tests
uses: actions/setup-dotnet@master
with:
dotnet-version: '3.1.414'
- name: Test Mids
run: |
dotnet build src/MIDTesters.Core/MIDTesters.Core.csproj
dotnet test src/MIDTesters.Core/MIDTesters.Core.csproj
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
- name: Publish NuGet
run: |
dotnet build src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj --configuration release
nuget push src/OpenProtocolInterpreter/bin/release/OpenProtocolInterpreter.5.0.0.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate
nuget push src/OpenProtocolInterpreter/bin/release/OpenProtocolInterpreter.5.1.0.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate
3 changes: 2 additions & 1 deletion OpenProtocolInterpreter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{BDBD
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{CE8390CD-7EFE-43CC-A8DD-123F04D6045E}"
ProjectSection(SolutionItems) = preProject
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
.github\workflows\net-framework.yml = .github\workflows\net-framework.yml
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Expand Down
Binary file modified dist/lib/netstandard2.0/OpenProtocolInterpreter.dll
Binary file not shown.
96 changes: 91 additions & 5 deletions dist/lib/netstandard2.0/OpenProtocolInterpreter.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

namespace OpenProtocolInterpreter.Sample.Ethernet
{
/// <summary>
/// ETHERNET CLASSES TAKEN FROM SimpleTCP Project
/// <see cref="https://github.com/BrandonPotter/SimpleTCP" />
/// </summary>
public class SimpleTcpClient : IDisposable
{
public SimpleTcpClient()
Expand Down Expand Up @@ -232,8 +228,6 @@ public Message WriteLineAndGetReply(string data, TimeSpan timeout)
}
}



#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls

Expand Down
8 changes: 8 additions & 0 deletions src/MIDTesters.Core/DefaultMidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ namespace MIDTesters
{
public class DefaultMidTests<TMid> : MidTester where TMid : Mid
{
[TestMethod]
[TestCategory("Defaults")]
public void HasParameterlessConstructor()
{
var constructor = typeof(TMid).GetConstructor(new Type[] { });
Assert.IsTrue(constructor != null);
}

[TestMethod]
[TestCategory("Defaults")]
public void HasHeaderParameterConstructor()
Expand Down
66 changes: 66 additions & 0 deletions src/MIDTesters.Core/TestMidExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenProtocolInterpreter;
using OpenProtocolInterpreter.Communication;
using System;

namespace MIDTesters
{
Expand All @@ -12,6 +13,13 @@ public TestMidExtensions()

}

[TestMethod]
public void TestPack()
{
var package = new Mid0001(true).PackWithNul();
Assert.IsNotNull(package);
}

[TestMethod]
public void TestPackWithNul()
{
Expand All @@ -20,12 +28,70 @@ public void TestPackWithNul()
Assert.AreEqual('\0', package[package.Length - 1]);
}

[TestMethod]
public void TestPackBytes()
{
var bytes = new Mid0001(true).PackBytesWithNul();
Assert.IsNotNull(bytes);
}

[TestMethod]
public void TestPackBytesWithNul()
{
var bytes = new Mid0001(true).PackBytesWithNul();
Assert.IsNotNull(bytes);
Assert.AreEqual(0x00, bytes[bytes.Length - 1]);
}

[TestMethod]
public void TestGetReply()
{
var mid0002 = new Mid0001(true).GetReply();
Assert.IsNotNull(mid0002);
}

[TestMethod]
public void TestGetReplyWithRevision()
{
var revision = 3;
var mid0002 = new Mid0001(true).GetReply(revision);
Assert.IsNotNull(mid0002);
Assert.AreEqual(mid0002.Header.Revision, revision);
}

[TestMethod]
public void TestGetAcceptCommand()
{
var mid0005 = new Mid0003().GetAcceptCommand();
Assert.IsNotNull(mid0005);
}

[TestMethod]
public void TestGetDeclineCommand()
{
var error = Error.CLIENT_ALREADY_CONNECTED;
var mid0004 = new Mid0001().GetDeclineCommand(error);
Assert.IsNotNull(mid0004);
Assert.AreEqual(mid0004.ErrorCode, error);
}

[TestMethod]
public void TestAssertAndGetDeclineCommand()
{
var error = Error.CLIENT_ALREADY_CONNECTED;
var mid0004 = new Mid0001().AssertAndGetDeclineCommand(error);
Assert.IsNotNull(mid0004);
Assert.AreEqual(mid0004.ErrorCode, error);
}

[TestMethod]
public void TestAssertAndGetDeclineCommandWithNonDocumentedError()
{
Assert.ThrowsException<ArgumentException>(() =>
{
var error = Error.CALIBRATION_FAILED;
var mid0004 = new Mid0001().AssertAndGetDeclineCommand(error);
});
}
}
}
12 changes: 8 additions & 4 deletions src/OpenProtocolInterpreter/Alarm/Mid0070.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
namespace OpenProtocolInterpreter.Alarm
using System.Collections.Generic;

namespace OpenProtocolInterpreter.Alarm
{
/// <summary>
/// Alarm subscribe
/// <para>A subscription for the alarms that can appear in the controller.</para>
/// <para>Message sent by Integrator</para>
/// <para>Answers: <see cref="Communication.Mid0005"/> Command accepted or <see cref="Communication.Mid0004"/> Command error, Alarm subscription already exists</para>
/// </summary>
public class Mid0070 : Mid, IAlarm, IIntegrator
public class Mid0070 : Mid, IAlarm, IIntegrator, ISubscription, IAcceptableCommand, IDeclinableCommand
{
private const int LAST_REVISION = 2;
public const int MID = 70;

public IEnumerable<Error> DocumentedPossibleErrors => new Error[] { Error.ALARM_SUBSCRIPTION_ALREADY_EXISTS };

public Mid0070() : this(LAST_REVISION)
{

}

public Mid0070(Header header) : base(header)
public Mid0070(int revision = LAST_REVISION, bool noAckFlag = false) : base(MID, revision, noAckFlag)
{

}

public Mid0070(int revision = LAST_REVISION, bool noAckFlag = false) : base(MID, revision, noAckFlag)
public Mid0070(Header header) : base(header)
{

}
Expand Down
6 changes: 3 additions & 3 deletions src/OpenProtocolInterpreter/Alarm/Mid0071.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace OpenProtocolInterpreter.Alarm
/// <para>Message sent by: Controller</para>
/// <para>Answer: <see cref="Mid0072"/> Alarm acknowledge</para>
/// </summary>
public class Mid0071 : Mid, IAlarm, IController
public class Mid0071 : Mid, IAlarm, IController, IAcknowledgeable<Mid0072>
{
private IValueConverter<bool> _boolConverter;
private IValueConverter<DateTime> _dateConverter;
private readonly IValueConverter<bool> _boolConverter;
private readonly IValueConverter<DateTime> _dateConverter;
private const int LAST_REVISION = 2;
public const int MID = 71;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenProtocolInterpreter/Alarm/Mid0072.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <para>Message sent by: Integrator</para>
/// <para>Answer: None</para>
/// </summary>
public class Mid0072 : Mid, IAlarm, IIntegrator
public class Mid0072 : Mid, IAlarm, IIntegrator, IAcknowledge
{
private const int LAST_REVISION = 2;
public const int MID = 72;
Expand Down
Loading

0 comments on commit 0498a46

Please sign in to comment.