Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MQTTnet" Version="4.3.7.1207" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Testcontainers" Version="3.10.0" />
<PackageReference Include="coverlet.collector" Version="6.0.4" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TrakHound Inc. licenses this file to you under the MIT license.

using NUnit.Framework;
using System;

namespace MTConnect.AgentModule.MqttRelay.Tests
{
Expand Down Expand Up @@ -90,7 +91,7 @@ public void TryFlush_keeps_dirty_when_writer_throws()
persister.Update(123UL);

Assert.Throws<System.IO.IOException>(
() => persister.TryFlush(_ => throw new System.IO.IOException("disk full")));
(Action)(() => persister.TryFlush(_ => throw new System.IO.IOException("disk full"))));

Assert.That(persister.IsDirty, Is.True,
"A failed write must leave the persister dirty so the next flush retries.");
Expand Down Expand Up @@ -135,7 +136,7 @@ public void TryFlush_no_ops_when_writer_is_null()
// A null writer means the caller has not wired persistence
// (e.g. DurableRelay disabled at runtime); the persister
// must not throw.
Assert.DoesNotThrow(() => persister.TryFlush(null));
Assert.DoesNotThrow((Action)(() => persister.TryFlush(null)));
// Dirty bit unchanged because no write happened.
Assert.That(persister.IsDirty, Is.True);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public void DisconnectWithTimeout_does_not_throw_when_disconnect_factory_throws_
// and route the exception to the fault logger.
string loggedFault = null;

Assert.DoesNotThrow(() => MqttRelayLifecycle.DisconnectWithTimeout(
Assert.DoesNotThrow((Action)(() => MqttRelayLifecycle.DisconnectWithTimeout(
disconnect: () => throw new InvalidOperationException("sync throw"),
timeout: TimeSpan.FromSeconds(1),
onFault: ex => loggedFault = ex.Message));
onFault: ex => loggedFault = ex.Message)));

Assert.That(loggedFault, Is.EqualTo("sync throw"));
}
Expand All @@ -104,10 +104,10 @@ public void DisconnectWithTimeout_no_ops_when_disconnect_factory_is_null()
// The shutdown path must tolerate a null disconnect factory
// (for example when _mqttClient is null because the worker
// never ran).
Assert.DoesNotThrow(() => MqttRelayLifecycle.DisconnectWithTimeout(
Assert.DoesNotThrow((Action)(() => MqttRelayLifecycle.DisconnectWithTimeout(
disconnect: null,
timeout: TimeSpan.FromSeconds(1),
onFault: _ => { }));
onFault: _ => { })));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TrakHound Inc. licenses this file to you under the MIT license.

using NUnit.Framework;
using System;

namespace MTConnect.AgentModule.MqttRelay.Tests
{
Expand Down Expand Up @@ -32,7 +33,7 @@ public void StopServers_does_not_throw_when_both_servers_null()
// either server is the worst case; the helper must be a
// total function over (null, null).
Assert.DoesNotThrow(
() => MqttRelayLifecycle.StopServers(documentStop: null, entityStop: null));
(Action)(() => MqttRelayLifecycle.StopServers(documentStop: null, entityStop: null)));
}

/// <summary>Pins the behaviour expressed by the test name: stop servers invokes document stop when provided.</summary>
Expand Down Expand Up @@ -85,9 +86,9 @@ public void StopServers_swallows_document_stop_exception_and_runs_entity_stop()
// shutdown leaks live handlers.
var entityStopped = false;

Assert.DoesNotThrow(() => MqttRelayLifecycle.StopServers(
Assert.DoesNotThrow((Action)(() => MqttRelayLifecycle.StopServers(
documentStop: () => throw new System.InvalidOperationException("doc"),
entityStop: () => entityStopped = true));
entityStop: () => entityStopped = true)));

Assert.That(entityStopped, Is.True);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public void Log_no_ops_when_callback_is_null()
// Defensive: the helper must not throw when the logger is
// not wired (would defeat the purpose of catching the
// unexpected exception).
Assert.DoesNotThrow(() => WorkerLoopExceptionLogger.Log(
Assert.DoesNotThrow((Action)(() => WorkerLoopExceptionLogger.Log(
exception: new InvalidOperationException("boom"),
onLog: null));
onLog: null)));
}

/// <summary>Pins the behaviour expressed by the test name: log treats subclass of task canceled exception as cancellation.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Agent_DeviceAdded_NullInternalErrorSwallowsFault()
var device = new Device { Name = "device-1", Uuid = "uuid-1" };
EventHandler<IDevice> handler = (_, _) => throw new InvalidOperationException("DeviceAdded fault");

Assert.DoesNotThrow(() => handler.Raise(this, (IDevice)device, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, (IDevice)device, null)));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -96,7 +96,7 @@ public void Agent_ObservationReceived_NullInternalErrorSwallowsFault()
var obs = new ObservationInput();
EventHandler<IObservationInput> handler = (_, _) => throw new InvalidOperationException("ObservationReceived fault");

Assert.DoesNotThrow(() => handler.Raise(this, (IObservationInput)obs, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, (IObservationInput)obs, null)));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -127,7 +127,7 @@ public void Agent_ObservationAdded_NullInternalErrorSwallowsFault()
var obs = new Observation();
EventHandler<IObservation> handler = (_, _) => throw new InvalidOperationException("ObservationAdded fault");

Assert.DoesNotThrow(() => handler.Raise(this, (IObservation)obs, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, (IObservation)obs, null)));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -158,7 +158,7 @@ public void Agent_AssetAdded_NullInternalErrorSwallowsFault()
var asset = new Asset { AssetId = "a1", Timestamp = DateTime.UtcNow };
EventHandler<IAsset> handler = (_, _) => throw new InvalidOperationException("AssetAdded fault");

Assert.DoesNotThrow(() => handler.Raise(this, (IAsset)asset, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, (IAsset)asset, null)));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -187,7 +187,7 @@ public void AgentBroker_StreamsResponseSent_NullInternalErrorSwallowsFault()
{
EventHandler handler = (_, _) => throw new InvalidOperationException("StreamsResponseSent fault");

Assert.DoesNotThrow(() => handler.Raise(this, EventArgs.Empty, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, EventArgs.Empty, null)));
}

// -----------------------------------------------------------------------
Expand All @@ -201,7 +201,7 @@ public void Agent_NullGenericHandler_DoesNotThrow()
EventHandler<IDevice>? handler = null;
var device = new Device { Name = "noop-device", Uuid = "noop-uuid" };

Assert.DoesNotThrow(() => handler.Raise(this, (IDevice)device, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, (IDevice)device, null)));
}

/// <summary>Pins the behavior expressed by the test name: Raise with a null non-generic EventHandler is a safe no-op covering the no-subscriber case at runtime.</summary>
Expand All @@ -210,7 +210,7 @@ public void AgentBroker_NullNonGenericHandler_DoesNotThrow()
{
EventHandler? handler = null;

Assert.DoesNotThrow(() => handler.Raise(this, EventArgs.Empty, null));
Assert.DoesNotThrow((Action)(() => handler.Raise(this, EventArgs.Empty, null)));
}

// =======================================================================
Expand Down Expand Up @@ -246,7 +246,7 @@ public void Agent_InvalidDeviceAdded_NullInternalErrorSwallowsFault()
var result = new ValidationResult(false, "bad device");
MTConnectDeviceValidationHandler handler = (_, _) => throw new InvalidOperationException("InvalidDeviceAdded fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h(device, result)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h(device, result))));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -278,7 +278,7 @@ public void Agent_InvalidComponentAdded_NullInternalErrorSwallowsFault()
var result = new ValidationResult(false, "bad component");
MTConnectComponentValidationHandler handler = (_, _, _) => throw new InvalidOperationException("InvalidComponentAdded fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1", component, result)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1", component, result))));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -310,7 +310,7 @@ public void Agent_InvalidCompositionAdded_NullInternalErrorSwallowsFault()
var result = new ValidationResult(false, "bad composition");
MTConnectCompositionValidationHandler handler = (_, _, _) => throw new InvalidOperationException("InvalidCompositionAdded fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1", composition, result)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1", composition, result))));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -342,7 +342,7 @@ public void Agent_InvalidDataItemAdded_NullInternalErrorSwallowsFault()
var result = new ValidationResult(false, "bad data item");
MTConnectDataItemValidationHandler handler = (_, _, _) => throw new InvalidOperationException("InvalidDataItemAdded fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1", dataItem, result)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1", dataItem, result))));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -372,7 +372,7 @@ public void Agent_InvalidObservationAdded_NullInternalErrorSwallowsFault()
var result = new ValidationResult(false, "bad observation");
MTConnectObservationValidationHandler handler = (_, _, _) => throw new InvalidOperationException("InvalidObservationAdded fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1", "key-1", result)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1", "key-1", result))));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -404,7 +404,7 @@ public void Agent_InvalidAssetAdded_NullInternalErrorSwallowsFault()
var result = new ValidationResult(false, "bad asset");
MTConnectAssetValidationHandler handler = (_, _) => throw new InvalidOperationException("InvalidAssetAdded fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h(asset, result)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h(asset, result))));
}

// =======================================================================
Expand Down Expand Up @@ -435,7 +435,7 @@ public void AgentBroker_DevicesRequestReceived_NullInternalErrorSwallowsFault()
{
MTConnectDevicesRequestedHandler handler = _ => throw new InvalidOperationException("DevicesRequestReceived fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1")));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1"))));
}

// -----------------------------------------------------------------------
Expand All @@ -462,7 +462,7 @@ public void AgentBroker_DevicesResponseSent_NullInternalErrorSwallowsFault()
{
MTConnectDevicesHandler handler = _ => throw new InvalidOperationException("DevicesResponseSent fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h(null!)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h(null!))));
}

// -----------------------------------------------------------------------
Expand All @@ -489,7 +489,7 @@ public void AgentBroker_StreamsRequestReceived_NullInternalErrorSwallowsFault()
{
MTConnectStreamsRequestedHandler handler = _ => throw new InvalidOperationException("StreamsRequestReceived fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1")));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1"))));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -518,7 +518,7 @@ public void AgentBroker_AssetsRequestReceived_NullInternalErrorSwallowsFault()
var ids = new[] { "asset-1" };
MTConnectAssetsRequestedHandler handler = _ => throw new InvalidOperationException("AssetsRequestReceived fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h(ids)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h(ids))));
}

// -----------------------------------------------------------------------
Expand All @@ -545,7 +545,7 @@ public void AgentBroker_DeviceAssetsRequestReceived_NullInternalErrorSwallowsFau
{
MTConnectDeviceAssetsRequestedHandler handler = _ => throw new InvalidOperationException("DeviceAssetsRequestReceived fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h("uuid-1")));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h("uuid-1"))));
}

// -----------------------------------------------------------------------
Expand All @@ -572,7 +572,7 @@ public void AgentBroker_AssetsResponseSent_NullInternalErrorSwallowsFault()
{
MTConnectAssetsHandler handler = _ => throw new InvalidOperationException("AssetsResponseSent fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h(null!)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h(null!))));
}

// -----------------------------------------------------------------------
Expand All @@ -599,7 +599,7 @@ public void AgentBroker_ErrorResponseSent_NullInternalErrorSwallowsFault()
{
MTConnectErrorHandler handler = _ => throw new InvalidOperationException("ErrorResponseSent fault");

Assert.DoesNotThrow(() => MulticastIsolation.Raise(handler, h => h((IErrorResponseDocument)null!)));
Assert.DoesNotThrow((Action)(() => MulticastIsolation.Raise(handler, h => h((IErrorResponseDocument)null!))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static string SimulateFreshBoot(string agentName, int port = 0)
public void DeriveFromSeed_matches_python_uuid_v5_NAMESPACE_DNS_example_com_vector()
{
var derived = DeterministicAgentUuid.DeriveFromSeed("example.com");
Assert.AreEqual("cfbff0d1-9375-5685-968c-48ce8b15ae17", derived,
Assert.That(derived, Is.EqualTo("cfbff0d1-9375-5685-968c-48ce8b15ae17"),
"DeriveFromSeed must reproduce the canonical UUID v5(NAMESPACE_DNS, 'example.com') vector.");
}

Expand Down
Loading