diff --git a/backend/FwLite/MiniLcm.Tests/Validators/EntryValidatorTests.cs b/backend/FwLite/MiniLcm.Tests/Validators/EntryValidatorTests.cs index 46c34ff27..63c033415 100644 --- a/backend/FwLite/MiniLcm.Tests/Validators/EntryValidatorTests.cs +++ b/backend/FwLite/MiniLcm.Tests/Validators/EntryValidatorTests.cs @@ -128,11 +128,11 @@ public void Succeeds_WhenComplexFormsContainEmptyGuid() } [Fact] - public void Succeeds_WhenComponentsContainEmptyGuid() + public void Fails_WhenComponentsContainEmptyGuid() { var entryId = Guid.NewGuid(); var entry = new Entry() { Id = entryId, LexemeForm = new MultiString(){{"en", "lexeme"}}, Components = [new ComplexFormComponent(){ ComplexFormEntryId = entryId, ComponentEntryId = Guid.Empty }] }; - _validator.TestValidate(entry).ShouldNotHaveAnyValidationErrors(); + _validator.TestValidate(entry).ShouldHaveValidationErrorFor("Components[0]"); } private void SetProperty(Entry entry, string propName, string content) diff --git a/backend/FwLite/MiniLcm/Validators/EntryValidator.cs b/backend/FwLite/MiniLcm/Validators/EntryValidator.cs index e2cc980fb..986caaf86 100644 --- a/backend/FwLite/MiniLcm/Validators/EntryValidator.cs +++ b/backend/FwLite/MiniLcm/Validators/EntryValidator.cs @@ -13,6 +13,7 @@ public EntryValidator() RuleFor(e => e.LiteralMeaning).NoEmptyValues(); RuleFor(e => e.Note).NoEmptyValues(); RuleForEach(e => e.Senses).SetValidator(entry => new SenseValidator(entry)); + RuleForEach(e => e.Components).Must(NotBeEmptyComponentReference); RuleForEach(e => e.Components).Must(NotBeComponentSelfReference); RuleForEach(e => e.Components).Must(HaveCorrectComponentEntryReference); RuleForEach(e => e.ComplexForms).Must(NotBeComplexFormSelfReference); @@ -23,13 +24,19 @@ public EntryValidator() RuleForEach(e => e.ComplexFormTypes).SetValidator(new ComplexFormTypeValidator()); } + private bool NotBeEmptyComponentReference(Entry entry, ComplexFormComponent component) + { + return component.ComponentEntryId != Guid.Empty; + } + private bool NotBeComponentSelfReference(Entry entry, ComplexFormComponent component) { - return component.ComponentEntryId != entry.Id || component.ComponentEntryId == Guid.Empty; + return component.ComponentEntryId != entry.Id; } private bool HaveCorrectComponentEntryReference(Entry entry, ComplexFormComponent component) { + // Empty GUID is okay here because it can be guessed from the parent object return component.ComplexFormEntryId == entry.Id || component.ComplexFormEntryId == Guid.Empty; } @@ -40,6 +47,7 @@ private bool NotBeComplexFormSelfReference(Entry entry, ComplexFormComponent com private bool HaveCorrectComplexFormEntryReference(Entry entry, ComplexFormComponent component) { + // Empty GUID is okay here because it can be guessed from the parent object return component.ComponentEntryId == entry.Id || component.ComponentEntryId == Guid.Empty; } }