public void RunSCL_WhenRunnerIsFailure_LogsErrorAndReturnsFailure() { var factory = TestLoggerFactory.Create(x => x.SetMinimumLevel(LogLevel.Debug)); var fs = new MockFileSystem(); var connMan = new FakeConnectorManager(); var run = new Mock <RunCommand>(factory.CreateLogger <RunCommand>(), fs, connMan); run.Setup(r => r.GetInjectedContexts(It.IsAny <StepFactoryStore>(), It.IsAny <SCLSettings>())) .Returns(() => new ErrorBuilder(ErrorCode.Unknown, "Just Testing")); var sp = new ServiceCollection() .AddSingleton(new ConnectorCommand(connMan)) .AddSingleton(run.Object) .AddSingleton(new StepsCommand(connMan)) .AddSingleton(new ValidateCommand(factory.CreateLogger <ValidateCommand>(), fs, connMan)) .AddSingleton <EDRMethods>() .BuildServiceProvider(); var result = new AppRunner <EDRMethods>() .UseMicrosoftDependencyInjection(sp) .UseDefaultMiddleware() .RunInMem($"run scl \"Log '{TheUltimateTestString}'\""); result.ExitCode.Should().Be(1); Assert.Contains( factory.Sink.LogEntries, l => l.LogLevel == LogLevel.Error && l.Message !.Contains("Unknown Error: 'Just Testing'") ); }
public StepsCommandTests() { var factory = TestLoggerFactory.Create(x => x.SetMinimumLevel(LogLevel.Debug)); var fs = new MockFileSystem(); var connMan = new FakeConnectorManager(); _steps = new List <StepsCommand.ConnectorRow>(); var stepsMock = new Mock <StepsCommand>(connMan); stepsMock.Setup(r => r.WriteTable(It.IsAny <IEnumerable <StepsCommand.ConnectorRow> >())) .Callback <IEnumerable <StepsCommand.ConnectorRow> >(steps => _steps = steps.ToList()); _sp = new ServiceCollection() .AddSingleton(new ConnectorCommand(connMan)) .AddSingleton(new RunCommand(factory.CreateLogger <RunCommand>(), fs, connMan)) .AddSingleton(stepsMock.Object) .AddSingleton(new ValidateCommand(factory.CreateLogger <ValidateCommand>(), fs, connMan)) .AddSingleton <EDRMethods>() .BuildServiceProvider(); }