Files
scadalink-design/infra/lmxfakeproxy/tests/LmxFakeProxy.Tests/IntegrationSmokeTest.cs

65 lines
1.9 KiB
C#

using ScadaLink.DataConnectionLayer.Adapters;
namespace LmxFakeProxy.Tests;
/// <summary>
/// End-to-end smoke test connecting RealLmxProxyClient to LmxFakeProxy.
/// Requires both OPC UA test server and LmxFakeProxy to be running.
/// Run manually: dotnet test --filter "Category=Integration"
/// </summary>
[Trait("Category", "Integration")]
public class IntegrationSmokeTest
{
private const string Host = "localhost";
private const int Port = 50051;
[Fact]
public async Task ConnectReadWriteSubscribe_EndToEnd()
{
var factory = new RealLmxProxyClientFactory();
var client = factory.Create(Host, Port, null);
try
{
// Connect
await client.ConnectAsync();
Assert.True(client.IsConnected);
// Read initial value
var vtq = await client.ReadAsync("Motor.Speed");
Assert.Equal(LmxQuality.Good, vtq.Quality);
// Write a value
await client.WriteAsync("Motor.Speed", 42.5);
// Read back
var vtq2 = await client.ReadAsync("Motor.Speed");
Assert.Equal(42.5, (double)vtq2.Value!);
// ReadBatch
var batch = await client.ReadBatchAsync(new[] { "Motor.Speed", "Pump.FlowRate" });
Assert.Equal(2, batch.Count);
// Subscribe briefly
LmxVtq? lastUpdate = null;
var sub = await client.SubscribeAsync(
new[] { "Motor.Speed" },
(tag, v) => lastUpdate = v);
// Write to trigger subscription update
await client.WriteAsync("Motor.Speed", 99.0);
await Task.Delay(2000);
await sub.DisposeAsync();
Assert.NotNull(lastUpdate);
// Disconnect
await client.DisconnectAsync();
}
finally
{
await client.DisposeAsync();
}
}
}