Vertaalbestanden 4/6: Offerings-validatiemeldingen naar Texts/nl.json en en.json (offerings.validation.*)
GEDRAGSWIJZIGING (goedgekeurd): de validatiemeldingen waren Engels en zijn nu Nederlands bij Texts:DefaultLanguage=nl (alleen zichtbaar voor beheerders). De Engelse teksten zijn de oude meldingen, letterlijk. TextCatalog.Default omvat nu alle geladen SlpModularCms.*-assemblies (fallback buiten DI). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using FluentAssertions;
|
||||
using SlpModularCms.Core.Texts;
|
||||
using SlpModularCms.Modules.Offerings.Models;
|
||||
|
||||
namespace SlpModularCms.Modules.Offerings.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The validation messages moved into the text files. The English texts are exactly the messages that were in the code;
|
||||
/// the Dutch ones are NEW (the messages used to be English only): with the site language Dutch an administrator now gets
|
||||
/// Dutch validation messages. That is the one deliberate change of behaviour of the translation work.
|
||||
/// </summary>
|
||||
public class OfferingsTextsTests
|
||||
{
|
||||
private static readonly TextCatalog Catalog = TextCatalog.CreateDefault(typeof(OfferingsTexts).Assembly);
|
||||
|
||||
[Fact]
|
||||
public void TheTextFiles_MatchTheDeclaredKeys_InDutchAndEnglish()
|
||||
=> TextAudit.Verify(typeof(OfferingsTexts).Assembly, TextAudit.KeysOf(typeof(OfferingsTexts)), "nl", "en").Should().BeEmpty();
|
||||
|
||||
[Theory]
|
||||
[InlineData("features.notAList", "Features must be a list of strings.")]
|
||||
[InlineData("features.count", "Features must contain between {min} and {max} items.")]
|
||||
[InlineData("features.item", "Each feature must be non-empty and at most {max} characters.")]
|
||||
[InlineData("banner.position", "Position must be 'top' or 'bottom'.")]
|
||||
[InlineData("banner.topTextTooLong", "A top banner text can be at most {max} characters.")]
|
||||
[InlineData("banner.bottomNeedsTitle", "A bottom banner needs a title.")]
|
||||
[InlineData("banner.linkTogether", "Link label and link URL must be given together.")]
|
||||
[InlineData("banner.linkNotAllowed", "Link URL must be an https:// address or a site path starting with '/'.")]
|
||||
[InlineData("schedule.endAfterStart", "EndsAt must be after StartsAt.")]
|
||||
public void TheEnglishTexts_AreTheMessagesThatWereInTheCode(string key, string expected)
|
||||
=> Catalog.Get(new TextKey("offerings.validation." + key, "min", "max"), "en", ("min", "{min}"), ("max", "{max}")).Should().Be(expected);
|
||||
|
||||
[Fact]
|
||||
public void WithTheSiteLanguageDutch_TheValidationMessagesAreDutch()
|
||||
{
|
||||
var banner = new OfferingBannerRequest("", "Tekst", Position: "bottom");
|
||||
var results = new List<ValidationResult>();
|
||||
|
||||
Validator.TryValidateObject(banner, new ValidationContext(banner), results, validateAllProperties: false);
|
||||
|
||||
results.Should().ContainSingle().Which.ErrorMessage.Should().Be("Een banner onderaan heeft een titel nodig.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheFeaturesMessages_CarryTheirLimits()
|
||||
{
|
||||
var attribute = new FeaturesValidationAttribute();
|
||||
|
||||
var tooMany = attribute.GetValidationResult(Enumerable.Repeat("x", 11).ToList(), new ValidationContext(new object()) { MemberName = "Features" });
|
||||
var tooLong = attribute.GetValidationResult(new List<string> { new('x', 201) }, new ValidationContext(new object()) { MemberName = "Features" });
|
||||
|
||||
tooMany!.ErrorMessage.Should().Be("Kenmerken moeten tussen 1 en 10 items bevatten.");
|
||||
tooLong!.ErrorMessage.Should().Be("Elk kenmerk mag niet leeg zijn en maximaal 200 tekens bevatten.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheScheduleMessage_IsShared_ByOfferingsAndBanners()
|
||||
{
|
||||
var starts = DateTimeOffset.UtcNow;
|
||||
var offering = new CreateOfferingRequest("T", null, "p", null, ["f"], "c", StartsAt: starts, EndsAt: starts);
|
||||
|
||||
offering.Validate(new ValidationContext(offering)).Should().ContainSingle()
|
||||
.Which.ErrorMessage.Should().Be("Het einde moet na het begin liggen.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user