Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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."));
        }
Exemplo n.º 5
0
        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
                );
        }