Skip to content
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

Replace NullLogger with FakeLogger #14982

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/OrchardCore.Build/Dependencies.AspNetCore.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<!-- 'Microsoft.Extensions' packages that are not included in the ASP.NET Core shared framework -->
<ItemGroup>
<PackageManagement Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageManagement Include="Microsoft.Extensions.Diagnostics.Testing" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageManagement Include="Microsoft.Extensions.Http.Polly" Version="$(MicrosoftExtensionsPackagesVersion)" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions test/OrchardCore.Tests/Email/EmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ private static ISmtpService CreateSmtpService(SmtpSettings settings)
var options = new Mock<IOptions<SmtpSettings>>();
options.Setup(o => o.Value).Returns(settings);

var logger = new Mock<ILogger<SmtpService>>();
var logger = new FakeLogger<SmtpService>();
var localizer = new Mock<IStringLocalizer<SmtpService>>();
var smtp = new SmtpService(options.Object, logger.Object, localizer.Object);
var smtp = new SmtpService(options.Object, logger, localizer.Object);

return smtp;
}
Expand Down
6 changes: 3 additions & 3 deletions test/OrchardCore.Tests/Extensions/ExtensionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ExtensionManagerTests()
new[] { new ExtensionPriorityStrategy() },
new TypeFeatureProvider(),
_moduleFeatureProvider,
new NullLogger<ExtensionManager>()
new FakeLogger<ExtensionManager>()
);

_themeScopedExtensionManager = new ExtensionManager(
Expand All @@ -45,7 +45,7 @@ public ExtensionManagerTests()
new[] { new ExtensionPriorityStrategy() },
new TypeFeatureProvider(),
_themeFeatureProvider,
new NullLogger<ExtensionManager>()
new FakeLogger<ExtensionManager>()
);

_moduleThemeScopedExtensionManager = new ExtensionManager(
Expand All @@ -54,7 +54,7 @@ public ExtensionManagerTests()
new[] { new ExtensionPriorityStrategy() },
new TypeFeatureProvider(),
_themeFeatureProvider,
new NullLogger<ExtensionManager>()
new FakeLogger<ExtensionManager>()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace OrchardCore.Tests.Localization
public class PortableObjectStringLocalizerTests
{
private readonly Mock<ILocalizationManager> _localizationManager;
private readonly Mock<ILogger> _logger;
private readonly FakeLogger _logger;

public PortableObjectStringLocalizerTests()
{
_localizationManager = new Mock<ILocalizationManager>();
_logger = new Mock<ILogger>();
_logger = new FakeLogger();
}

[Fact]
Expand All @@ -21,7 +21,7 @@ public void LocalizerReturnsTranslationsFromProvidedDictionary()
new CultureDictionaryRecord("ball", "míč", "míče", "míčů")
});

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{

Expand All @@ -38,7 +38,7 @@ public void LocalizerReturnsOriginalTextIfTranslationsDoesntExistInProvidedDicti
new CultureDictionaryRecord("ball", "míč", "míče", "míčů")
});

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer["car"];
Expand All @@ -52,7 +52,7 @@ public void LocalizerReturnsOriginalTextIfDictionaryIsEmpty()
{
SetupDictionary("cs", Array.Empty<CultureDictionaryRecord>());

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer["car"];
Expand All @@ -72,7 +72,7 @@ public void LocalizerFallbacksToParentCultureIfTranslationDoesntExistInSpecificC
new CultureDictionaryRecord("car", "auto", "auta", "aut")
});

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs-cz"))
{
var translation = localizer["ball"];
Expand All @@ -92,7 +92,7 @@ public void LocalizerReturnsTranslationFromSpecificCultureIfItExists()
new CultureDictionaryRecord("ball", "balón", "balóny", "balónů")
});

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs-CZ"))
{
var translation = localizer["ball"];
Expand All @@ -109,7 +109,7 @@ public void LocalizerReturnsTranslationWithSpecificContext()
new CultureDictionaryRecord("ball", "small", new [] { "míček", "míčky", "míčků" })
});

var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer["ball"];
Expand All @@ -126,7 +126,7 @@ public void LocalizerReturnsTranslationWithoutContextIfTranslationWithContextDoe
new CultureDictionaryRecord("ball", "big", new [] { "míček", "míčky", "míčků" })
});

var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer["ball"];
Expand All @@ -142,7 +142,7 @@ public void LocalizerReturnsFormattedTranslation()
new CultureDictionaryRecord("The page (ID:{0}) was deleted.", "Stránka (ID:{0}) byla smazána.")
});

var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer["The page (ID:{0}) was deleted.", 1];
Expand All @@ -158,7 +158,7 @@ public void HtmlLocalizerDoesNotFormatTwiceIfFormattedTranslationContainsCurlyBr
new CultureDictionaryRecord("The page (ID:{0}) was deleted.", "Stránka (ID:{0}) byla smazána.")
});

var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var htmlLocalizer = new PortableObjectHtmlLocalizer(localizer);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void LocalizerReturnsOriginalTextForPluralIfTranslationDoesntExist(string
new CultureDictionaryRecord("ball", "míč", "míče", "míčů"),
});

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer.Plural(count, "car", "cars");
Expand All @@ -212,7 +212,7 @@ public void LocalizerReturnsCorrectTranslationForPluralIfNoPluralFormsSpecified(

SetupDictionary(culture, new[] { new CultureDictionaryRecord("ball", translations), }, rule);

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
var translation = localizer.Plural(count, "ball", "{0} balls", count);

Assert.Equal(expected, translation);
Expand All @@ -228,7 +228,7 @@ public void LocalizerReturnsTranslationInCorrectPluralForm(string expected, int
new CultureDictionaryRecord("ball", "míč", "{0} míče", "{0} míčů"),
});

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("cs"))
{
var translation = localizer.Plural(count, "ball", "{0} balls", count);
Expand All @@ -245,7 +245,7 @@ public void LocalizerReturnsOriginalValuesIfTranslationDoesntExistAndMultiplePlu
{
SetupDictionary("en", Array.Empty<CultureDictionaryRecord>());

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("en"))
{
var translation = localizer.Plural(count, new[] { "míč", "{0} míče", "{0} míčů" }, count);
Expand All @@ -264,7 +264,7 @@ public void LocalizerReturnsCorrectPluralFormIfMultiplePluraflFormsAreSpecified(
new CultureDictionaryRecord("míč", "ball", "{0} balls")
}, PluralizationRule.English);

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger);
using (CultureScope.Create("en"))
{
var translation = localizer.Plural(count, new[] { "míč", "{0} míče", "{0} míčů" }, count);
Expand All @@ -285,7 +285,7 @@ public void LocalizerFallBackToParentCultureIfFallBackToParentUICulturesIsTrue(b

SetupDictionary("ar-YE", Array.Empty<CultureDictionaryRecord>(), PluralizationRule.Arabic);

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, fallBackToParentCulture, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, fallBackToParentCulture, _logger);
using (CultureScope.Create("ar-YE"))
{
var translation = localizer[resourceKey];
Expand Down Expand Up @@ -313,7 +313,7 @@ public void LocalizerReturnsGetAllStrings(bool includeParentCultures, string[] e
new CultureDictionaryRecord("Product", "منتج")
}, PluralizationRule.Arabic);

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, false, _logger.Object);
var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, false, _logger);
using (CultureScope.Create("ar-YE"))
{
var translations = localizer.GetAllStrings(includeParentCultures).Select(l => l.Value).ToArray();
Expand All @@ -336,7 +336,7 @@ public void LocalizerWithContextShouldCallGetDictionaryOncePerCulture(string cul
// Arrange
SetupDictionary(culture, Array.Empty<CultureDictionaryRecord>());

var localizer = new PortableObjectStringLocalizer("context", _localizationManager.Object, true, _logger.Object);
var localizer = new PortableObjectStringLocalizer("context", _localizationManager.Object, true, _logger);
CultureInfo.CurrentUICulture = new CultureInfo(culture);

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public async Task ExecuteTask_WhenToAndCcAndBccAreNotSet_ShouldFails()
private static ISmtpService CreateSmtpService(SmtpSettings settings)
{
var options = new Mock<IOptions<SmtpSettings>>();
var logger = new Mock<ILogger<SmtpService>>();
var logger = new FakeLogger<SmtpService>();
var localizer = new Mock<IStringLocalizer<SmtpService>>();
var smtp = new SmtpService(options.Object, logger.Object, localizer.Object);
var smtp = new SmtpService(options.Object, logger, localizer.Object);

options.Setup(o => o.Value).Returns(settings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task ShouldProcess(string cdnBaseUrl, string text, string expected)
cdnBaseUrl,
Enumerable.Empty<IMediaEventHandler>(),
Enumerable.Empty<IMediaCreatingEventHandler>(),
Mock.Of<ILogger<DefaultMediaFileStore>>());
new FakeLogger<DefaultMediaFileStore>());

var sanitizer = new HtmlSanitizerService(Options.Create(new HtmlSanitizerOptions()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task ShouldProcess(string cdnBaseUrl, string text, string expected)
cdnBaseUrl,
Enumerable.Empty<IMediaEventHandler>(),
Enumerable.Empty<IMediaCreatingEventHandler>(),
Mock.Of<ILogger<DefaultMediaFileStore>>());
new FakeLogger<DefaultMediaFileStore>());

var fileVersionProvider = Mock.Of<IFileVersionProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private ApiController CreateController()
Enumerable.Empty<DatabaseProvider>(),
tenantValidator,
Mock.Of<IStringLocalizer<ApiController>>(),
Mock.Of<ILogger<ApiController>>())
new FakeLogger<ApiController>())
{
ControllerContext = new ControllerContext { HttpContext = CreateHttpContext() }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task HttpRequestMessageShouldHaveCorrectSignedOAuthHeader()
);

var mockTwitterClient = new Mock<TwitterClient>(
new HttpClient(_mockFakeHttpMessageHandler.Object), Mock.Of<ILogger<TwitterClient>>())
new HttpClient(_mockFakeHttpMessageHandler.Object), new FakeLogger<TwitterClient>())
{
CallBase = true,
};
Expand Down
1 change: 1 addition & 0 deletions test/OrchardCore.Tests/OrchardCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<ItemGroup>
<PackageReference Include="AngleSharp" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="Moq" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static RegistrationController SetupRegistrationController(RegistrationSe
Mock.Of<IAuthorizationService>(),
mockSiteService,
Mock.Of<INotifier>(),
Mock.Of<ILogger<RegistrationController>>(),
new FakeLogger<RegistrationController>(),
Mock.Of<IHtmlLocalizer<RegistrationController>>(),
mockStringLocalizer.Object)
{
Expand Down
4 changes: 2 additions & 2 deletions test/OrchardCore.Tests/Recipes/RecipeExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public async Task ShouldTrimValidScriptExpression(string recipeName, string expe
.Returns(GetScopeAsync);

var recipeEventHandlers = new List<IRecipeEventHandler> { new RecipeEventHandler() };
var loggerMock = new Mock<ILogger<RecipeExecutor>>();
var logger = new FakeLogger<RecipeExecutor>();
var recipeExecutor = new RecipeExecutor(
shellHostMock.Object,
scope.ShellContext.Settings,
recipeEventHandlers,
loggerMock.Object);
logger);

// Act
var executionId = Guid.NewGuid().ToString("n");
Expand Down
1 change: 1 addition & 0 deletions test/OrchardCore.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
global using Microsoft.Extensions.Localization;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Logging.Abstractions;
global using Microsoft.Extensions.Logging.Testing;
global using Microsoft.Extensions.Options;
global using Microsoft.Extensions.Primitives;
global using Moq;
Expand Down
12 changes: 6 additions & 6 deletions test/OrchardCore.Tests/Workflows/WorkflowManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static IWorkflowScriptEvaluator CreateWorkflowScriptEvaluator(IServicePr
return new JavaScriptWorkflowScriptEvaluator(
scriptingManager,
workflowContextHandlers.Resolve(),
new Mock<ILogger<JavaScriptWorkflowScriptEvaluator>>().Object
new FakeLogger<JavaScriptWorkflowScriptEvaluator>()
);
}

Expand All @@ -100,9 +100,9 @@ WorkflowType workflowType
var workflowIdGenerator = new Mock<IWorkflowIdGenerator>();
workflowIdGenerator.Setup(x => x.GenerateUniqueId(It.IsAny<Workflow>())).Returns(IdGenerator.GenerateId());
var distributedLock = new Mock<IDistributedLock>();
var workflowManagerLogger = new Mock<ILogger<WorkflowManager>>();
var workflowContextLogger = new Mock<ILogger<WorkflowExecutionContext>>();
var missingActivityLogger = new Mock<ILogger<MissingActivity>>();
var workflowManagerLogger = new FakeLogger<WorkflowManager>();
var workflowContextLogger = new FakeLogger<WorkflowExecutionContext>();
var missingActivityLogger = new FakeLogger<MissingActivity>();
var missingActivityLocalizer = new Mock<IStringLocalizer<MissingActivity>>();
var clock = new Mock<IClock>();
var workflowFaultHandler = new Mock<IWorkflowFaultHandler>();
Expand All @@ -114,8 +114,8 @@ WorkflowType workflowType
workflowValueSerializers,
workflowFaultHandler.Object,
distributedLock.Object,
workflowManagerLogger.Object,
missingActivityLogger.Object,
workflowManagerLogger,
missingActivityLogger,
missingActivityLocalizer.Object,
clock.Object
);
Expand Down