2021-03-03 19:04:37 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
2021-11-02 23:04:12 +08:00
|
|
|
using VerifyTests;
|
2021-03-03 19:04:37 +08:00
|
|
|
using Xunit.Sdk;
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
namespace BililiveRecorder.Flv.Tests
|
2021-03-03 19:04:37 +08:00
|
|
|
{
|
|
|
|
public class SampleFileTestDataAttribute : DataAttribute
|
|
|
|
{
|
2021-11-13 02:01:03 +08:00
|
|
|
public SampleFileTestDataAttribute(string basePath, params string[] patterns)
|
2021-03-03 19:04:37 +08:00
|
|
|
{
|
|
|
|
this.BasePath = basePath;
|
2021-11-13 02:01:03 +08:00
|
|
|
this.Patterns = patterns;
|
2021-11-02 23:04:12 +08:00
|
|
|
this.FullPath = Path.GetFullPath(Path.Combine(AttributeReader.GetProjectDirectory(), basePath));
|
2021-03-03 19:04:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public string BasePath { get; }
|
|
|
|
|
2021-11-02 23:04:12 +08:00
|
|
|
public string FullPath { get; }
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
public string[] Patterns { get; }
|
|
|
|
|
2021-03-03 19:04:37 +08:00
|
|
|
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
|
|
|
|
{
|
2021-11-02 23:04:12 +08:00
|
|
|
if (!Directory.Exists(this.FullPath))
|
|
|
|
throw new ArgumentException($"Could not find directory at path: {this.FullPath}");
|
2021-03-03 19:04:37 +08:00
|
|
|
|
2022-06-07 19:50:34 +08:00
|
|
|
return this.Patterns.SelectMany(x => Directory.GetFiles(this.FullPath, x)).Select(x => (new object[] { Path.GetFileName(x) }));
|
2021-03-03 19:04:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|