using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;

namespace ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests;

/// <summary>
///     Unit tests for the IReadable/IWritable surface that don't need a live remote OPC UA
///     server. Wire-level round-trips against a local in-process server fixture land in a
///     follow-up PR once we have one scaffolded.
/// </summary>
[Trait("Category", "Unit")]
public sealed class OpcUaClientReadWriteTests
{
    /// <summary>Verifies that ReadAsync throws InvalidOperationException when not initialized.</summary>
    [Fact]
    public async Task ReadAsync_without_initialize_throws_InvalidOperationException()
    {
        using var drv = new OpcUaClientDriver(new OpcUaClientDriverOptions(), "opcua-uninit");
        await Should.ThrowAsync<InvalidOperationException>(async () =>
            await drv.ReadAsync(["ns=2;s=Demo"], TestContext.Current.CancellationToken));
    }

    /// <summary>Verifies that WriteAsync throws InvalidOperationException when not initialized.</summary>
    [Fact]
    public async Task WriteAsync_without_initialize_throws_InvalidOperationException()
    {
        using var drv = new OpcUaClientDriver(new OpcUaClientDriverOptions(), "opcua-uninit");
        await Should.ThrowAsync<InvalidOperationException>(async () =>
            await drv.WriteAsync(
                [new WriteRequest("ns=2;s=Demo", 42)],
                TestContext.Current.CancellationToken));
    }
}
