Skip to content

Commit

Permalink
Add entry validation tests for literal meaning, note
Browse files Browse the repository at this point in the history
Refactored citation form tests to be more generic so they can be resued
for other similar fields.
  • Loading branch information
rmunn committed Jan 6, 2025
1 parent dcf2aef commit 4dd4032
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions backend/FwLite/MiniLcm.Tests/Validators/EntryValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,49 @@ public void Fails_WhenLexemeFormHasWsWithEmptyContent()
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", ""}} };
_validator.TestValidate(entry).ShouldHaveValidationErrorFor("LexemeForm");
}
//

[Fact]
public void Succeeds_WhenCitationFormIsPresent()
[Theory]
[InlineData("CitationForm")]
[InlineData("LiteralMeaning")]
[InlineData("Note")]
public void Succeeds_WhenNonEmptyFieldIsPresent(string fieldName)
{
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", "lexeme"}}, CitationForm = new MultiString(){{"en", "citation"}} };
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", "lexeme"}} };
SetProperty(entry, fieldName, "content");
_validator.TestValidate(entry).ShouldNotHaveAnyValidationErrors();
}

[Fact]
public void Succeeds_WhenCitationFormIsMissing()
[Theory]
[InlineData("CitationForm")]
[InlineData("LiteralMeaning")]
[InlineData("Note")]
public void Succeeds_WhenNonEmptyFieldHasNoContent(string fieldName)
{
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", "lexeme"}} };
MakePropertyEmpty(entry, fieldName);
_validator.TestValidate(entry).ShouldNotHaveAnyValidationErrors();
}

[Fact]
public void Succeeds_WhenCitationFormHasNoContent()
[Theory]
[InlineData("CitationForm")]
[InlineData("LiteralMeaning")]
[InlineData("Note")]
public void Failss_WhenNonEmptyFieldHasWsWithEmptyContent(string fieldName)
{
// Technically the same as Succeeds_WhenCitationFormIsMissing -- should we combine them?
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", "lexeme"}}, CitationForm = new MultiString() };
_validator.TestValidate(entry).ShouldNotHaveAnyValidationErrors();
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", "lexeme"}} };
SetProperty(entry, fieldName, "");
_validator.TestValidate(entry).ShouldHaveValidationErrorFor(fieldName);
}

[Fact]
public void Fails_WhenCitationFormHasWsWithEmptyContent()
private void SetProperty(Entry entry, string propName, string content)
{
var entry = new Entry() { Id = Guid.NewGuid(), LexemeForm = new MultiString(){{"en", "lexeme"}}, CitationForm = new MultiString(){{"en", ""}} };
_validator.TestValidate(entry).ShouldHaveValidationErrorFor("CitationForm");
var propInfo = typeof(Entry).GetProperty(propName);
propInfo?.SetValue(entry, new MultiString(){{"en", content}});
}

// TODO: That's extremely similar to the LexemeForm tests except for the missing/no content tests.
// And we'll need to write similar tests for LiteralMeaning and Note. A test helper method is clearly needed here.
private void MakePropertyEmpty(Entry entry, string propName)
{
var propInfo = typeof(Entry).GetProperty(propName);
propInfo?.SetValue(entry, new MultiString());
}
}

0 comments on commit 4dd4032

Please sign in to comment.