From 0c8b3f999923596c1207fc2b0a4147ad5f9c39a7 Mon Sep 17 00:00:00 2001 From: Genteure Date: Tue, 2 Nov 2021 23:04:12 +0800 Subject: [PATCH] Fix tests by removing file copy --- .../BililiveRecorder.Flv.RuleTests.csproj | 6 -- .../IntegratedBadTests.cs | 73 ++----------------- .../IntegratedGoodTests.cs | 7 -- .../SampleFileLoader.cs | 2 +- .../SampleFileTestDataAttribute.cs | 12 +-- 5 files changed, 16 insertions(+), 84 deletions(-) diff --git a/test/BililiveRecorder.Flv.RuleTests/BililiveRecorder.Flv.RuleTests.csproj b/test/BililiveRecorder.Flv.RuleTests/BililiveRecorder.Flv.RuleTests.csproj index eebacfb..12e4b3f 100644 --- a/test/BililiveRecorder.Flv.RuleTests/BililiveRecorder.Flv.RuleTests.csproj +++ b/test/BililiveRecorder.Flv.RuleTests/BililiveRecorder.Flv.RuleTests.csproj @@ -26,10 +26,4 @@ - - - Always - - - diff --git a/test/BililiveRecorder.Flv.RuleTests/IntegratedBadTests.cs b/test/BililiveRecorder.Flv.RuleTests/IntegratedBadTests.cs index cdc7a0e..ad4fcc8 100644 --- a/test/BililiveRecorder.Flv.RuleTests/IntegratedBadTests.cs +++ b/test/BililiveRecorder.Flv.RuleTests/IntegratedBadTests.cs @@ -13,6 +13,8 @@ using Newtonsoft.Json.Converters; using VerifyTests; using VerifyXunit; using Xunit; +using Xunit.Abstractions; + namespace BililiveRecorder.Flv.RuleTests.Integrated { [UsesVerify] @@ -21,15 +23,10 @@ namespace BililiveRecorder.Flv.RuleTests.Integrated { [Theory] [Expectation("TestBadSamples")] - //[SampleDirectoryTestData("TestData/Bad")] [SampleFileTestData("TestData/Bad")] public async Task TestBadSamples(string path) { - // Arrange - //var path_info = Path.Combine(path, "info.json"); - //var INFO_TO_BE_REMOVED = JsonConvert.DeserializeObject(File.ReadAllText(path_info)); - //var path_input = Path.Combine(path, "input.xml"); var originalTags = SampleFileLoader.Load(path).Tags; var reader = new TagGroupReader(new FlvTagListReader(originalTags)); var flvTagListWriter = new FlvTagListWriter(); @@ -41,59 +38,24 @@ namespace BililiveRecorder.Flv.RuleTests.Integrated // Assert comments.RemoveAll(x => x.T == CommentType.Logging); - var outputResult = new OutputResult(); - - //Assert.Equal(INFO_TO_BE_REMOVED.AlternativeHeaderCount, flvTagListWriter.AlternativeHeaders.Count); - outputResult.AlternativeHeaders = flvTagListWriter.AlternativeHeaders.Select(x => x.BinaryDataForSerializationUseOnly).ToArray(); - - //Assert.Equal(INFO_TO_BE_REMOVED.AllowedComments.Values.Sum(x => x), comments.Count); - //Assert.DoesNotContain(comments, x => !INFO_TO_BE_REMOVED.AllowedComments.ContainsKey(x.T)); - //Assert.True(INFO_TO_BE_REMOVED.AllowedComments.All(x => x.Value == comments.Count(c => c.T == x.Key))); - - outputResult.Comments = comments.GroupBy(x => x.T).Select(x => new CommentCount(x.Key, x.Count())).ToArray(); - - - //Assert.Equal(INFO_TO_BE_REMOVED.Files.Length, flvTagListWriter.Files.Count); - - outputResult.TagCounts = flvTagListWriter.Files.Select(x => x.Count).ToArray(); - - // outputResult.Tags = flvTagListWriter.Files.ToArray(); + var outputResult = new OutputResult + { + AlternativeHeaders = flvTagListWriter.AlternativeHeaders.Select(x => x.BinaryDataForSerializationUseOnly).ToArray(), + Comments = comments.GroupBy(x => x.T).Select(x => new CommentCount(x.Key, x.Count())).ToArray(), + TagCounts = flvTagListWriter.Files.Select(x => x.Count).ToArray() + }; using var sw = new StringWriter(); - sw.WriteLine(JsonConvert.SerializeObject(outputResult, Formatting.Indented)); - // OutputResultSerializer.Serialize(xmlSw, outputResult); - // var xmlStr = xmlSw.ToString(); - - // await Verifier.Verify(xmlStr).UseParameters(path); - for (var i = 0; i < flvTagListWriter.Files.Count; i++) { - // var expected = INFO_TO_BE_REMOVED.Files[i]; var outputTags = flvTagListWriter.Files[i]; - // Assert.Equal(expected.TagCount, outputTags.Count); - - // TODO 重写相关测试的检查,支持只有音频或视频 header 的数据片段 - AssertTags.ShouldHaveLinearTimestamps(outputTags); - - // if (!expected.SkipTagCheck) - // this.AssertTagsShouldPassBasicChecks(outputTags); - - //if (expected.VideoHeaderData is not null) - // Assert.Equal(expected.VideoHeaderData, outputTags[1].BinaryDataForSerializationUseOnly); - - //if (expected.AudioHeaderData is not null) - // Assert.Equal(expected.AudioHeaderData, outputTags[2].BinaryDataForSerializationUseOnly); - await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false); var xmlStr = SerializeTags(outputTags); - - // await Verifier.Verify(xmlStr).UseExtension("xml").UseParameters(path); - sw.WriteLine(xmlStr); } @@ -111,25 +73,6 @@ namespace BililiveRecorder.Flv.RuleTests.Integrated public string?[] AlternativeHeaders { get; set; } = Array.Empty(); } - public class Info - { - public OutputFile[] Files { get; set; } = Array.Empty(); - - public Dictionary AllowedComments { get; set; } = new Dictionary(); - - public int AlternativeHeaderCount { get; set; } - } - - public class OutputFile - { - public string? VideoHeaderData { get; set; } - - public string? AudioHeaderData { get; set; } - - public int TagCount { get; set; } - } - - public struct CommentCount { [JsonConverter(typeof(StringEnumConverter))] diff --git a/test/BililiveRecorder.Flv.RuleTests/IntegratedGoodTests.cs b/test/BililiveRecorder.Flv.RuleTests/IntegratedGoodTests.cs index 32306e3..b9a9bab 100644 --- a/test/BililiveRecorder.Flv.RuleTests/IntegratedGoodTests.cs +++ b/test/BililiveRecorder.Flv.RuleTests/IntegratedGoodTests.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using BililiveRecorder.Flv.Grouping; using BililiveRecorder.Flv.Pipeline; @@ -41,11 +40,8 @@ namespace BililiveRecorder.Flv.RuleTests.Integrated AssertTags.ShouldHaveLinearTimestamps(outputTags); AssertTags.ShouldHaveFullHeaderTags(outputTags); - //this.AssertTagsShouldPassBasicChecks(outputTags); - AssertTags.ShouldHaveSingleHeaderTagPerType(outputTags); AssertTags.ShouldAlmostEqual(originalTags, outputTags); - //this.AssertTagsAlmostEqual(originalTags, outputTags); await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false); @@ -88,11 +84,8 @@ namespace BililiveRecorder.Flv.RuleTests.Integrated AssertTags.ShouldHaveLinearTimestamps(outputTags); AssertTags.ShouldHaveFullHeaderTags(outputTags); - //this.AssertTagsShouldPassBasicChecks(outputTags); - AssertTags.ShouldHaveSingleHeaderTagPerType(outputTags); AssertTags.ShouldAlmostEqual(originalTags, outputTags); - //this.AssertTagsAlmostEqual(originalTags, outputTags); await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false); diff --git a/test/BililiveRecorder.Flv.RuleTests/SampleFileLoader.cs b/test/BililiveRecorder.Flv.RuleTests/SampleFileLoader.cs index 6672aaf..81dbf01 100644 --- a/test/BililiveRecorder.Flv.RuleTests/SampleFileLoader.cs +++ b/test/BililiveRecorder.Flv.RuleTests/SampleFileLoader.cs @@ -13,7 +13,7 @@ namespace BililiveRecorder.Flv.RuleTests var stackTrace = new StackTrace(); var frames = stackTrace.GetFrames(); var attr = frames.Select(x => x!.GetMethod()!.GetCustomAttribute()).First(x => x is not null); - var fullPath = Path.Combine(attr!.BasePath, fileName); + var fullPath = Path.Combine(attr!.FullPath, fileName); using var s = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); diff --git a/test/BililiveRecorder.Flv.RuleTests/SampleFileTestDataAttribute.cs b/test/BililiveRecorder.Flv.RuleTests/SampleFileTestDataAttribute.cs index 9032237..0888024 100644 --- a/test/BililiveRecorder.Flv.RuleTests/SampleFileTestDataAttribute.cs +++ b/test/BililiveRecorder.Flv.RuleTests/SampleFileTestDataAttribute.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using VerifyTests; using Xunit.Sdk; namespace BililiveRecorder.Flv.RuleTests @@ -12,18 +13,19 @@ namespace BililiveRecorder.Flv.RuleTests public SampleFileTestDataAttribute(string basePath) { this.BasePath = basePath; + this.FullPath = Path.GetFullPath(Path.Combine(AttributeReader.GetProjectDirectory(), basePath)); } public string BasePath { get; } + public string FullPath { get; } + public override IEnumerable GetData(MethodInfo testMethod) { - var fullPath = Path.IsPathRooted(this.BasePath) ? this.BasePath : Path.GetRelativePath(Directory.GetCurrentDirectory(), this.BasePath); + if (!Directory.Exists(this.FullPath)) + throw new ArgumentException($"Could not find directory at path: {this.FullPath}"); - if (!Directory.Exists(fullPath)) - throw new ArgumentException($"Could not find directory at path: {fullPath}"); - - return new[] { "*.xml" }.SelectMany(x => Directory.GetFiles(fullPath, x)).Select(x => new object[] { Path.GetFileName(x) }); + return new[] { "*.xml" }.SelectMany(x => Directory.GetFiles(this.FullPath, x)).Select(x => new object[] { Path.GetFileName(x) }); } } }