Files
live_recorder/tests/LiveRecorder.Tests/LiveRoomPollingDecisionTests.cs
T

72 lines
2.1 KiB
C#

using LiveRecorder.Domain.Entities;
using LiveRecorder.Domain.Enums;
using LiveRecorder.Infrastructure.Services;
namespace LiveRecorder.Tests;
public sealed class LiveRoomPollingDecisionTests
{
private const string ActiveCode = "skipped_active_session";
private const string ActiveSummary = "Auto-start skipped because an active recording session already exists.";
[Fact]
public void HasAutoStartDecisionChanged_ReturnsFalseForSameActiveSession()
{
var room = CreateRoom();
var sessionId = Guid.NewGuid();
room.SetLastAutoStartDecision(
ActiveCode,
ActiveSummary,
$"activeSessionId={sessionId}",
DateTimeOffset.UtcNow.AddMinutes(-1));
var changed = LiveRoomPollingBackgroundService.HasAutoStartDecisionChanged(
room,
ActiveCode,
ActiveSummary,
$"activeSessionId={sessionId}");
Assert.False(changed);
}
[Fact]
public void HasAutoStartDecisionChanged_ReturnsTrueForNewActiveSession()
{
var room = CreateRoom();
room.SetLastAutoStartDecision(
ActiveCode,
ActiveSummary,
$"activeSessionId={Guid.NewGuid()}",
DateTimeOffset.UtcNow.AddMinutes(-1));
var changed = LiveRoomPollingBackgroundService.HasAutoStartDecisionChanged(
room,
ActiveCode,
ActiveSummary,
$"activeSessionId={Guid.NewGuid()}");
Assert.True(changed);
}
[Fact]
public void HasAutoStartDecisionChanged_ReturnsTrueForFirstSkipDecision()
{
var room = CreateRoom();
var changed = LiveRoomPollingBackgroundService.HasAutoStartDecisionChanged(
room,
ActiveCode,
ActiveSummary,
$"activeSessionId={Guid.NewGuid()}");
Assert.True(changed);
}
private static LiveRoom CreateRoom() => new(
LivePlatformType.Douyin,
"https://live.douyin.com/123456",
"123456",
"https://live.douyin.com/123456",
DateTimeOffset.UtcNow);
}