Added Tests

This commit is contained in:
BobSilent 2021-11-18 14:01:38 +01:00
parent f7ad339459
commit 47a6c23b2d
3 changed files with 87 additions and 2 deletions

View file

@ -0,0 +1,84 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
namespace FFMpegCore.Test
{
[TestClass]
public class FFMpegArgumentProcessorTest
{
private static FFMpegArgumentProcessor CreateArgumentProcessor() => FFMpegArguments
.FromFileInput("")
.OutputToFile("");
[TestMethod]
public void Processor_GlobalOptions_GetUsed()
{
var globalWorkingDir = "Whatever";
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalWorkingDir });
var processor = CreateArgumentProcessor();
var options2 = processor.GetConfiguredOptions(null);
options2.WorkingDirectory.Should().Be(globalWorkingDir);
}
[TestMethod]
public void Processor_SessionOptions_GetUsed()
{
var sessionWorkingDir = "./CurrentRunWorkingDir";
var processor = CreateArgumentProcessor();
processor.Configure(options => options.WorkingDirectory = sessionWorkingDir);
var options = processor.GetConfiguredOptions(null);
options.WorkingDirectory.Should().Be(sessionWorkingDir);
}
[TestMethod]
public void Processor_Options_CanBeOverridden_And_Configured()
{
var globalConfig = "Whatever";
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalConfig, TemporaryFilesFolder = globalConfig, BinaryFolder = globalConfig });
var processor = CreateArgumentProcessor();
var sessionTempDir = "./CurrentRunWorkingDir";
processor.Configure(options => options.TemporaryFilesFolder = sessionTempDir);
var overrideOptions = new FFOptions() { WorkingDirectory = "override" };
var options = processor.GetConfiguredOptions(overrideOptions);
options.Should().BeEquivalentTo(overrideOptions);
options.TemporaryFilesFolder.Should().BeEquivalentTo(sessionTempDir);
options.BinaryFolder.Should().NotBeEquivalentTo(globalConfig);
}
[TestMethod]
public void Options_Global_And_Session_Options_Can_Differ()
{
FFMpegArgumentProcessor CreateArgumentProcessor() => FFMpegArguments
.FromFileInput("")
.OutputToFile("");
var globalWorkingDir = "Whatever";
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalWorkingDir });
var processor1 = CreateArgumentProcessor();
var sessionWorkingDir = "./CurrentRunWorkingDir";
processor1.Configure(options => options.WorkingDirectory = sessionWorkingDir);
var options1 = processor1.GetConfiguredOptions(null);
options1.WorkingDirectory.Should().Be(sessionWorkingDir);
var processor2 = CreateArgumentProcessor();
var options2 = processor2.GetConfiguredOptions(null);
options2.WorkingDirectory.Should().Be(globalWorkingDir);
}
}
}

View file

@ -39,6 +39,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" /> <PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" /> <PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />

View file

@ -172,7 +172,7 @@ private bool HandleCompletion(bool throwOnError, int exitCode, IReadOnlyList<str
return exitCode == 0; return exitCode == 0;
} }
private FFOptions GetConfiguredOptions(FFOptions? ffOptions) internal FFOptions GetConfiguredOptions(FFOptions? ffOptions)
{ {
var options = ffOptions ?? GlobalFFOptions.Current.Clone(); var options = ffOptions ?? GlobalFFOptions.Current.Clone();