using System.Text; using Flypaper.Core.Models; using Flypaper.Core.Strategies; using Flypaper.Tests.Fakes; using Shouldly; namespace Flypaper.Tests.Core; public sealed class HtmlDripStrategyTests { [Fact] public async Task Drips_html_in_small_chunks_until_cancelled() { var strategy = CreateStrategy(); var channel = new FakeTrapChannel(); using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(300)); await Should.ThrowAsync(() => strategy.RunAsync(channel, cts.Token)); channel.Writes.Count.ShouldBeGreaterThan(5); channel.Writes.ShouldAllBe(write => write.Length >= 1 && write.Length <= 64); Encoding.UTF8.GetString(channel.Writes.SelectMany(write => write).ToArray()).ShouldStartWith(""); } [Theory] [InlineData(TrapProtocol.Http, true)] [InlineData(TrapProtocol.Ssh, false)] public void Supports_only_http(TrapProtocol protocol, bool expected) => CreateStrategy().Supports(protocol).ShouldBe(expected); private static HtmlDripStrategy CreateStrategy() => new( TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(1), MaxDelay = TimeSpan.FromMilliseconds(5) }), new SeededRandomSource(21), TimeProvider.System); }