using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests;
///
/// Unit tests for the IReadable/IWritable surface that don't need a live remote OPC UA
/// server (the uninitialised-guard contract). The wire-level read/write round-trips live in
/// OpcUaServer.IntegrationTests/OpcUaClientDriverWireTests, against the in-process server.
///
[Trait("Category", "Unit")]
public sealed class OpcUaClientReadWriteTests
{
/// Verifies that ReadAsync throws InvalidOperationException when not initialized.
[Fact]
public async Task ReadAsync_without_initialize_throws_InvalidOperationException()
{
using var drv = new OpcUaClientDriver(new OpcUaClientDriverOptions(), "opcua-uninit");
await Should.ThrowAsync(async () =>
await drv.ReadAsync(["ns=2;s=Demo"], TestContext.Current.CancellationToken));
}
/// Verifies that WriteAsync throws InvalidOperationException when not initialized.
[Fact]
public async Task WriteAsync_without_initialize_throws_InvalidOperationException()
{
using var drv = new OpcUaClientDriver(new OpcUaClientDriverOptions(), "opcua-uninit");
await Should.ThrowAsync(async () =>
await drv.WriteAsync(
[new WriteRequest("ns=2;s=Demo", 42)],
TestContext.Current.CancellationToken));
}
}