Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit c71f47a

Browse files
Refactoring
1 parent 19d68fd commit c71f47a

23 files changed

+142
-215
lines changed

CSharpInteractive.Tests/BuildMessageLogWriterTests.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ namespace CSharpInteractive.Tests;
55

66
public class BuildMessageLogWriterTests
77
{
8-
private static readonly ProcessInfo ProcessInfo = new(Mock.Of<IStartInfo>(), Mock.Of<IProcessMonitor>());
8+
private static readonly ProcessInfo ProcessInfo = new(Mock.Of<IStartInfo>(), Mock.Of<IProcessMonitor>(), 1);
99
private static readonly Output Output = new(Mock.Of<IStartInfo>(), false, "", 99);
1010
private readonly Mock<ILog<BuildMessageLogWriter>> _log = new();
1111
private readonly Mock<IStdOut> _stdOut = new();
1212
private readonly Mock<IStdErr> _stdErr = new();
13-
private readonly Mock<ICommandLineStatisticsRegistry> _statisticsRegistry = new();
1413

1514
[Fact]
1615
public void ShouldWriteInfo()
@@ -48,7 +47,6 @@ public void ShouldWriteWarning()
4847
writer.Write(ProcessInfo, new BuildMessage(Output, BuildMessageState.Warning, default, "Abc"));
4948

5049
// Then
51-
_statisticsRegistry.Verify(i => i.RegisterWarning(ProcessInfo, It.IsAny<Text[]>()));
5250
_log.Verify(i => i.Warning(It.IsAny<Text[]>()));
5351
}
5452

@@ -64,13 +62,11 @@ public void ShouldWriteError(BuildMessageState state)
6462
writer.Write(ProcessInfo, new BuildMessage(Output, state, default, "Abc"));
6563

6664
// Then
67-
_statisticsRegistry.Verify(i => i.RegisterError(ProcessInfo, It.IsAny<Text[]>()));
6865
_log.Verify(i => i.Error(ErrorId.Build, It.IsAny<Text[]>()));
6966
}
7067

7168
private BuildMessageLogWriter CreateInstance() =>
7269
new(_log.Object,
7370
_stdOut.Object,
74-
_stdErr.Object,
75-
_statisticsRegistry.Object);
71+
_stdErr.Object);
7672
}

CSharpInteractive.Tests/BuildRunnerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class BuildRunnerTests
2727

2828
public BuildRunnerTests()
2929
{
30-
var processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>());
30+
var processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>(), 1);
3131
_processResult = new ProcessResult(processInfo, ProcessState.Finished, 33, []);
3232
var buildResult = new BuildResult(_commandLineResult.Object);
3333
_process.Setup(i => i.GetStartInfo(_host.Object)).Returns(_startInfo.Object);

CSharpInteractive.Tests/CommandLineRunnerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CommandLineRunnerTests
1515

1616
public CommandLineRunnerTests()
1717
{
18-
var processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>());
18+
var processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>(), 1);
1919
_processResult = new ProcessResult(processInfo, ProcessState.Finished, 12, [], 33);
2020
}
2121

CSharpInteractive.Tests/CustomMessagesProcessorTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CSharpInteractive.Tests;
55

66
public class CustomMessagesProcessorTests
77
{
8-
private static readonly ProcessInfo ProcessInfo = new(Mock.Of<IStartInfo>(), Mock.Of<IProcessMonitor>());
8+
private static readonly ProcessInfo ProcessInfo = new(Mock.Of<IStartInfo>(), Mock.Of<IProcessMonitor>(), 1);
99
private static readonly Output Output = new(Mock.Of<IStartInfo>(), false, "", 99);
1010
private readonly Mock<IStartInfo> _startInfo = new();
1111

CSharpInteractive.Tests/DefaultBuildMessagesProcessorTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace CSharpInteractive.Tests;
66

77
public class DefaultBuildMessagesProcessorTests
88
{
9-
private static readonly ProcessInfo ProcessInfo = new(Mock.Of<IStartInfo>(), Mock.Of<IProcessMonitor>());
9+
private static readonly ProcessInfo ProcessInfo = new(Mock.Of<IStartInfo>(), Mock.Of<IProcessMonitor>(), 1);
1010
private static readonly Output Output = new(Mock.Of<IStartInfo>(), false, "", 99);
1111
private readonly Mock<ICISettings> _teamCitySettings = new();
1212
private readonly Mock<IProcessOutputWriter> _processOutputWriter = new();

CSharpInteractive.Tests/ProcessInFlowRunnerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ProcessInFlowRunnerTests
2121

2222
public ProcessInFlowRunnerTests()
2323
{
24-
_processInfo = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
24+
_processInfo = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
2525
_processResult = new ProcessResult(_processInfo, ProcessState.Finished, 33, [], 12);
2626
_flowContext.SetupGet(i => i.CurrentFlowId).Returns("FlowId123");
2727
_startInfo.SetupGet(i => i.Vars).Returns(InitialVars);

CSharpInteractive.Tests/ProcessMonitorTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ProcessMonitorTests
1616

1717
public ProcessMonitorTests()
1818
{
19-
_processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>());
19+
_processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>(), 1);
2020
_startInfoDescription.Setup(i => i.GetDescriptionText(_startInfo.Object, It.IsAny<int?>())).Returns([Description]);
2121
_startInfo.SetupGet(i => i.ExecutablePath).Returns("Cm d");
2222
_startInfo.SetupGet(i => i.WorkingDirectory).Returns("W d");

CSharpInteractive.Tests/ProcessResultHandlerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ProcessResultHandlerTests
1515

1616
public ProcessResultHandlerTests()
1717
{
18-
_processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>());
18+
_processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>(), 1);
1919
}
2020

2121
[Theory]

CSharpInteractive.Tests/ProcessRunnerTests.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class ProcessRunnerTests: IDisposable
1414

1515
public ProcessRunnerTests()
1616
{
17-
_processResult = new ProcessResult(new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>()), ProcessState.Finished, 12, [new Text("Abc")]);
17+
_processResult = new ProcessResult(new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>(), 1), ProcessState.Finished, 12, [new Text("Abc")]);
1818
}
1919

2020
[Fact]
@@ -30,7 +30,7 @@ public void ShouldKillWhenTimeoutIsExpired()
3030
var instance = CreateInstance();
3131

3232
// When
33-
instance.Run(new ProcessInfo(_startInfo.Object, _monitor.Object, Handler), timeout).ShouldBe(_processResult);
33+
instance.Run(new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler), timeout).ShouldBe(_processResult);
3434

3535
// Then
3636
_processManager.Verify(i => i.WaitForExit(timeout));
@@ -44,7 +44,7 @@ public void ShouldRunWhenTimeoutIsSpecified()
4444
{
4545
// Given
4646
var timeout = TimeSpan.FromSeconds(5);
47-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
47+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
4848
Exception? exception;
4949
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
5050
_processManager.Setup(i => i.WaitForExit(timeout)).Returns(true);
@@ -68,7 +68,7 @@ public void ShouldRunWhenTimeoutIsNotSpecified()
6868
{
6969
// Given
7070
var timeout = TimeSpan.Zero;
71-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
71+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
7272
Exception? exception;
7373
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
7474
_processManager.Setup(i => i.WaitForExit(TimeSpan.Zero)).Returns(true);
@@ -92,7 +92,7 @@ public void ShouldNotWaitWhenCannotStart()
9292
{
9393
// Given
9494
var timeout = TimeSpan.Zero;
95-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
95+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
9696
var cannotStart = new Exception("Cannot start");
9797
var exception = cannotStart;
9898
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(false);
@@ -113,7 +113,7 @@ public void ShouldProvideOutput()
113113
{
114114
// Given
115115
var timeout = TimeSpan.Zero;
116-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
116+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
117117
Exception? exception;
118118
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
119119
_processManager.SetupGet(i => i.ExitCode).Returns(1);
@@ -132,7 +132,7 @@ public void ShouldProvideOutput()
132132
public void ShouldRun()
133133
{
134134
// Given
135-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
135+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
136136
Exception? exception;
137137
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
138138
_processManager.Setup(i => i.WaitForExit(TimeSpan.FromDays(1))).Returns(true);
@@ -154,7 +154,7 @@ public void ShouldRun()
154154
public void ShouldRunWhenStateProviderIsNotDefined()
155155
{
156156
// Given
157-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
157+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
158158
Exception? exception;
159159
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
160160
_processManager.Setup(i => i.WaitForExit(TimeSpan.FromDays(1))).Returns(true);
@@ -175,7 +175,7 @@ public void ShouldRunWhenStateProviderIsNotDefined()
175175
public async Task ShouldRunAsync()
176176
{
177177
// Given
178-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
178+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
179179
Exception? exception;
180180
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
181181
_processManager.SetupGet(i => i.ExitCode).Returns(2);
@@ -199,7 +199,7 @@ public async Task ShouldRunAsync()
199199
public async Task ShouldKillWhenCanceled()
200200
{
201201
// Given
202-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
202+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
203203
Exception? exception;
204204
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
205205
_processManager.SetupGet(i => i.ExitCode).Returns(2);
@@ -223,7 +223,7 @@ public async Task ShouldKillWhenCanceled()
223223
public async Task ShouldThrowException()
224224
{
225225
// Given
226-
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, Handler);
226+
var processRun = new ProcessInfo(_startInfo.Object, _monitor.Object, 1, Handler);
227227
Exception? exception;
228228
_processManager.Setup(i => i.Start(_startInfo.Object, out exception)).Returns(true);
229229
_processManager.SetupGet(i => i.ExitCode).Returns(2);

CSharpInteractive.Tests/SummaryPresenterTests.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace CSharpInteractive.Tests;
88
public class SummaryPresenterTests
99
{
1010
private readonly Mock<ILog<SummaryPresenter>> _log = new();
11-
private readonly Mock<ICommandLineStatistics> _commandLineStatistics = new();
12-
private readonly Mock<IPresenter<ICommandLineStatistics>> _commandLineStatisticsPresenter = new();
1311
private readonly Mock<IStatistics> _statistics = new();
1412
private readonly Mock<IPresenter<IStatistics>> _statisticsPresenter = new();
1513

@@ -26,6 +24,7 @@ public void ShouldSummary(bool? success, bool hasError, bool hasWarning, string
2624
{
2725
// Given
2826
var presenter = CreateInstance();
27+
_statistics.SetupGet(i => i.CommandLines).Returns(ArraySegment<CommandLineInfo>.Empty);
2928
if (hasError)
3029
{
3130
_statistics.SetupGet(i => i.Errors).Returns([new Text("Err")]);
@@ -49,15 +48,12 @@ public void ShouldSummary(bool? success, bool hasError, bool hasWarning, string
4948
presenter.Show(new Summary(success));
5049

5150
// Then
52-
_commandLineStatisticsPresenter.Verify(i => i.Show(_commandLineStatistics.Object));
5351
_statisticsPresenter.Verify(i => i.Show(_statistics.Object));
5452
_log.Verify(i => i.Info(new Text(message, color)));
5553
}
5654

5755
private SummaryPresenter CreateInstance() =>
5856
new(_log.Object,
59-
_commandLineStatistics.Object,
60-
_commandLineStatisticsPresenter.Object,
6157
_statistics.Object,
6258
_statisticsPresenter.Object);
6359
}

CSharpInteractive/Composition.cs

-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private void Setup()
104104
return lineCodeSource;
105105
}))
106106
.Bind().To<Statistics>()
107-
.Bind().To<CommandLineStatistics>()
108107
.Bind().To<CommandsRunner>()
109108
.Bind().To<CodeSourceCommandFactory>()
110109
.Bind().To<CSharpScriptRunner>()
@@ -134,7 +133,6 @@ private void Setup()
134133
.Bind().To<StringService>()
135134
.Bind().To<TracePresenter>()
136135
.Bind().To<StatisticsPresenter>()
137-
.Bind().To<CommandLineStatisticsPresenter>()
138136
.Bind().To<DiagnosticsPresenter>()
139137
.Bind().To<ScriptStatePresenter>()
140138
.Bind().To<BuildEngine>()

CSharpInteractive/Core/BuildMessageLogWriter.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace CSharpInteractive.Core;
77
internal class BuildMessageLogWriter(
88
ILog<BuildMessageLogWriter> log,
99
[Tag("Default")] IStdOut stdOut,
10-
[Tag("Default")] IStdErr stdErr,
11-
ICommandLineStatisticsRegistry statisticsRegistry)
10+
[Tag("Default")] IStdErr stdErr)
1211
: IBuildMessageLogWriter
1312
{
1413
public void Write(ProcessInfo processInfo, BuildMessage message)
@@ -26,14 +25,12 @@ public void Write(ProcessInfo processInfo, BuildMessage message)
2625

2726
case BuildMessageState.Warning:
2827
var warning = new Text(message.Text, Color.Warning);
29-
statisticsRegistry.RegisterWarning(processInfo, warning);
3028
log.Warning(warning);
3129
break;
3230

3331
case BuildMessageState.Failure:
3432
case BuildMessageState.BuildProblem:
3533
var error = new Text(message.Text, Color.Error);
36-
statisticsRegistry.RegisterError(processInfo, error);
3734
log.Error(ErrorId.Build, error);
3835
break;
3936
}

CSharpInteractive/Core/BuildRunner.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ public IBuildResult Run(ICommandLine commandLine, Action<BuildMessage>? handler
2828
ArgumentNullException.ThrowIfNull(commandLine);
2929
var buildContext = buildContextFactory();
3030
var startInfo = CreateStartInfo(commandLine);
31-
var processInfo = new ProcessInfo(startInfo, monitorFactory());
31+
var processInfo = new ProcessInfo(startInfo, monitorFactory(), ProcessInfo.CreateRunId());
3232
var info = processInfo;
3333
processInfo = processInfo.WithHandler(output => Handle(info, handler, output, buildContext));
3434
var processResult = processRunner.Run(processInfo, timeout);
3535
processResultHandler.Handle(processResult, handler);
3636
var buildResult = buildContext.Create(
3737
new CommandLineResult(startInfoDescription, startInfo, processResult.State, processResult.ElapsedMilliseconds, processResult.ExitCode, processResult.Error));
38-
statisticsRegistry.Register(new CommandLineInfo(buildResult, processResult));
38+
var commandLineInfo = new CommandLineInfo(buildResult, processResult);
39+
statisticsRegistry.Register(commandLineInfo);
3940
return buildResult;
4041
}
4142

@@ -44,14 +45,15 @@ public async Task<IBuildResult> RunAsync(ICommandLine commandLine, Action<BuildM
4445
ArgumentNullException.ThrowIfNull(commandLine);
4546
var buildContext = buildContextFactory();
4647
var startInfo = CreateStartInfo(commandLine);
47-
var processInfo = new ProcessInfo(startInfo, monitorFactory());
48+
var processInfo = new ProcessInfo(startInfo, monitorFactory(), ProcessInfo.CreateRunId());
4849
var info = processInfo;
4950
processInfo = processInfo.WithHandler(output => Handle(info, handler, output, buildContext));
5051
var processResult = await processRunner.RunAsync(processInfo, cancellationToken);
5152
processResultHandler.Handle(processResult, handler);
5253
var buildResult = buildContext.Create(
5354
new CommandLineResult(startInfoDescription, startInfo, processResult.State, processResult.ElapsedMilliseconds, processResult.ExitCode, processResult.Error));
54-
statisticsRegistry.Register(new CommandLineInfo(buildResult, processResult));
55+
var commandLineInfo = new CommandLineInfo(buildResult, processResult);
56+
statisticsRegistry.Register(commandLineInfo);
5557
return buildResult;
5658
}
5759

CSharpInteractive/Core/CommandLineRunner.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@ internal class CommandLineRunner(
1515
public ICommandLineResult Run(ICommandLine commandLine, Action<Output>? handler = default, TimeSpan timeout = default)
1616
{
1717
ArgumentNullException.ThrowIfNull(commandLine);
18-
var processResult = processRunner.Run(new ProcessInfo(commandLine.GetStartInfo(host), monitorFactory(), handler), timeout);
18+
var processResult = processRunner.Run(new ProcessInfo(commandLine.GetStartInfo(host), monitorFactory(), ProcessInfo.CreateRunId(), handler), timeout);
1919
processResultHandler.Handle(processResult, handler);
2020
var commandLineResult = new CommandLineResult(startInfoDescription, processResult.ProcessInfo.StartInfo, processResult.State, processResult.ElapsedMilliseconds, processResult.ExitCode, processResult.Error);
21-
statisticsRegistry.Register(new CommandLineInfo(commandLineResult, processResult));
21+
var info = new CommandLineInfo(commandLineResult, processResult);
22+
statisticsRegistry.Register(info);
2223
return commandLineResult;
2324
}
2425

2526
public async Task<ICommandLineResult> RunAsync(ICommandLine commandLine, Action<Output>? handler = default, CancellationToken cancellationToken = default)
2627
{
2728
ArgumentNullException.ThrowIfNull(commandLine);
28-
var processResult = await processRunner.RunAsync(new ProcessInfo(commandLine.GetStartInfo(host), monitorFactory(), handler), cancellationToken);
29+
var processResult = await processRunner.RunAsync(new ProcessInfo(commandLine.GetStartInfo(host), monitorFactory(), ProcessInfo.CreateRunId(), handler), cancellationToken);
2930
processResultHandler.Handle(processResult, handler);
3031
var commandLineResult = new CommandLineResult(startInfoDescription, processResult.ProcessInfo.StartInfo, processResult.State, processResult.ElapsedMilliseconds, processResult.ExitCode, processResult.Error);
31-
statisticsRegistry.Register(new CommandLineInfo(commandLineResult, processResult));
32+
var info = new CommandLineInfo(commandLineResult, processResult);
33+
statisticsRegistry.Register(info);
3234
return commandLineResult;
3335
}
3436
}

CSharpInteractive/Core/CommandLineStatistics.cs

-59
This file was deleted.

0 commit comments

Comments
 (0)