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); }
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 ); }
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 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); }
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); }
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 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 ) ); }
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")); }
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}''"); }
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 ); }
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 ); }