42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using Heimdall.Application.Common;
|
|||
|
|
using Heimdall.Application.Tests.Common;
|
||
|
|
using Heimdall.Domain.Entities;
|
||
|
|
using Heimdall.Infrastructure.Settings;
|
||
|
|
using NSubstitute;
|
||
|
|
using Shouldly;
|
||
|
|
|
||
|
|
namespace Heimdall.Infrastructure.Tests.Settings;
|
||
|
|
|
||
|
|
public sealed class AppSettingReaderTests
|
||
|
|
{
|
||
|
|
[Theory]
|
||
|
|
[InlineData("email.smtpHost", "email.smtphost", "mailpit")]
|
||
|
|
[InlineData("email.smtpPort", "email.smtpport", "1025")]
|
||
|
|
[InlineData("email.fromAddress", "email.fromaddress", "synthetic@example.invalid")]
|
||
|
|
[InlineData("email.useSsl", "email.usessl", "false")]
|
||
|
|
[InlineData("ai.cpaiUrl", "ai.cpaiurl", "http://codeproject-ai")]
|
||
|
|
[InlineData("ai.ollamaUrl", "ai.ollamaurl", "http://ollama")]
|
||
|
|
public async Task GetAsync_NormalizesKeyLikeSettingsUi(string requestedKey, string storedKey, string value)
|
||
|
|
{
|
||
|
|
var db = Substitute.For<IApplicationDbContext>();
|
||
|
|
db.AppSettings.Returns(MockDbSetHelper.CreateFor([new AppSetting(storedKey, value)]));
|
||
|
|
|
||
|
|
var result = await AppSettingReader.GetAsync(db, requestedKey);
|
||
|
|
|
||
|
|
result.ShouldBe(value);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Theory]
|
||
|
|
[InlineData(null)]
|
||
|
|
[InlineData("")]
|
||
|
|
[InlineData(" ")]
|
||
|
|
public async Task GetAsync_EmptyKey_ReturnsNullWithoutQuery(string? key)
|
||
|
|
{
|
||
|
|
var db = Substitute.For<IApplicationDbContext>();
|
||
|
|
db.AppSettings.Returns(MockDbSetHelper.CreateFor<AppSetting>([]));
|
||
|
|
|
||
|
|
var result = await AppSettingReader.GetAsync(db, key!);
|
||
|
|
|
||
|
|
result.ShouldBeNull();
|
||
|
|
}
|
||
|
|
}
|