Skip to content

Commit

Permalink
Work on Code Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Feb 22, 2024
1 parent c9aa808 commit 1392ed9
Show file tree
Hide file tree
Showing 65 changed files with 569 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage"
run: dotnet test --no-restore --verbosity normal
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.1
with:
Expand Down
7 changes: 3 additions & 4 deletions RDMSharp/RDM/Device/AbstractRDMDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected async Task ReceiveRDMMessage(RDMMessage rdmMessage)

if ((rdmMessage.DestUID.IsBroadcast || rdmMessage.DestUID == UID) && !rdmMessage.Command.HasFlag(ERDM_Command.RESPONSE))
{
await SendRDMMessage(await processRequestMessage(rdmMessage));
await SendRDMMessage(processRequestMessage(rdmMessage));
return;
}

Expand Down Expand Up @@ -153,13 +153,12 @@ private async Task collectAllParameters()
await UpdateSlotDescriptions();
AllDataPulled = true;
}
protected async Task<RDMMessage> processRequestMessage(RDMMessage rdmMessage)
protected RDMMessage processRequestMessage(RDMMessage rdmMessage)
{
//await Task.Delay(200);
var pm = pmManager.GetRDMParameterWrapperByID(rdmMessage.Parameter);
object responseValue = null;
parameterValues.TryGetValue(rdmMessage.Parameter, out responseValue);
RDMMessage? response = null;
RDMMessage response = null;
if (rdmMessage.Command == ERDM_Command.GET_COMMAND)
{
switch (pm)
Expand Down
2 changes: 1 addition & 1 deletion RDMSharp/RDM/Device/RDMDeviceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public IReadOnlyCollection<ERDM_Parameter> KnownNotSupportedParameters
public event PropertyChangedEventHandler PropertyChanged;
private readonly Func<RDMMessage, Task> sendRdmFunktion;

protected RDMDeviceModel(RDMUID uid, RDMDeviceInfo deviceInfo, Func<RDMMessage, Task> sendRdmFunktion)
internal RDMDeviceModel(RDMUID uid, RDMDeviceInfo deviceInfo, Func<RDMMessage, Task> sendRdmFunktion)
{
this.sendRdmFunktion = sendRdmFunktion;
DeviceInfo = deviceInfo;
Expand Down
2 changes: 1 addition & 1 deletion RDMSharp/RDM/EventTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace RDMSharp
{
internal static class EventTools
public static class EventTools
{
[DebuggerHidden]
public static int InvokeFailSafe(this EventHandler @event, object sender, EventArgs args)
Expand Down
4 changes: 3 additions & 1 deletion RDMSharp/RDM/IPv4Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace RDMSharp
public readonly byte B3;
public readonly byte B4;

public static IPv4Address Default { get => new IPv4Address(0, 0, 0, 0); }
public static IPv4Address LocalHost { get => new IPv4Address(127, 0, 0, 1); }

public IPv4Address(in byte block1, in byte block2, in byte block3, in byte block4)
{
Expand All @@ -26,6 +26,8 @@ public IPv4Address(in string ipAddress) : this()
{
Regex regex = new Regex(@"^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$");
var match = regex.Match(ipAddress);
if (!match.Success)
throw new FormatException("The given string is not a IPv4Address");
B1 = byte.Parse(match.Groups[1].Value);
B2 = byte.Parse(match.Groups[2].Value);
B3 = byte.Parse(match.Groups[3].Value);
Expand Down
41 changes: 1 addition & 40 deletions RDMSharp/RDM/MACAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MACAddress(in string macAddress) : this()
B6 = byte.Parse(match.Groups[6].Value, System.Globalization.NumberStyles.HexNumber);
}
else
throw new Exception($"The given string\"{macAddress}\" is not matchable to any known MAC-Address format");
throw new FormatException($"The given string\"{macAddress}\" is not matchable to any known MAC-Address format");
}

public MACAddress(IEnumerable<byte> enumerable)
Expand Down Expand Up @@ -93,45 +93,6 @@ public static implicit operator MACAddress(byte[] bytes)
return new MACAddress(bytes);
}

public static MACAddress Parse(string uid)
{
if (!uid.Contains(':')) return MACAddress.Empty;
string[] parts = uid.Split(':');
if (parts.Length != 6) return MACAddress.Empty;
foreach (var part in parts)
if (part.Length != 2) return MACAddress.Empty;

byte b1;
byte b2;
byte b3;
byte b4;
byte b5;
byte b6;
try
{
b1 = Convert.ToByte(parts[0], 16);
b2 = Convert.ToByte(parts[1], 16);
b3 = Convert.ToByte(parts[2], 16);
b4 = Convert.ToByte(parts[3], 16);
b5 = Convert.ToByte(parts[4], 16);
b6 = Convert.ToByte(parts[5], 16);
}
catch
{
return MACAddress.Empty;
}
return new MACAddress(b1, b2, b3, b4, b5, b6);
}
public IEnumerable<byte> ToBytes()
{
yield return this.B1;
yield return this.B2;
yield return this.B3;
yield return this.B4;
yield return this.B5;
yield return this.B6;
}

public static bool operator ==(MACAddress a, MACAddress b)
{
return a.Equals(b);
Expand Down
2 changes: 1 addition & 1 deletion RDMSharp/RDM/PayloadObject/GetHardwareAddressResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override byte[] ToPayloadData()
{
List<byte> data = new List<byte>();
data.AddRange(Tools.ValueToData(this.InterfaceId));
data.AddRange(this.HardwareAddress.ToBytes());
data.AddRange((byte[])this.HardwareAddress);
return data.ToArray();
}
}
Expand Down
18 changes: 16 additions & 2 deletions RDMSharp/RDM/RDMMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RDMSharp.ParameterWrapper;
using Microsoft.Extensions.Logging;
using RDMSharp.ParameterWrapper;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -7,7 +8,8 @@
namespace RDMSharp
{
public class RDMMessage : IEquatable<RDMMessage>
{
{
private static ILogger Logger = null;

Check warning on line 12 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The field 'RDMMessage.Logger' is assigned but its value is never used

Check warning on line 12 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The field 'RDMMessage.Logger' is assigned but its value is never used

Check warning on line 12 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The field 'RDMMessage.Logger' is assigned but its value is never used

Check warning on line 12 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The field 'RDMMessage.Logger' is assigned but its value is never used
private byte[] _parameterData = new byte[0];

public RDMMessage()
Expand Down Expand Up @@ -196,6 +198,9 @@ public object Value
}
catch (Exception ex)

Check warning on line 199 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 199 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 199 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 199 in RDMSharp/RDM/RDMMessage.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
#if DEBUG
Logger?.LogError(string.Empty, ex);
#endif
return null;
}
}
Expand Down Expand Up @@ -266,6 +271,15 @@ public bool Equals(RDMMessage other)
ResponseType == other.ResponseType &&
IsAck == other.IsAck &&
EqualityComparer<object>.Default.Equals(Value, other.Value);
}
public static bool operator ==(RDMMessage a, RDMMessage b)
{
return a.Equals(b);
}

public static bool operator !=(RDMMessage a, RDMMessage b)
{
return !a.Equals(b);
}

public override int GetHashCode()
Expand Down
2 changes: 1 addition & 1 deletion RDMSharpTests/Devices/Mock/SendReceivePipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RDMMessageSend(long identifyer, RDMMessage rdmMessage)
Console.WriteLine(rdmMessage);
#endif

RDMMessageRereived?.Invoke(null, new Tuple<long, RDMMessage>(identifyer,rdmMessage));
RDMMessageRereived?.InvokeFailSafe(null, new Tuple<long, RDMMessage>(identifyer,rdmMessage));
}
public static event EventHandler<Tuple<long, RDMMessage>>? RDMMessageRereived;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void ToPayloadAndFromMessageTest()
GetBackgroundQueuedStatusPolicyDescriptionResponse resultGetBackgroundQueuedStatusPolicyDescriptionResponse = GetBackgroundQueuedStatusPolicyDescriptionResponse.FromMessage(message);

Assert.That(resultGetBackgroundQueuedStatusPolicyDescriptionResponse, Is.EqualTo(getBackgroundQueuedStatusPolicyDescriptionResponse));

var res = resultGetBackgroundQueuedStatusPolicyDescriptionResponse.ToString();
var src = getBackgroundQueuedStatusPolicyDescriptionResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
[Test]
public void DescriptionCharLimitTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public void ToPayloadAndFromMessageTest()

GetBackgroundQueuedStatusPolicyResponse resultGetBackgroundQueuedStatusPolicyResponse = GetBackgroundQueuedStatusPolicyResponse.FromMessage(message);

Assert.That(resultGetBackgroundQueuedStatusPolicyResponse, Is.EqualTo(getBackgroundQueuedStatusPolicyResponse));
Assert.That(resultGetBackgroundQueuedStatusPolicyResponse, Is.EqualTo(getBackgroundQueuedStatusPolicyResponse));

var res = resultGetBackgroundQueuedStatusPolicyResponse.ToString();
var src = getBackgroundQueuedStatusPolicyResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
16 changes: 14 additions & 2 deletions RDMSharpTests/RDM/GetBindingAndControlFieldsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public void ToPayloadAndFromMessageTest()

GetBindingAndControlFieldsRequest resultGetBindingAndControlFieldsRequest = GetBindingAndControlFieldsRequest.FromMessage(message);

Assert.That(resultGetBindingAndControlFieldsRequest, Is.EqualTo(getBindingAndControlFieldsRequest));
Assert.That(resultGetBindingAndControlFieldsRequest, Is.EqualTo(getBindingAndControlFieldsRequest));

var res = getBindingAndControlFieldsRequest.ToString();
var src = resultGetBindingAndControlFieldsRequest.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));

GetBindingAndControlFieldsResponse getBindingAndControlFieldsResponse = new GetBindingAndControlFieldsResponse(1, new RDMUID(1213, 34444), 1234, new RDMUID(542, 476436));
data = getBindingAndControlFieldsResponse.ToPayloadData();
Expand All @@ -38,7 +44,13 @@ public void ToPayloadAndFromMessageTest()

GetBindingAndControlFieldsResponse resultGetBindingAndControlFieldsResponse = GetBindingAndControlFieldsResponse.FromMessage(message);

Assert.That(resultGetBindingAndControlFieldsResponse, Is.EqualTo(getBindingAndControlFieldsResponse));
Assert.That(resultGetBindingAndControlFieldsResponse, Is.EqualTo(getBindingAndControlFieldsResponse));

res = getBindingAndControlFieldsResponse.ToString();
src = resultGetBindingAndControlFieldsResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetBrokerStatusResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void ToPayloadAndFromMessageTest()
GetBrokerStatusResponse resultGetBrokerStatusResponse = GetBrokerStatusResponse.FromMessage(message);

Assert.That(resultGetBrokerStatusResponse, Is.EqualTo(getBrokerStatusResponse));

var res = resultGetBrokerStatusResponse.ToString();
var src = getBrokerStatusResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetEndpointListResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public void ToPayloadAndFromMessageTest()
GetEndpointListResponse resultGetEndpointListResponse = GetEndpointListResponse.FromMessage(message);

Assert.That(resultGetEndpointListResponse, Is.EqualTo(getEndpointListResponse));

var res = resultGetEndpointListResponse.ToString();
var src = getEndpointListResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void ToPayloadAndFromMessageTest()
GetEndpointResponderListChangeResponse resultGetEndpointResponderListChangeResponse = GetEndpointResponderListChangeResponse.FromMessage(message);

Assert.That(resultGetEndpointResponderListChangeResponse, Is.EqualTo(getEndpointResponderListChangeResponse));

var res = resultGetEndpointResponderListChangeResponse.ToString();
var src = getEndpointResponderListChangeResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetEndpointRespondersResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public void ToPayloadAndFromMessageTest()
GetEndpointRespondersResponse resultGetEndpointRespondersResponse = GetEndpointRespondersResponse.FromMessage(message);

Assert.That(resultGetEndpointRespondersResponse, Is.EqualTo(getEndpointRespondersResponse));

var res = resultGetEndpointRespondersResponse.ToString();
var src = getEndpointRespondersResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetEndpointTimingDescriptionResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void ToPayloadAndFromMessageTest()
GetEndpointTimingDescriptionResponse resultGetEndpointTimingDescriptionResponse = GetEndpointTimingDescriptionResponse.FromMessage(message);

Assert.That(resultGetEndpointTimingDescriptionResponse, Is.EqualTo(getGetEndpointTimingDescriptionResponse));

var res = resultGetEndpointTimingDescriptionResponse.ToString();
var src = getGetEndpointTimingDescriptionResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
[Test]
public void DescriptionCharLimitTest()
Expand Down
8 changes: 7 additions & 1 deletion RDMSharpTests/RDM/GetHardwareAddressResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void Setup()
[Test]
public void ToPayloadAndFromMessageTest()
{
GetHardwareAddressResponse getHardwareAddressResponse = new GetHardwareAddressResponse(1, MACAddress.Parse("02:42:c0:a8:01:09"));
GetHardwareAddressResponse getHardwareAddressResponse = new GetHardwareAddressResponse(1, new MACAddress("02:42:c0:a8:01:09"));
byte[] data = getHardwareAddressResponse.ToPayloadData();

RDMMessage message = new RDMMessage()
Expand All @@ -24,6 +24,12 @@ public void ToPayloadAndFromMessageTest()
GetHardwareAddressResponse resultGetHardwareAddressResponse = GetHardwareAddressResponse.FromMessage(message);

Assert.That(resultGetHardwareAddressResponse, Is.EqualTo(getHardwareAddressResponse));

var res = resultGetHardwareAddressResponse.ToString();
var src = getHardwareAddressResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
8 changes: 7 additions & 1 deletion RDMSharpTests/RDM/GetIPv4CurrentAddressResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public void ToPayloadAndFromMessageTest()

GetIPv4CurrentAddressResponse resultGetIPv4CurrentAddressResponse = GetIPv4CurrentAddressResponse.FromMessage(message);

Assert.That(resultGetIPv4CurrentAddressResponse, Is.EqualTo(getIPv4CurrentAddressResponse));
Assert.That(resultGetIPv4CurrentAddressResponse, Is.EqualTo(getIPv4CurrentAddressResponse));

var res = resultGetIPv4CurrentAddressResponse.ToString();
var src = getIPv4CurrentAddressResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetInterfaceListResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public void ToPayloadAndFromMessageTest()
GetInterfaceListResponse resultGetInterfaceListResponse = GetInterfaceListResponse.FromMessage(message);

Assert.That(resultGetInterfaceListResponse, Is.EqualTo(getInterfaceListResponse));

var res = resultGetInterfaceListResponse.ToString();
var src = getInterfaceListResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetInterfaceNameResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void ToPayloadAndFromMessageTest()
GetInterfaceNameResponse resultGetInterfaceNameResponse = GetInterfaceNameResponse.FromMessage(message);

Assert.That(resultGetInterfaceNameResponse, Is.EqualTo(getInterfaceNameResponse));

var res = resultGetInterfaceNameResponse.ToString();
var src = getInterfaceNameResponse.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
}
}
6 changes: 6 additions & 0 deletions RDMSharpTests/RDM/GetSetComponentScopeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public void ToPayloadAndFromMessageTest()
resultSensorValue = GetSetComponentScope.FromMessage(message);

Assert.That(resultSensorValue, Is.EqualTo(sensorValue));

var res = resultSensorValue.ToString();
var src = sensorValue.ToString();
Assert.That(res, Is.Not.Null);
Assert.That(src, Is.Not.Null);
Assert.That(res, Is.EqualTo(src));
}
[Test]
public void DescriptionCharLimitTest()
Expand Down
Loading

0 comments on commit 1392ed9

Please sign in to comment.