Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trossr32 committed Jan 1, 2024
1 parent 4ecc145 commit 7a00939
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
src/PsVideoResolutionCmdlet/C/
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace PsVideoResolutionCmdlet.Tests;
public partial class Tests
{
private const string Assets = nameof(Assets);
private const string Nested = @"Assets\Nested";
private static readonly string Nested = Path.Combine("Assets", "Nested");
private const string File = "sample.mp4";
private const string OutputDirectory = @"C:\Temp\VideoResolutionCmdletTests";
private const string OutputDirectory = "VideoResolutionCmdletTests_Output";

private const string Resolution = "320x240";
private const double Size = 0.543879d;
Expand Down
50 changes: 2 additions & 48 deletions src/PsVideoResolutionCmdlet/GetVideoResolutionCmdlet.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Reflection;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
using PsVideoResolution.Core.Formatters;
using PsVideoResolution.Core.Models;
using Xabe.FFmpeg;
using Xabe.FFmpeg.Downloader;
using Xabe.FFmpeg.Exceptions;

[assembly: InternalsVisibleTo("PsVideoResolutionCmdlet.Tests")]
Expand Down Expand Up @@ -273,9 +269,9 @@ protected override void EndProcessing()

WriteOutput(results);
}
catch (FFmpegNotFoundException)
catch (FFmpegNotFoundException ffe)
{
FFMpegMissing();
ThrowTerminatingError(new ErrorRecord(ffe, null, ErrorCategory.ResourceUnavailable, null));
}
catch (Exception e)
{
Expand Down Expand Up @@ -322,46 +318,4 @@ private void WriteOutput(List<VideoInfo> results)

WriteObject(lines);
}

private void FFMpegMissing()
{
WriteWarning("FFMpeg installation not found. Would you like to download it now? (FFMpeg latest official release will be downloaded to this module's execution directory).");

var choices = new BindingList<ChoiceDescription>
{
new("yes"),
new("no")
};

var response = Host.UI.PromptForChoice("FFMpeg installation not found", "Would you like to download it now?", choices, 1);

if (response is not 0)
return;

try
{
var installProgress = new Progress<ProgressInfo>();

installProgress.ProgressChanged += (sender, info) =>
{
WriteProgress(new ProgressRecord(1, "Downloading FFMpeg...", $"{info.DownloadedBytes} / {info.TotalBytes}"));
};

WriteVerbose("Setting FFMpeg executables path to this module's execution directory.");

FFmpeg.SetExecutablesPath(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location));

FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, installProgress);

WriteProgress(new ProgressRecord(1, "Downloading FFMpeg...", "Completed"));
}
catch (Exception e)
{
WriteError(new ErrorRecord(e, null, ErrorCategory.InvalidOperation, null));

return;
}

EndProcessing();
}
}
7 changes: 1 addition & 6 deletions src/PsVideoResolutionCmdlet/VideoResolution.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a00939

Please sign in to comment.