Exemplo n.º 1
0
        GetActionResult(
            ConnectionOutput output,
            string[]?stdOut,
            string[]?stdErr)
        {
            const string?casePath = @"d:\case";
            const string?search   = "*.png";
            const string?tag      = "image";

            var action = ConnectionTestsHelper.SearchAndTagAction(casePath, search, tag, output);

            action.WriteToStdOut = stdOut;
            action.WriteToStdErr = stdErr;

            var loggerFactory = TestLoggerFactory.Create();

            var nuixConnection = ConnectionTestsHelper.GetNuixConnection(
                loggerFactory,
                ConnectionTestsHelper.SearchHelperAction,
                ConnectionTestsHelper.ExpandHelperAction,
                action
                );

            var result = await nuixConnection.RunFunctionAsync(
                ConnectionTestsHelper.GetStateMonadForProcess(loggerFactory),
                null,
                new NuixSearchAndTag().RubyScriptStepFactory.RubyFunction,
                ConnectionTestsHelper.SearchAndTagParams(casePath, search, tag),
                CasePathParameter.IgnoresOpenCase.Instance,
                new CancellationToken()
                );

            return(loggerFactory, result);
        }
Exemplo n.º 2
0
        public async Task GetOrCreateNuixConnection_WhenScriptFileDoesNotExist_ReturnsError()
        {
            var fakeExternalProcess = new ExternalProcessMock(
                1,
                ConnectionTestsHelper.GetCreateCaseAction()
                );

            var fileMock =
                Mock.Of <IFile>(f => f.Exists(It.IsAny <string>()) == false);

            IStateMonad state = ConnectionTestsHelper.GetStateMonad(
                TestLoggerFactory.Create(),
                fakeExternalProcess,
                ConsoleAdapter.Instance
                );

            //Remove the script from the file system
            var nuixFileSystem =
                state.ExternalContext.TryGetContext <IFileSystem>(ConnectorInjection.FileSystemKey);

            nuixFileSystem.Value.File.Delete(NuixConnectionHelper.NuixGeneralScriptName);

            var connection = await state.GetOrCreateNuixConnection(null, false);

            Assert.True(connection.IsFailure);

            Assert.Matches(
                $"Could not find.+{NuixConnectionHelper.NuixGeneralScriptName}'",
                connection.Error.AsString
                );
        }
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
0
        public async Task RunFunctionAsync_WhenFunctionHasEntityStream_ProcessStream()
        {
            var action = new ExternalProcessAction(
                new ConnectionCommand
            {
                Command            = "EntityStream",
                FunctionDefinition = "doesn't matter",
                Arguments          = new Dictionary <string, object>(),
                IsStream           = true
            }
                );

            var logFactory     = TestLoggerFactory.Create();
            var nuixConnection = ConnectionTestsHelper.GetNuixConnection(logFactory, action);
            var ct             = new CancellationToken();

            var entities = new List <Entity>
            {
                Entity.Create(("Property1", "Value1")), Entity.Create(("Property2", "Value2"))
            };

            var stream1 = entities.ToAsyncEnumerable().ToSCLArray();

            var dict = new Dictionary <RubyFunctionParameter, object>
            {
                { new RubyFunctionParameter("entityStream", "EntityStream", false), stream1 }
            };

            var stepParams = new ReadOnlyDictionary <RubyFunctionParameter, object>(dict);

            var step = new FakeNuixStreamFunction();

            var result = await nuixConnection.RunFunctionAsync(
                ConnectionTestsHelper.GetStateMonadForProcess(logFactory),
                null,
                step.RubyScriptStepFactory.RubyFunction,
                stepParams,
                CasePathParameter.IgnoresOpenCase.Instance,
                ct
                );

            result.ShouldBeSuccessful();

            Assert.Equal(@"[{""Property1"":""Value1""},{""Property2"":""Value2""}]", result.Value);
        }
Exemplo n.º 7
0
        public async Task CloseNuixConnectionAsync_WhenNoConnectionExists_DoesNothing()
        {
            var fakeExternalProcess = new ExternalProcessMock(
                1,
                ConnectionTestsHelper.GetCreateCaseAction()
                );

            IStateMonad state = ConnectionTestsHelper.GetStateMonad(
                fakeExternalProcess,
                TestLoggerFactory.Create()
                );

            var ct = new CancellationToken();

            var actual = await state.CloseNuixConnectionAsync(null, ct);

            Assert.True(actual.IsSuccess);
            Assert.Equal(Unit.Default, actual);
        }
Exemplo n.º 8
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.º 9
0
        public async Task RunFunctionAsync_WhenDisposed_Throws()
        {
            var logFactory     = TestLoggerFactory.Create();
            var nuixConnection = ConnectionTestsHelper.GetNuixConnection(logFactory);

            var ct = new CancellationToken();

            nuixConnection.Dispose();

            await Assert.ThrowsAsync <ObjectDisposedException>(
                () => nuixConnection.RunFunctionAsync <Unit>(
                    ConnectionTestsHelper.GetStateMonadForProcess(logFactory),
                    null !,
                    null !,
                    new Dictionary <RubyFunctionParameter, object>(),
                    CasePathParameter.IgnoresOpenCase.Instance,
                    ct
                    )
                );
        }
Exemplo n.º 10
0
        public async Task SendDoneCommand_WritesDoneToExternalProcess()
        {
            var logFactory     = TestLoggerFactory.Create();
            var action         = ConnectionTestsHelper.GetDoneAction();
            var nuixConnection = ConnectionTestsHelper.GetNuixConnection(logFactory, action);

            var fakeExternalProcess = new ExternalProcessMock(
                1,
                ConnectionTestsHelper.GetCreateCaseAction()
                );

            var state = ConnectionTestsHelper.GetStateMonad(
                fakeExternalProcess,
                logFactory
                );

            var ct = new CancellationToken();

            await nuixConnection.SendDoneCommand(state, null, ct);

            logFactory.Sink.LogEntries.Should()
            .Contain(x => x.Message != null && x.Message.Equals("Finished"));
        }
Exemplo n.º 11
0
        public async Task GetOrCreateNuixConnection_OnStartExternalProcessFailure_ReturnsError()
        {
            var fakeExternalProcess =
                new ExternalProcessMock(1, ConnectionTestsHelper.GetCreateCaseAction())
            {
                ProcessPath = "WrongPath", ValidateArguments = false
            };

            var loggerFactory = TestLoggerFactory.Create();

            IStateMonad state =
                ConnectionTestsHelper.GetStateMonad(
                    fakeExternalProcess,
                    loggerFactory
                    );

            var createConnection = await state.GetOrCreateNuixConnection(null, true);

            createConnection.ShouldBeFailure();

            createConnection.Error.AsString.Should()
            .Be($"External Process Failed: 'Could not start '{Constants.NuixConsoleExe}''");
        }
Exemplo n.º 12
0
        public async Task RunFunctionAsync_WithTwoEntityStreamParameters_ReturnsError()
        {
            var logFactory     = TestLoggerFactory.Create();
            var action         = ConnectionTestsHelper.GetDoneAction();
            var nuixConnection = ConnectionTestsHelper.GetNuixConnection(logFactory, action);
            var ct             = new CancellationToken();

            var stream1 = new List <Entity>().ToAsyncEnumerable().ToSCLArray();
            var stream2 = new List <Entity>().ToAsyncEnumerable().ToSCLArray();

            var dict = new Dictionary <RubyFunctionParameter, object>
            {
                { new RubyFunctionParameter("stream1Arg", "Stream1", false), stream1 },
                { new RubyFunctionParameter("stream2Arg", "Stream2", false), stream2 }
            };

            var stepParams = new ReadOnlyDictionary <RubyFunctionParameter, object>(dict);

            var step = new FakeNuixTwoStreamFunction();

            var result = await nuixConnection.RunFunctionAsync(
                ConnectionTestsHelper.GetStateMonadForProcess(logFactory),
                null,
                step.RubyScriptStepFactory.RubyFunction,
                stepParams,
                CasePathParameter.IgnoresOpenCase.Instance,
                ct
                );

            Assert.True(result.IsFailure);

            Assert.Equal(
                "A nuix function cannot have more than one Entity Array parameter.",
                result.Error.AsString
                );
        }
Exemplo n.º 13
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
                );
        }