BililiveRecorder/test/BililiveRecorder.Flv.Tests/SampleFileTestDataAttribute.cs

35 lines
1.0 KiB
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;
2021-11-02 23:04:12 +08:00
using VerifyTests;
2021-03-03 19:04:37 +08:00
using Xunit.Sdk;
namespace BililiveRecorder.Flv.Tests
2021-03-03 19:04:37 +08:00
{
public class SampleFileTestDataAttribute : DataAttribute
{
public SampleFileTestDataAttribute(string basePath, params string[] patterns)
2021-03-03 19:04:37 +08:00
{
this.BasePath = basePath;
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; }
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
return Patterns.SelectMany(x => Directory.GetFiles(this.FullPath, x)).Select(x => (new object[] { Path.GetFileName(x) }));
2021-03-03 19:04:37 +08:00
}
}
}