76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
using Heimdall.Infrastructure.Services.Discovery;
|
|||
|
|
using Microsoft.Extensions.Logging;
|
||
|
|
using NSubstitute;
|
||
|
|
using Shouldly;
|
||
|
|
|
||
|
|
namespace Heimdall.Infrastructure.Tests;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Unit tests for StreamTesterService.
|
||
|
|
/// Tests focus on session management and lifecycle.
|
||
|
|
/// Network-dependent tests (RTSP/HTTP connects) belong in integration tests.
|
||
|
|
/// </summary>
|
||
|
|
public class StreamTesterServiceTests
|
||
|
|
{
|
||
|
|
private readonly IHttpClientFactory _httpClientFactory = Substitute.For<IHttpClientFactory>();
|
||
|
|
private readonly ILogger<StreamTesterService> _logger = Substitute.For<ILogger<StreamTesterService>>();
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task CreateSession_ReturnsValidSession()
|
||
|
|
{
|
||
|
|
var service = new StreamTesterService(_httpClientFactory, _logger);
|
||
|
|
var request = new Application.DTOs.StreamTestRequest("test", ["rtsp://192.168.1.100:554/stream1"]);
|
||
|
|
var session = await service.CreateSessionAsync(request);
|
||
|
|
|
||
|
|
session.ShouldNotBeNull();
|
||
|
|
session.SessionId.ShouldNotBe(Guid.Empty);
|
||
|
|
session.Status.ShouldBe("running");
|
||
|
|
session.Total.ShouldBe(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task CreateAndCancelSession_ReturnsCancelled()
|
||
|
|
{
|
||
|
|
var service = new StreamTesterService(_httpClientFactory, _logger);
|
||
|
|
var request = new Application.DTOs.StreamTestRequest("test", ["rtsp://192.168.1.100:554/stream1"]);
|
||
|
|
|
||
|
|
var session = await service.CreateSessionAsync(request);
|
||
|
|
await service.CancelSessionAsync(session.SessionId);
|
||
|
|
|
||
|
|
var cancelled = await service.GetSessionAsync(session.SessionId);
|
||
|
|
cancelled.ShouldNotBeNull();
|
||
|
|
cancelled.Status.ShouldBe("cancelled");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task GetSession_NotFound_ReturnsNull()
|
||
|
|
{
|
||
|
|
var service = new StreamTesterService(_httpClientFactory, _logger);
|
||
|
|
var result = await service.GetSessionAsync(Guid.NewGuid());
|
||
|
|
result.ShouldBeNull();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task CancelSession_UnknownId_DoesNotThrow()
|
||
|
|
{
|
||
|
|
var service = new StreamTesterService(_httpClientFactory, _logger);
|
||
|
|
await service.CancelSessionAsync(Guid.NewGuid());
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task CreateSession_MultipleUrls_CreatesCorrectCount()
|
||
|
|
{
|
||
|
|
var service = new StreamTesterService(_httpClientFactory, _logger);
|
||
|
|
var urls = new[]
|
||
|
|
{
|
||
|
|
"rtsp://192.168.1.100:554/stream1",
|
||
|
|
"rtsp://192.168.1.101:554/stream1",
|
||
|
|
"http://192.168.1.102:80/mjpeg",
|
||
|
|
};
|
||
|
|
var request = new Application.DTOs.StreamTestRequest("test", urls);
|
||
|
|
var session = await service.CreateSessionAsync(request);
|
||
|
|
|
||
|
|
session.Total.ShouldBe(3);
|
||
|
|
session.Status.ShouldBe("running");
|
||
|
|
}
|
||
|
|
}
|