From 349b6044d16efe016911f1cd27757463343b0b9d Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 23 Feb 2023 19:18:34 +0100 Subject: [PATCH 1/2] Wrap Instances exception for expected behaviour --- FFMpegCore.Test/FFMpegArgumentProcessorTest.cs | 10 ++++++++++ FFMpegCore/Helpers/FFMpegHelper.cs | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs index bb7071d8..7652d48a 100644 --- a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs +++ b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs @@ -1,6 +1,9 @@ using System.Reflection; using FFMpegCore.Arguments; +using FFMpegCore.Exceptions; +using FFMpegCore.Helpers; using FluentAssertions; +using Instances.Exceptions; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace FFMpegCore.Test @@ -99,5 +102,12 @@ public void Audible_Aax_Test() var arg = new AudibleEncryptionKeyArgument("62689101"); arg.Text.Should().Be($"-activation_bytes 62689101"); } + + [TestMethod] + public void Throws_FFMpegException_when_ffmpeg_not_found() + { + var exception = Assert.ThrowsException(() => FFMpegHelper.VerifyFFMpegExists(new FFOptions { BinaryFolder = Path.GetTempPath() })); + Assert.IsInstanceOfType(exception.InnerException); + } } } diff --git a/FFMpegCore/Helpers/FFMpegHelper.cs b/FFMpegCore/Helpers/FFMpegHelper.cs index 3fb03eb8..0d64cb83 100644 --- a/FFMpegCore/Helpers/FFMpegHelper.cs +++ b/FFMpegCore/Helpers/FFMpegHelper.cs @@ -42,8 +42,16 @@ public static void VerifyFFMpegExists(FFOptions ffMpegOptions) return; } - var result = Instance.Finish(GlobalFFOptions.GetFFMpegBinaryPath(ffMpegOptions), "-version"); - _ffmpegVerified = result.ExitCode == 0; + try + { + var result = Instance.Finish(GlobalFFOptions.GetFFMpegBinaryPath(ffMpegOptions), "-version"); + _ffmpegVerified = result.ExitCode == 0; + } + catch (Exception e) + { + throw new FFMpegException(FFMpegExceptionType.Operation, "ffmpeg was not found on your system", e); + } + if (!_ffmpegVerified) { throw new FFMpegException(FFMpegExceptionType.Operation, "ffmpeg was not found on your system"); From 508cce882773fc0d73f5950aaee1eb59fab3593a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 23 Feb 2023 22:00:19 +0100 Subject: [PATCH 2/2] Change test path to non-existing directory --- FFMpegCore.Test/FFMpegArgumentProcessorTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs index 7652d48a..289234f4 100644 --- a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs +++ b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs @@ -106,7 +106,7 @@ public void Audible_Aax_Test() [TestMethod] public void Throws_FFMpegException_when_ffmpeg_not_found() { - var exception = Assert.ThrowsException(() => FFMpegHelper.VerifyFFMpegExists(new FFOptions { BinaryFolder = Path.GetTempPath() })); + var exception = Assert.ThrowsException(() => FFMpegHelper.VerifyFFMpegExists(new FFOptions { BinaryFolder = "./folder/that/does/not/exist" })); Assert.IsInstanceOfType(exception.InnerException); } }