TwitchDownloader/dotnet/src/TwitchArchive.Tests/FileManagerServiceTests.cs

38 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.IO;
using Xunit;
using TwitchArchive.Core.Services;
namespace TwitchArchive.Tests
{
public class FileManagerServiceTests : IDisposable
{
private readonly string _root;
public FileManagerServiceTests()
{
_root = Path.Combine(Path.GetTempPath(), "ta_fm_" + Guid.NewGuid().ToString("N"));
}
[Fact]
public void EnsureDirectories_CreatesPaths_And_GetUniquePath_AppendsSuffix()
{
var svc = new FileManagerService(_root);
var paths = svc.GetPaths("alice");
svc.EnsureDirectories(paths);
Assert.True(Directory.Exists(paths.RawPath));
Assert.True(Directory.Exists(paths.VideoPath));
var file = Path.Combine(paths.RawPath, "file.ts");
File.WriteAllText(file, "x");
var unique = svc.GetUniqueFilePath(file);
Assert.NotEqual(file, unique);
Assert.Contains("file-", Path.GetFileName(unique));
}
public void Dispose()
{
try { Directory.Delete(_root, true); } catch { }
}
}
}