using Heimdall.Cameras.Domain; using Shouldly; using Xunit; namespace Heimdall.Migration.Domain.Tests; public sealed class CameraTests { [Fact] public void Register_ValidInput_PreservesReferences() { Guid id = Guid.NewGuid(); Guid tenant = Guid.NewGuid(); Guid site = Guid.NewGuid(); Guid secret = Guid.NewGuid(); Camera camera = Camera.Register(id, tenant, site, " Entrée ", "rtsp://camera.example/stream", secret); camera.Id.ShouldBe(id); camera.TenantId.ShouldBe(tenant); camera.SiteId.ShouldBe(site); camera.Name.ShouldBe("Entrée"); camera.CredentialReference.ShouldBe(secret); camera.IsEnabled.ShouldBeTrue(); } [Theory] [InlineData("https://camera.example/stream")] [InlineData("rtsp://user:password@camera.example/stream")] [InlineData("rtsp://camera.example/stream?token=sensitive")] [InlineData("rtsp://camera.example/stream#sensitive")] [InlineData("relative/stream")] [InlineData("")] public void Register_InvalidStream_RejectsWithoutEchoingInput(string stream) { CamerasDomainException error = Should.Throw(() => Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Camera", stream)); error.Message.ShouldNotContain("sensitive"); error.Message.ShouldNotContain("password"); } [Theory] [InlineData(0)] [InlineData(1)] [InlineData(2)] public void Register_MissingIdentity_RejectsCamera(int missing) { Should.Throw(() => Camera.Register( missing == 0 ? Guid.Empty : Guid.NewGuid(), missing == 1 ? Guid.Empty : Guid.NewGuid(), missing == 2 ? Guid.Empty : Guid.NewGuid(), "Camera", "rtsp://camera.example/stream")); } [Fact] public void Update_InvalidSecretReference_PreservesAllConfiguration() { Guid secret = Guid.NewGuid(); Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Avant", "rtsp://camera.example/old", secret); Should.Throw(() => camera.Update("Après", "rtsps://camera.example/new", Guid.Empty)); camera.Name.ShouldBe("Avant"); camera.StreamUri.AbsoluteUri.ShouldBe("rtsp://camera.example/old"); camera.CredentialReference.ShouldBe(secret); } [Fact] public void Update_InvalidStream_PreservesPreviousState() { Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Avant", "rtsp://camera.example/old"); Should.Throw(() => camera.Update("Après", "relative", null)); camera.Name.ShouldBe("Avant"); camera.StreamUri.AbsoluteUri.ShouldBe("rtsp://camera.example/old"); } [Fact] public void Update_ValidConfiguration_RemovesSecretReferenceWithoutEnabling() { Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Avant", "rtsp://camera.example/old", Guid.NewGuid()); camera.Disable(); camera.Update(" Après ", "rtsps://camera.example/new", null); camera.Name.ShouldBe("Après"); camera.StreamUri.Scheme.ShouldBe("rtsps"); camera.CredentialReference.ShouldBeNull(); camera.IsEnabled.ShouldBeFalse(); } [Fact] public void Disable_RepeatedCall_PreservesConfiguration() { Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Camera", "rtsp://camera.example/stream"); camera.Disable(); camera.Disable(); camera.IsEnabled.ShouldBeFalse(); camera.Name.ShouldBe("Camera"); } }