Erweiterungsmethode hinzugefügt, um IStringLocalizer in ein dynamisches Objekt zu konvertieren.

This commit is contained in:
Developer 02
2024-06-24 14:34:24 +02:00
parent b6adf7ed8b
commit e554197089
4 changed files with 61 additions and 0 deletions

View 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);
}
}
}