Erweiterungsmethode hinzugefügt, um IStringLocalizer in ein dynamisches Objekt zu konvertieren.
This commit is contained in:
31
DigitalData.Core.Tests/API/StringLocalizerExtensionsTests.cs
Normal file
31
DigitalData.Core.Tests/API/StringLocalizerExtensionsTests.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Moq;
|
||||
using DigitalData.Core.API;
|
||||
|
||||
namespace DigitalData.Core.Tests.API
|
||||
{
|
||||
[TestFixture]
|
||||
public class StringLocalizerExtensionsTests
|
||||
{
|
||||
[Test]
|
||||
public void ToDynamic_ShouldReturnDynamicObject_WithLocalizedStrings()
|
||||
{
|
||||
// Arrange
|
||||
var localizedStrings = new List<LocalizedString>
|
||||
{
|
||||
new ("Key1", "Value1"),
|
||||
new ("Key2", "Value2"),
|
||||
};
|
||||
|
||||
var mockLocalizer = new Mock<IStringLocalizer>();
|
||||
mockLocalizer.Setup(l => l.GetAllStrings(It.IsAny<bool>())).Returns(localizedStrings);
|
||||
|
||||
// Act
|
||||
dynamic result = mockLocalizer.Object.ToDynamic();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Value1", result.Key1);
|
||||
Assert.AreEqual("Value2", result.Key2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user