mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
test: adds unit, integration and security test projects for the web project
This commit is contained in:
1 parent
7b56033a15
commit
7ad7ad308e
70 files changed
+4993
No files matched your search
+74
@@ -0,0 +1,74 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Localization;
|
||||
using Microsoft.AspNetCore.Mvc.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.UnitTests.Common.Localization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CoreHtmlLocalizerFactory"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CoreHtmlLocalizerFactoryTests
|
||||
{
|
||||
private readonly IStringLocalizerFactory _mockStringLocalizerFactory;
|
||||
private readonly CoreHtmlLocalizerFactory _sut;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CoreHtmlLocalizerFactoryTests"/> class.
|
||||
/// </summary>
|
||||
public CoreHtmlLocalizerFactoryTests()
|
||||
{
|
||||
_mockStringLocalizerFactory = Substitute.For<IStringLocalizerFactory>();
|
||||
_mockStringLocalizerFactory.Create(Arg.Any<string>(), Arg.Any<string>()).Returns(Substitute.For<IStringLocalizer>());
|
||||
_sut = new CoreHtmlLocalizerFactory(_mockStringLocalizerFactory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenBaseNameStartsWithLocationCorePrefix_ShouldStripCoreSegment()
|
||||
{
|
||||
// Act
|
||||
IHtmlLocalizer localizer = _sut.Create("Lumina.Presentation.Web.Core.Views.Auth.Login", "Lumina.Presentation.Web");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(localizer);
|
||||
_mockStringLocalizerFactory.Received(1).Create("Lumina.Presentation.Web.Views.Auth.Login", "Lumina.Presentation.Web");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenBaseNameDoesNotStartWithLocationCorePrefix_ShouldKeepBaseNameUnchanged()
|
||||
{
|
||||
// Act
|
||||
IHtmlLocalizer localizer = _sut.Create("Lumina.Presentation.Web.Views.Shared.Layout", "Lumina.Presentation.Web");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(localizer);
|
||||
_mockStringLocalizerFactory.Received(1).Create("Lumina.Presentation.Web.Views.Shared.Layout", "Lumina.Presentation.Web");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenResourceSourceTypeProvided_ShouldCreateLocalizerForType()
|
||||
{
|
||||
// Arrange
|
||||
_mockStringLocalizerFactory.Create(Arg.Any<Type>()).Returns(Substitute.For<IStringLocalizer>());
|
||||
|
||||
// Act
|
||||
IHtmlLocalizer localizer = _sut.Create(typeof(TestLocalizationResource));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(localizer);
|
||||
_mockStringLocalizerFactory.Received(1).Create(typeof(TestLocalizationResource));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marker type used for the resource source based localizer creation test.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
private sealed class TestLocalizationResource
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user