Files
Heimdall/tests/Heimdall.Domain.Tests/Entities/PersonTests.cs
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

122 lines
3.1 KiB
C#

using Heimdall.Domain.Entities;
using Shouldly;
namespace Heimdall.Domain.Tests.Entities;
public class PersonTests
{
[Fact]
public void Create_person_should_set_properties()
{
var person = new Person("John Doe", "family");
person.DisplayName.ShouldBe("John Doe");
person.Category.ShouldBe("family");
}
[Fact]
public void Create_person_without_category()
{
var person = new Person("Unknown");
person.Category.ShouldBeNull();
person.IsWatchlisted.ShouldBeFalse();
}
[Fact]
public void Update_should_change_all_properties()
{
var person = new Person("Old Name", "family");
person.Update("New Name", "Some notes", "watchlist", true);
person.DisplayName.ShouldBe("New Name");
person.Notes.ShouldBe("Some notes");
person.Category.ShouldBe("watchlist");
person.IsWatchlisted.ShouldBeTrue();
}
[Fact]
public void SetPhoto_should_update_photo_url()
{
var person = new Person("John Doe");
person.SetPhoto("https://example.com/photo.jpg");
person.PhotoUrl.ShouldBe("https://example.com/photo.jpg");
}
[Fact]
public void AddFace_should_add_to_collection()
{
var person = new Person("John Doe");
var face = new KnownFace(person.Id, [0.1f, 0.2f, 0.3f]);
person.AddFace(face);
person.Faces.Count.ShouldBe(1);
person.Faces.ShouldContain(face);
}
[Fact]
public void Faces_collection_should_be_readonly()
{
var person = new Person("John Doe");
person.Faces.ShouldBeEmpty();
}
}
public class KnownFaceTests
{
[Fact]
public void Create_knownface_should_set_properties()
{
var personId = Guid.NewGuid();
var embedding = new float[] { 0.1f, 0.2f, 0.3f, 0.4f };
var face = new KnownFace(personId, embedding, "thumb.jpg", "evt-123");
face.PersonId.ShouldBe(personId);
face.Embedding.ShouldBe(embedding);
face.ThumbnailUrl.ShouldBe("thumb.jpg");
face.SourceEventId.ShouldBe("evt-123");
}
[Fact]
public void Create_knownface_minimal()
{
var face = new KnownFace(Guid.NewGuid(), [0.5f, 0.6f]);
face.ThumbnailUrl.ShouldBeNull();
face.SourceEventId.ShouldBeNull();
}
[Fact]
public void Create_knownface_should_copy_embedding_to_prevent_mutation()
{
var input = new[] { 0.1f, 0.2f };
var face = new KnownFace(Guid.NewGuid(), input);
input[0] = 0.9f;
face.Embedding[0].ShouldBe(0.1f);
}
[Theory]
[InlineData(float.NaN)]
[InlineData(float.PositiveInfinity)]
public void Create_knownface_should_reject_non_finite_values(float invalidValue)
{
Should.Throw<ArgumentException>(() => new KnownFace(Guid.NewGuid(), [invalidValue]));
}
[Fact]
public void Create_knownface_should_reject_embedding_over_limit()
{
var embedding = new float[KnownFace.MaxEmbeddingDimensions + 1];
Should.Throw<ArgumentException>(() => new KnownFace(Guid.NewGuid(), embedding));
}
}