Improve reset of GlobalOptions

This commit is contained in:
Malte Rosenbjerg 2025-10-16 13:46:08 +02:00
parent 9765b78d48
commit 012a5ca74a

View file

@ -1,19 +1,10 @@
using System.Reflection; using FFMpegCore.Arguments;
using FFMpegCore.Arguments;
namespace FFMpegCore.Test; namespace FFMpegCore.Test;
[TestClass] [TestClass]
public class FFMpegArgumentProcessorTest public class FFMpegArgumentProcessorTest
{ {
[TestCleanup]
public void TestInitialize()
{
// After testing reset global configuration to null, to be not wrong for other test relying on configuration
typeof(GlobalFFOptions).GetField("_current", BindingFlags.NonPublic | BindingFlags.Static)!.SetValue(GlobalFFOptions.Current, null);
}
private static FFMpegArgumentProcessor CreateArgumentProcessor() private static FFMpegArgumentProcessor CreateArgumentProcessor()
{ {
return FFMpegArguments return FFMpegArguments
@ -37,7 +28,7 @@ public class FFMpegArgumentProcessorTest
} }
finally finally
{ {
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = string.Empty }); GlobalFFOptions.Configure(new FFOptions());
} }
} }
@ -70,13 +61,16 @@ public class FFMpegArgumentProcessorTest
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalConfig, TemporaryFilesFolder = globalConfig, BinaryFolder = globalConfig }); GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalConfig, TemporaryFilesFolder = globalConfig, BinaryFolder = globalConfig });
var options = processor.GetConfiguredOptions(overrideOptions); var options = processor.GetConfiguredOptions(overrideOptions);
Assert.AreSame(options, overrideOptions); Assert.AreEqual(options.WorkingDirectory, overrideOptions.WorkingDirectory);
Assert.AreEqual(options.TemporaryFilesFolder, overrideOptions.TemporaryFilesFolder);
Assert.AreEqual(options.BinaryFolder, overrideOptions.BinaryFolder);
Assert.AreEqual(sessionTempDir, options.TemporaryFilesFolder); Assert.AreEqual(sessionTempDir, options.TemporaryFilesFolder);
Assert.AreNotEqual(globalConfig, options.BinaryFolder); Assert.AreNotEqual(globalConfig, options.BinaryFolder);
} }
finally finally
{ {
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = string.Empty }); GlobalFFOptions.Configure(new FFOptions());
} }
} }
@ -100,7 +94,7 @@ public class FFMpegArgumentProcessorTest
} }
finally finally
{ {
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = string.Empty }); GlobalFFOptions.Configure(new FFOptions());
} }
} }