Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/McjCoderOrg.ClaudeAutoResume/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using McjCoderOrg.ClaudeAutoResume.Resources;
using McjCoderOrg.ClaudeAutoResume.Services;

using Microsoft.Extensions.DependencyInjection;

using Serilog;

namespace McjCoderOrg.ClaudeAutoResume;
Expand All @@ -22,34 +20,31 @@ internal sealed class Application : IApplication

private readonly IArgumentParser _argumentParser;
private readonly IConsoleService _console;
private readonly IServiceProvider _serviceProvider;
private readonly IEnvironmentService _environment;
private readonly ILogger _logger;

/// <summary>
/// Initializes a new instance of the <see cref="Application"/> class.
/// </summary>
/// <param name="argumentParser">The argument parser.</param>
/// <param name="console">The console service.</param>
/// <param name="serviceProvider">The service provider for creating monitors.</param>
/// <param name="environment">The environment service.</param>
/// <param name="logger">The logger.</param>
public Application(
IArgumentParser argumentParser,
IConsoleService console,
IServiceProvider serviceProvider,
IEnvironmentService environment,
ILogger? logger = null)
{
_argumentParser = argumentParser;
_console = console;
_serviceProvider = serviceProvider;
_environment = environment;
_logger = logger ?? Log.Logger;
}

/// <inheritdoc/>
public async Task<int> RunAsync(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
Console.InputEncoding = Encoding.UTF8;

var parseResult = _argumentParser.Parse(args);

if (parseResult.ShowHelp)
Expand Down Expand Up @@ -101,10 +96,7 @@ public async Task<int> RunAsync(string[] args)

private ClaudeMonitor CreateMonitor(WrapperConfig config)
{
// Create monitor with DI services
var console = _serviceProvider.GetRequiredService<IConsoleService>();
var environment = _serviceProvider.GetRequiredService<IEnvironmentService>();
return new ClaudeMonitor(config, console, environment, _logger);
return new ClaudeMonitor(config, _console, _environment, _logger);
}

private static string? ValidateArguments(ParseResult result)
Expand Down
23 changes: 8 additions & 15 deletions tests/McjCoderOrg.ClaudeAutoResume.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,29 @@ public sealed class ProgramTests
{
private readonly ITestOutputHelper _output;
private readonly Mock<IConsoleService> _mockConsole;
private readonly Mock<IServiceProvider> _mockServiceProvider;
private readonly Mock<IEnvironmentService> _mockEnvironment;
private Application _app = null!;

public ProgramTests(ITestOutputHelper output)
{
_output = output;
_mockConsole = new Mock<IConsoleService>(MockBehavior.Loose);
_mockServiceProvider = new Mock<IServiceProvider>(MockBehavior.Loose);
_mockEnvironment = new Mock<IEnvironmentService>(MockBehavior.Loose);

// Setup console mock
_mockConsole.Setup(c => c.WindowWidth).Returns(120);
_mockConsole.Setup(c => c.WindowHeight).Returns(30);

// Setup environment mock
_mockEnvironment.Setup(e => e.CurrentDirectory).Returns(Environment.CurrentDirectory);
_mockEnvironment.Setup(e => e.GetEnvironmentVariables()).Returns(new Dictionary<string, string>(StringComparer.Ordinal));
}

private Application CreateApplication(Mock<IArgumentParser>? parserMock = null)
{
var mockEnvironment = new Mock<IEnvironmentService>(MockBehavior.Loose);
mockEnvironment.Setup(e => e.CurrentDirectory).Returns(Environment.CurrentDirectory);
mockEnvironment.Setup(e => e.GetEnvironmentVariables()).Returns(new Dictionary<string, string>(StringComparer.Ordinal));

var parser = parserMock?.Object ?? new ArgumentParser(mockEnvironment.Object);

_mockServiceProvider
.Setup(sp => sp.GetService(typeof(IConsoleService)))
.Returns(_mockConsole.Object);
_mockServiceProvider
.Setup(sp => sp.GetService(typeof(IEnvironmentService)))
.Returns(mockEnvironment.Object);
var parser = parserMock?.Object ?? new ArgumentParser(_mockEnvironment.Object);

return new Application(parser, _mockConsole.Object, _mockServiceProvider.Object);
return new Application(parser, _mockConsole.Object, _mockEnvironment.Object);
}

[Fact]
Expand Down