Files
Nexus.Reader/tests/NexusReader.Application.Tests/Services/PaywallParserTests.cs
T

82 lines
2.5 KiB
C#

using System;
using FluentAssertions;
using NexusReader.UI.Shared.Services;
using Xunit;
namespace NexusReader.Application.Tests.Services;
public class PaywallParserTests
{
[Fact]
public void TryParsePaywallTrigger_WithValidSimpleToken_ReturnsTrueAndCorrectValues()
{
// Arrange
var guid = Guid.NewGuid();
var rawText = $"Teaser sentence. [PAYWALL_TRIGGER:{guid}:Clean Book Title:45:82]";
// Act
var result = PaywallParser.TryParsePaywallTrigger(
rawText,
out var teaser,
out var bookId,
out var title,
out var localScore,
out var globalScore);
// Assert
result.Should().BeTrue();
teaser.Should().Be("Teaser sentence.");
bookId.Should().Be(guid);
title.Should().Be("Clean Book Title");
localScore.Should().Be(45);
globalScore.Should().Be(82);
}
[Fact]
public void TryParsePaywallTrigger_WithColonsInBookTitle_ReturnsTrueAndCorrectValues()
{
// Arrange
var guid = Guid.NewGuid();
var rawText = $"Teaser text. [PAYWALL_TRIGGER:{guid}:Architektura: .NET 10 i C# 14:15:99]";
// Act
var result = PaywallParser.TryParsePaywallTrigger(
rawText,
out var teaser,
out var bookId,
out var title,
out var localScore,
out var globalScore);
// Assert
result.Should().BeTrue();
teaser.Should().Be("Teaser text.");
bookId.Should().Be(guid);
title.Should().Be("Architektura: .NET 10 i C# 14");
localScore.Should().Be(15);
globalScore.Should().Be(99);
}
[Theory]
[InlineData("")]
[InlineData("Just plain text with no trigger token.")]
[InlineData("Plain text [PAYWALL_TRIGGER:invalid-guid:Title:50:80]")]
[InlineData("Plain text [PAYWALL_TRIGGER:00000000-0000-0000-0000-000000000000:Title:50:invalid]")]
[InlineData("Plain text [PAYWALL_TRIGGER:00000000-0000-0000-0000-000000000000:Title:invalid:80]")]
[InlineData("Plain text [PAYWALL_TRIGGER:00000000-0000-0000-0000-000000000000:Title]")]
public void TryParsePaywallTrigger_WithInvalidInputs_ReturnsFalse(string rawText)
{
// Act
var result = PaywallParser.TryParsePaywallTrigger(
rawText,
out var teaser,
out var bookId,
out var title,
out var localScore,
out var globalScore);
// Assert
result.Should().BeFalse();
}
}