public async Task GetOrCreateNuixConnection_WhenConnectionExists_ReturnsConnection() { var loggerFactory = TestLoggerFactory.Create(); var state = ConnectionTestsHelper.GetStateMonadWithConnection(loggerFactory); var expected = state.GetVariable <NuixConnection>(NuixConnectionHelper.NuixVariableName); var createConnection = await state.GetOrCreateNuixConnection(null, false); Assert.True(createConnection.IsSuccess); Assert.Same(expected.Value, createConnection.Value); }
public async Task CloseNuixConnectionAsync_WhenConnectionExists_ClosesConnection() { var state = ConnectionTestsHelper.GetStateMonadWithConnection(TestLoggerFactory.Create()); var ct = new CancellationToken(); var actual = await state.CloseNuixConnectionAsync(null, ct); var connection = state.GetVariable <NuixConnection>(NuixConnectionHelper.NuixVariableName); Assert.True(actual.IsSuccess); Assert.Equal(Unit.Default, actual); Assert.True(connection.IsFailure); }
public async Task GetOrCreateNuixConnection_WhenReopenIsSet_DisposesOldConnection() { var loggerFactory = TestLoggerFactory.Create(); var state = ConnectionTestsHelper.GetStateMonadWithConnection(loggerFactory); var originalConnection = state.GetVariable <NuixConnection>(NuixConnectionHelper.NuixVariableName); var createConnection = await state.GetOrCreateNuixConnection(null, true); var processRef = originalConnection.Value.ExternalProcess as ExternalProcessMock.ProcessReferenceMock; Assert.True(createConnection.IsSuccess); Assert.True(processRef !.IsDisposed); }
public async Task GetOrCreateNuixConnection_WhenConnectionAlreadyDisposed_LogsMessage() { var loggerFactory = TestLoggerFactory.Create(); var state = ConnectionTestsHelper.GetStateMonadWithConnection(loggerFactory); var originalConnection = state.GetVariable <NuixConnection>(NuixConnectionHelper.NuixVariableName); originalConnection.Value.Dispose(); var createConnection = await state.GetOrCreateNuixConnection(null, true); Assert.True(originalConnection.IsSuccess); Assert.True(createConnection.IsSuccess); loggerFactory.Sink.LogEntries .Should() .Contain(x => x.Message != null && x.Message.Equals("Connection already disposed.")); }
public async Task CloseNuixConnectionAsync_ErrorOnClose_ReturnsError() { var state = ConnectionTestsHelper.GetStateMonadWithConnection( TestLoggerFactory.Create(), ConnectionTestsHelper.GetDoneAction() ); var ct = new CancellationToken(); var originalConnection = state.GetVariable <NuixConnection>(NuixConnectionHelper.NuixVariableName); Assert.True(originalConnection.IsSuccess); originalConnection.Value.Dispose(); var actual = await state.CloseNuixConnectionAsync(null, ct); Assert.True(actual.IsFailure); Assert.Matches( $"Cannot access a disposed object\\.\\s+Object name: '{nameof(NuixConnection)}'", actual.Error.AsString ); }