using Robotico.Nexus.Client.Tests.TestSupport; using Robotico.Result.Errors; using Robotico.Time; using Xunit; namespace Robotico.Nexus.Client.Tests.Time; public class NexusTimeStoreTests : IAsyncLifetime { private NexusTestHost _host = null!; private NexusClient _client = null!; public async Task InitializeAsync() { _host = await NexusTestHost.StartAsync(); Robotico.Result.Result connected = NexusClient.Connect(_host.ConnectionUri(NexusUriSchemes.Time)); Assert.True(connected.IsSuccess(out NexusClient? client, out _)); _client = client!; } public async Task DisposeAsync() { _client.Dispose(); await _host.DisposeAsync(); } [Fact] public void Open_Succeeds_WhenEngineReachable() { Robotico.Result.Result result = _client.Time.Open("mytimedb"); Assert.True(result.IsSuccess(out ITimeSession? session, out _)); session!.Dispose(); } [Fact] public void Open_UsesDefaultDatabaseName_WhenPathBlank() { Robotico.Result.Result result = _client.Time.Open(string.Empty); Assert.True(result.IsSuccess(out ITimeSession? session, out _)); session!.Dispose(); } [Fact] public void Open_Fails_WhenPingReportsEngineFailure() { Robotico.Result.Result result = _client.Time.Open(FakeNexusTriggers.PingReportsFailure); Assert.True(result.IsError(out IError? error)); Assert.Equal(NexusErrors.Unavailable, error!.Code); } [Fact] public void Open_Fails_WhenPingThrowsRpcException() { Robotico.Result.Result result = _client.Time.Open(FakeNexusTriggers.PingThrows); Assert.True(result.IsError(out IError? error)); Assert.Equal(NexusErrors.Unavailable, error!.Code); } [Fact] public void OpenOrCreate_DelegatesTo_Open() { Robotico.Result.Result result = _client.Time.OpenOrCreate("greenfield-time-db"); Assert.True(result.IsSuccess(out ITimeSession? session, out _)); session!.Dispose(); } [Fact] public void Create_Fails_WithAlreadyExists_WhenPingSucceeds() { Robotico.Result.Result result = _client.Time.Create("already-reachable-time-db"); Assert.True(result.IsError(out IError? error)); Assert.Equal(NexusErrors.AlreadyExists, error!.Code); } [Fact] public void Create_Fails_WhenInitialPingReportsFailure() { Robotico.Result.Result result = _client.Time.Create(FakeNexusTriggers.PingReportsFailure); Assert.True(result.IsError(out IError? error)); Assert.Equal(NexusErrors.Unavailable, error!.Code); } }