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

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