BililiveRecorder/test/BililiveRecorder.Flv.RuleTests/SampleFileTestDataAttribute.cs

30 lines
918 B
C#
Raw Normal View History

2021-03-03 19:04:37 +08:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;
namespace BililiveRecorder.Flv.RuleTests
{
public class SampleFileTestDataAttribute : DataAttribute
{
public SampleFileTestDataAttribute(string basePath)
{
this.BasePath = basePath;
}
public string BasePath { get; }
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
var fullPath = Path.IsPathRooted(this.BasePath) ? this.BasePath : Path.GetRelativePath(Directory.GetCurrentDirectory(), this.BasePath);
if (!Directory.Exists(fullPath))
throw new ArgumentException($"Could not find directory at path: {fullPath}");
2021-03-09 22:13:44 +08:00
return new[] { "*.xml", "*.gz" }.SelectMany(x => Directory.GetFiles(fullPath, x)).Select(x => new object[] { x });
2021-03-03 19:04:37 +08:00
}
}
}