164 lines
4.6 KiB
C#
164 lines
4.6 KiB
C#
using Heimdall.Domain.Entities;
|
|
using Heimdall.Domain.Enums;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Domain.Tests.Entities;
|
|
|
|
public class CameraTests
|
|
{
|
|
[Fact]
|
|
public void Create_camera_should_set_properties()
|
|
{
|
|
var siteId = Guid.NewGuid();
|
|
var camera = new Camera(siteId, "Caméra Entrée", "rtsp://192.168.1.100:554/stream1");
|
|
|
|
camera.Id.ShouldNotBe(Guid.Empty);
|
|
camera.SiteId.ShouldBe(siteId);
|
|
camera.Name.ShouldBe("Caméra Entrée");
|
|
camera.RtspUrl.ShouldBe("rtsp://192.168.1.100:554/stream1");
|
|
camera.Status.ShouldBe(CameraStatus.Disabled);
|
|
}
|
|
|
|
[Fact]
|
|
public void Assign_agent_should_set_agent_id()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
var agentId = Guid.NewGuid();
|
|
|
|
camera.AssignAgent(agentId);
|
|
|
|
camera.AgentId.ShouldBe(agentId);
|
|
}
|
|
|
|
[Fact]
|
|
public void Assign_agent_with_null_should_clear_agent_id()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
camera.AssignAgent(Guid.NewGuid());
|
|
|
|
camera.AssignAgent(null);
|
|
|
|
camera.AgentId.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Set_status_should_update_status()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SetStatus(CameraStatus.Online);
|
|
|
|
camera.Status.ShouldBe(CameraStatus.Online);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetCapabilities_should_update_capability_flags()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SetCapabilities(true, false, true);
|
|
|
|
camera.HasPtz.ShouldBeTrue();
|
|
camera.HasAudio.ShouldBeFalse();
|
|
camera.HasMotionDetection.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void SetCredentials_should_set_credentials()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
var creds = new CameraCredentials(camera.Id);
|
|
|
|
camera.SetCredentials(creds);
|
|
|
|
camera.Credentials.ShouldBe(creds);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetDetectionProfile_should_set_profile()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
var profile = new CameraDetectionProfile(camera.Id);
|
|
|
|
camera.SetDetectionProfile(profile);
|
|
|
|
camera.DetectionProfile.ShouldBe(profile);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetDiscoveryInfo_should_update_discovery_fields()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SetDiscoveryInfo(CameraDiscoveryMethod.OnvifWsDiscovery,
|
|
DetectedCameraType.Standard, "00:11:22:33:44:55", "192.168.1.100");
|
|
|
|
camera.DiscoveryMethod.ShouldBe(CameraDiscoveryMethod.OnvifWsDiscovery);
|
|
camera.DetectedType.ShouldBe(DetectedCameraType.Standard);
|
|
camera.MacAddress.ShouldBe("00:11:22:33:44:55");
|
|
camera.IpAddress.ShouldBe("192.168.1.100");
|
|
camera.LastDiscoveredAt.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void SetPorts_should_update_ports()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SetPorts(554, 80, 3702);
|
|
|
|
camera.RtspPort.ShouldBe(554);
|
|
camera.HttpPort.ShouldBe(80);
|
|
camera.OnvifPort.ShouldBe(3702);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetCapabilityFlags_should_update_capabilities()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SetCapabilityFlags(CameraCapability.RtspStreaming | CameraCapability.Onvif);
|
|
|
|
camera.Capabilities.ShouldBe(CameraCapability.RtspStreaming | CameraCapability.Onvif);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetStreamTestResult_should_update_stream_fields()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SetStreamTestResult("rtsp://sub.stream", "[\"H264\"]", 1280, 720, 50);
|
|
|
|
camera.SubRtspUrl.ShouldBe("rtsp://sub.stream");
|
|
camera.LastTestedCodecs.ShouldBe("[\"H264\"]");
|
|
camera.LastTestedWidth.ShouldBe(1280);
|
|
camera.LastTestedHeight.ShouldBe(720);
|
|
camera.LastTestedLatencyMs.ShouldBe(50);
|
|
camera.LastStreamTestAt.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_should_change_properties()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Old Name", "rtsp://old");
|
|
|
|
camera.Update("New Name", "Hikvision", "DS-2CD", "rtsp://new");
|
|
|
|
camera.Name.ShouldBe("New Name");
|
|
camera.Manufacturer.ShouldBe("Hikvision");
|
|
camera.Model.ShouldBe("DS-2CD");
|
|
camera.RtspUrl.ShouldBe("rtsp://new");
|
|
}
|
|
|
|
[Fact]
|
|
public void SoftDelete_should_set_deleted_flag()
|
|
{
|
|
var camera = new Camera(Guid.NewGuid(), "Camera-1");
|
|
|
|
camera.SoftDelete();
|
|
|
|
camera.IsDeleted.ShouldBeTrue();
|
|
camera.DeletedAt.ShouldNotBeNull();
|
|
}
|
|
}
|