BililiveRecorder/test/BililiveRecorder.Flv.Tests/RuleTests/IntegratedTestBase.cs

73 lines
2.8 KiB
C#
Raw Normal View History

2021-11-02 21:46:44 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BililiveRecorder.Flv.Grouping;
using BililiveRecorder.Flv.Pipeline;
2022-06-24 21:29:10 +08:00
using BililiveRecorder.Flv.Pipeline.Rules;
2021-11-02 21:46:44 +08:00
using BililiveRecorder.Flv.Writer;
using BililiveRecorder.Flv.Xml;
using Xunit;
namespace BililiveRecorder.Flv.Tests.RuleTests
2021-11-02 21:46:44 +08:00
{
public abstract class IntegratedTestBase
{
protected static async Task RunPipeline(ITagGroupReader reader, IFlvTagWriter output, List<ProcessingComment> comments)
{
var writer = new FlvProcessingContextWriter(tagWriter: output, allowMissingHeader: true, disableKeyframes: true, logger: null);
2021-11-02 21:46:44 +08:00
var session = new Dictionary<object, object?>();
var context = new FlvProcessingContext();
var pipeline = new ProcessingPipelineBuilder().AddRule<FfmpegDetectionRule>().AddDefaultRules().AddRemoveFillerDataRule().Build();
2021-11-02 21:46:44 +08:00
while (true)
{
var group = await reader.ReadGroupAsync(default).ConfigureAwait(false);
if (group is null)
break;
context.Reset(group, session);
pipeline(context);
comments.AddRange(context.Comments);
await writer.WriteAsync(context).ConfigureAwait(false);
}
}
protected static async Task AssertTagsByRerunPipeline(List<Tag> tags)
{
var reader = new TagGroupReader(new FlvTagListReader(tags.Select(x => x.Clone()).ToList()));
var output = new FlvTagListWriter();
var comments = new List<ProcessingComment>();
await RunPipeline(reader, output, comments).ConfigureAwait(false);
// 忽略 ignore Logging
2022-06-17 17:42:50 +08:00
comments.RemoveAll(x => !x.ActionRequired);
2021-11-02 21:46:44 +08:00
// 不应该有任何问题 Shouldn't have any problems
Assert.Empty(comments);
// 不应该有多个 Header Shouldn't have multiple headers
Assert.Empty(output.AccompanyingTextLogs);
2021-11-02 21:46:44 +08:00
// 只应该有一个文件输出 Should output only a single file
var outputTags = Assert.Single(output.Files);
// Tag count should match
Assert.Equal(tags.Count, outputTags.Count);
for (var i = 0; i < tags.Count; i++)
{
var a = tags[i];
var b = outputTags[i];
Assert.NotSame(a, b);
Assert.Equal(a.Type, b.Type);
Assert.Equal(a.Flag, b.Flag);
Assert.Equal(a.Index, b.Index);
Assert.Equal(a.Size, b.Size);
Assert.Equal(a.Timestamp, b.Timestamp);
Assert.Equal(a.BinaryDataForSerializationUseOnly, b.BinaryDataForSerializationUseOnly);
}
}
}
}