using Shouldly;
using Xunit;

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

public sealed class ModbusTransportFactoryTests
{
    [Fact]
    public void Tcp_mode_builds_tcp_transport()
        => ModbusTransportFactory.Create(new ModbusDriverOptions { Transport = ModbusTransportMode.Tcp })
            .ShouldBeOfType<ModbusTcpTransport>();

    [Fact]
    public void RtuOverTcp_mode_builds_rtu_transport()
        => ModbusTransportFactory.Create(new ModbusDriverOptions { Transport = ModbusTransportMode.RtuOverTcp })
            .ShouldBeOfType<ModbusRtuOverTcpTransport>();

    [Fact]
    public void Default_options_build_tcp_transport()
        => ModbusTransportFactory.Create(new ModbusDriverOptions())
            .ShouldBeOfType<ModbusTcpTransport>();

    [Fact]
    public void Unknown_transport_mode_throws()
        => Should.Throw<ArgumentOutOfRangeException>(
            () => ModbusTransportFactory.Create(new ModbusDriverOptions { Transport = (ModbusTransportMode)999 }));
}
