-
Notifications
You must be signed in to change notification settings - Fork 717
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
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2685e4e
Create Restore Bar logger in Package Manager UI
donnie-msft 536e353
More unit tests
donnie-msft 5972584
Add comment to RestoreBarLogger
donnie-msft 242b599
Update comment for RestoreBarLogger
donnie-msft 8263ddc
Make LogAsync just call Log and not throw
donnie-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/NuGet.Clients/NuGet.PackageManagement.UI/Utility/RestoreBarLogger.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
donnie-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
test/NuGet.Clients.Tests/NuGet.PackageManagement.UI.Test/Utility/RestoreBarLoggerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// 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_Always() | ||
{ | ||
// 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()); | ||
} | ||
|
||
[Fact] | ||
public void LogError_InvokesNuGetProjectContextLog_Always() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
var message = Mock.Of<ILogMessage>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogError(data: "Message should be logged"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public void LogWarning_InvokesNuGetProjectContextLog_Always() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
var message = Mock.Of<ILogMessage>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogWarning(data: "Message should be logged"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public void LogInformation_InvokesNuGetProjectContextLog_Never() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogInformation(data: "Message which should be ignored"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Never()); | ||
} | ||
|
||
[Fact] | ||
public void LogInformationSummary_InvokesNuGetProjectContextLog_Never() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogInformationSummary(data: "Message which should be ignored"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Never()); | ||
} | ||
|
||
[Fact] | ||
public void LogDebug_InvokesNuGetProjectContextLog_Never() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogDebug(data: "Message which should be ignored"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Never()); | ||
} | ||
|
||
|
||
[Fact] | ||
public void LogMinimal_InvokesNuGetProjectContextLog_Never() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogMinimal(data: "Message which should be ignored"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Never()); | ||
} | ||
|
||
[Fact] | ||
public void LogVerbose_InvokesNuGetProjectContextLog_Never() | ||
{ | ||
// Arrange | ||
var mockNuGetProjectContext = new Mock<INuGetProjectContext>(); | ||
|
||
// Act | ||
var restoreBarLogger = new RestoreBarLogger(mockNuGetProjectContext.Object); | ||
restoreBarLogger.LogVerbose(data: "Message which should be ignored"); | ||
|
||
// Assert | ||
mockNuGetProjectContext.Verify(nuGetProjectContext => nuGetProjectContext.Log(It.IsAny<ILogMessage>()), Times.Never()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.