mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-12-27 12:35:35 +08:00
97 lines
3.5 KiB
C#
97 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using BililiveRecorder.Flv.Grouping;
|
|
using BililiveRecorder.Flv.Pipeline;
|
|
using BililiveRecorder.Flv.Writer;
|
|
using BililiveRecorder.Flv.Xml;
|
|
using VerifyTests;
|
|
using VerifyXunit;
|
|
using Xunit;
|
|
|
|
namespace BililiveRecorder.Flv.Tests.RuleTests
|
|
{
|
|
[UsesVerify]
|
|
[ExpectationPath("Good")]
|
|
public class IntegratedGoodTests : IntegratedTestBase
|
|
{
|
|
[Theory()]
|
|
[Expectation("StandardTest")]
|
|
[SampleFileTestData("../data/flv/TestData/Good", "*.xml")]
|
|
public async Task StrictTestsAsync(string path)
|
|
{
|
|
// Arrange
|
|
var originalTags = SampleFileLoader.LoadXmlFlv(path).Tags;
|
|
var reader = new TagGroupReader(new FlvTagListReader(SampleFileLoader.LoadXmlFlv(path).Tags));
|
|
var flvTagListWriter = new FlvTagListWriter();
|
|
var comments = new List<ProcessingComment>();
|
|
|
|
// Act
|
|
await RunPipeline(reader, flvTagListWriter, comments).ConfigureAwait(false);
|
|
|
|
// Assert
|
|
comments.RemoveAll(x => !x.ActionRequired);
|
|
|
|
Assert.Empty(comments);
|
|
|
|
Assert.Empty(flvTagListWriter.AccompanyingTextLogs);
|
|
|
|
var outputTags = Assert.Single(flvTagListWriter.Files);
|
|
Assert.Equal(originalTags.Count, outputTags.Count);
|
|
|
|
AssertTags.ShouldHaveLinearTimestamps(outputTags);
|
|
AssertTags.ShouldHaveFullHeaderTags(outputTags);
|
|
AssertTags.ShouldHaveSingleHeaderTagPerType(outputTags);
|
|
AssertTags.ShouldAlmostEqual(originalTags, outputTags);
|
|
|
|
await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false);
|
|
|
|
var xmlStr = outputTags.SerializeXml();
|
|
await Verifier.Verify(xmlStr, extension: "xml").UseParameters(path);
|
|
}
|
|
|
|
[Theory()]
|
|
[Expectation("WithOffsetTest")]
|
|
[SampleFileTestData("../data/flv/TestData/Good", "*.xml")]
|
|
public async Task StrictWithArtificalOffsetTestsAsync(string path)
|
|
{
|
|
// Arrange
|
|
var originalTags = SampleFileLoader.LoadXmlFlv(path).Tags;
|
|
|
|
var random = new System.Random();
|
|
var offset = random.Next(501, 9999);
|
|
if (random.Next(2) == 1)
|
|
offset = -offset;
|
|
|
|
var inputTagsWithOffset = SampleFileLoader.LoadXmlFlv(path).Tags;
|
|
foreach (var tag in inputTagsWithOffset)
|
|
tag.Timestamp += offset;
|
|
var reader = new TagGroupReader(new FlvTagListReader(inputTagsWithOffset));
|
|
|
|
var output = new FlvTagListWriter();
|
|
var comments = new List<ProcessingComment>();
|
|
|
|
// Act
|
|
await RunPipeline(reader, output, comments).ConfigureAwait(false);
|
|
|
|
// Assert
|
|
comments.RemoveAll(x => !x.ActionRequired);
|
|
Assert.Equal(CommentType.TimestampJump, Assert.Single(comments).Type);
|
|
|
|
Assert.Empty(output.AccompanyingTextLogs);
|
|
|
|
var outputTags = Assert.Single(output.Files);
|
|
Assert.Equal(originalTags.Count, outputTags.Count);
|
|
|
|
AssertTags.ShouldHaveLinearTimestamps(outputTags);
|
|
AssertTags.ShouldHaveFullHeaderTags(outputTags);
|
|
AssertTags.ShouldHaveSingleHeaderTagPerType(outputTags);
|
|
AssertTags.ShouldAlmostEqual(originalTags, outputTags);
|
|
|
|
await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false);
|
|
|
|
var xmlStr = outputTags.SerializeXml();
|
|
await Verifier.Verify(xmlStr, extension: "xml").UseParameters(path);
|
|
}
|
|
}
|
|
}
|