2021-11-02 21:46:44 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
using BililiveRecorder.Flv.Xml;
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
namespace BililiveRecorder.Flv.Tests
|
2021-11-02 21:46:44 +08:00
|
|
|
{
|
|
|
|
public static class SampleFileLoader
|
|
|
|
{
|
2021-11-13 02:01:03 +08:00
|
|
|
public static string GetFullPath(string fileName)
|
2021-11-02 21:46:44 +08:00
|
|
|
{
|
|
|
|
var stackTrace = new StackTrace();
|
|
|
|
var frames = stackTrace.GetFrames();
|
|
|
|
var attr = frames.Select(x => x!.GetMethod()!.GetCustomAttribute<SampleFileTestDataAttribute>()).First(x => x is not null);
|
2021-11-02 23:04:12 +08:00
|
|
|
var fullPath = Path.Combine(attr!.FullPath, fileName);
|
2021-11-13 02:01:03 +08:00
|
|
|
return fullPath;
|
|
|
|
}
|
2021-11-02 21:46:44 +08:00
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
public static XmlFlvFile LoadXmlFlv(string fileName)
|
|
|
|
{
|
|
|
|
var fullPath = GetFullPath(fileName);
|
2021-11-02 21:46:44 +08:00
|
|
|
using var s = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
return (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(s)!;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|