59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using Flypaper.Core.Strategies;
|
|
using Flypaper.Tests.Fakes;
|
|
using Shouldly;
|
|
|
|
namespace Flypaper.Tests.Core;
|
|
|
|
public sealed class HtmlContentTests
|
|
{
|
|
[Fact]
|
|
public void Starts_with_a_complete_html_head()
|
|
{
|
|
var head = HtmlContent.Generate(new SeededRandomSource(1)).First();
|
|
|
|
head.ShouldStartWith("<!doctype html>");
|
|
head.ShouldContain("<head>");
|
|
head.ShouldContain("<title>");
|
|
head.ShouldContain("<style>");
|
|
head.ShouldContain("</head>");
|
|
head.ShouldContain("<body>");
|
|
}
|
|
|
|
[Fact]
|
|
public void Keeps_generating_varied_body_content()
|
|
{
|
|
var body = string.Concat(HtmlContent.Generate(new SeededRandomSource(2)).Skip(1).Take(400));
|
|
|
|
body.ShouldContain("<main>");
|
|
body.ShouldContain("<h2>");
|
|
body.ShouldContain("<p>");
|
|
body.ShouldContain("<li><a href=\"/");
|
|
body.ShouldNotContain("</html>");
|
|
body.Length.ShouldBeGreaterThan(50_000);
|
|
}
|
|
|
|
[Fact]
|
|
public void Varies_sentence_and_paragraph_lengths()
|
|
{
|
|
var paragraphs = string.Concat(HtmlContent.Generate(new SeededRandomSource(3)).Take(300))
|
|
.Split("<p>", StringSplitOptions.RemoveEmptyEntries)
|
|
.Skip(1)
|
|
.Select(p => p[..p.IndexOf("</p>", StringComparison.Ordinal)])
|
|
.ToList();
|
|
|
|
paragraphs.Select(p => p.Length).Distinct().Count().ShouldBeGreaterThan(paragraphs.Count / 2);
|
|
paragraphs.Select(p => p.Count(c => c is '.' or '?')).Distinct().Count().ShouldBeGreaterThan(3);
|
|
}
|
|
|
|
[Fact]
|
|
public void Is_deterministic_for_the_same_random_source()
|
|
{
|
|
var first = string.Concat(HtmlContent.Generate(new SeededRandomSource(4)).Take(50));
|
|
var second = string.Concat(HtmlContent.Generate(new SeededRandomSource(4)).Take(50));
|
|
var other = string.Concat(HtmlContent.Generate(new SeededRandomSource(5)).Take(50));
|
|
|
|
second.ShouldBe(first);
|
|
other.ShouldNotBe(first);
|
|
}
|
|
}
|