using Robotico.Graph; using Robotico.Nexus.Client.Tests.TestSupport; using Robotico.Result.Errors; using Xunit; namespace Robotico.Nexus.Client.Tests.Graph; public class NexusGraphStoreTests : 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.Graph)); 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.Graph.Open("mydb"); Assert.True(result.IsSuccess(out IGraphSession? session, out _)); session!.Dispose(); } [Fact] public void Open_UsesDefaultDatabaseName_WhenPathBlank() { Robotico.Result.Result result = _client.Graph.Open(string.Empty); Assert.True(result.IsSuccess(out IGraphSession? session, out _)); session!.Dispose(); } [Fact] public void Open_Fails_WhenPingReportsEngineFailure() { Robotico.Result.Result result = _client.Graph.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.Graph.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.Graph.OpenOrCreate("greenfield-db"); Assert.True(result.IsSuccess(out IGraphSession? session, out _)); session!.Dispose(); } [Fact] public void Create_Fails_WithAlreadyExists_WhenPingSucceeds() { Robotico.Result.Result result = _client.Graph.Create("already-reachable-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.Graph.Create(FakeNexusTriggers.PingReportsFailure); Assert.True(result.IsError(out IError? error)); Assert.Equal(NexusErrors.Unavailable, error!.Code); } [Fact] public void Create_RegistersInitialLabelsAndEdgeTypes() { Robotico.Result.Result result = _client.Graph.Create( "brand-new-db-" + Guid.NewGuid(), initialLabels: ["Person", "Company"], initialEdgeTypes: ["WorksAt"]); // Fake Ping always succeeds for a fresh sentinel-free name, so Create reports AlreadyExists. Assert.True(result.IsError(out IError? error)); Assert.Equal(NexusErrors.AlreadyExists, error!.Code); } }