Skip to content

Create Restore Bar logger in Package Manager UI #6433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.ProjectManagement;

namespace NuGet.PackageManagement.UI.Utility
{
internal class RestoreBarLogger : LoggerBase
{
private readonly INuGetProjectContext _nuGetProjectContext;

public RestoreBarLogger(INuGetProjectContext nuGetProjectContext)
: base(verbosityLevel: LogLevel.Warning)
{
_nuGetProjectContext = nuGetProjectContext ?? throw new ArgumentNullException(nameof(nuGetProjectContext));
}

public override void Log(ILogMessage message)
{
_nuGetProjectContext.Log(message);
}

public override Task LogAsync(ILogMessage message)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using NuGet.Common;
using NuGet.PackageManagement.UI.Utility;
using NuGet.PackageManagement.VisualStudio;
using NuGet.Packaging;
using NuGet.ProjectManagement;
Expand Down Expand Up @@ -269,7 +270,7 @@ public async Task<bool> UIRestorePackagesAsync(CancellationToken token)
string solutionDirectory = await _solutionManager.GetSolutionDirectoryAsync(token);
await _packageRestoreManager.RestoreMissingPackagesInSolutionAsync(solutionDirectory,
this,
new LoggerAdapter(this),
new RestoreBarLogger(this),
token);

if (_restoreException == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using NuGet.Common;
using NuGet.PackageManagement.UI.Utility;
using NuGet.ProjectManagement;
using Xunit;

namespace NuGet.PackageManagement.UI.Test.Utility
{
public class RestoreBarLoggerTests
{
[Fact]
public void Constructor_NullParameterNuGetProjectContext_Throws()
{
// Arrange
INuGetProjectContext? nuGetProjectContext = null;

// Act
Action act = () => new RestoreBarLogger(nuGetProjectContext!);

// Assert
act.Should().Throw<ArgumentNullException>()
.WithParameterName("nuGetProjectContext");
}

[Fact]
public async Task LogAsync_ShouldThrowNotImplementedException_ThrowsAsync()
{
// Arrange
var nuGetProjectContext = Mock.Of<INuGetProjectContext>();
var message = Mock.Of<ILogMessage>();
var restoreBarLogger = new RestoreBarLogger(nuGetProjectContext);

// Act
var act = async () => await restoreBarLogger.LogAsync(message);

// Assert
await act.Should().ThrowAsync<NotImplementedException>();
}

[Fact]
public void Log_InvokesNuGetProjectContextLog_Once()
{
// Arrange
var mockNuGetProjectContext = new Mock<INuGetProjectContext>();
var message = Mock.Of<ILogMessage>();

// Act
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object);
restoreBarLogger.Log(message);

// Assert
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Once());
}
}
}
Loading