forked from rosenbjerg/FFMpegCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFMpegCore: Rethink options configuration
- Loading branch information
Showing
8 changed files
with
103 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using FFMpegCore.FFMPEG; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
|
||
namespace FFMpegCore.Test | ||
{ | ||
[TestClass] | ||
public class FFMpegOptionsTest | ||
{ | ||
[TestMethod] | ||
public void Options_Initialized() | ||
{ | ||
Assert.IsNotNull(FFMpegOptions.Options); | ||
} | ||
|
||
[TestMethod] | ||
public void Options_Defaults_Configured() | ||
{ | ||
Assert.AreEqual(new FFMpegOptions().RootDirectory, ".\\FFMPEG\\bin"); | ||
} | ||
|
||
[TestMethod] | ||
public void Options_Loaded_From_File() | ||
{ | ||
Assert.AreEqual( | ||
FFMpegOptions.Options.RootDirectory, | ||
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(".\\ffmpeg.config.json")).RootDirectory | ||
); | ||
} | ||
|
||
[TestMethod] | ||
public void Options_Overrided() | ||
{ | ||
var original = FFMpegOptions.Options; | ||
try | ||
{ | ||
FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = "Whatever" }); | ||
Assert.AreEqual( | ||
FFMpegOptions.Options.RootDirectory, | ||
"Whatever" | ||
); | ||
} | ||
finally | ||
{ | ||
FFMpegOptions.Configure(original); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
namespace FFMpegCore.FFMPEG | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
|
||
namespace FFMpegCore.FFMPEG | ||
{ | ||
public class FFMpegOptions | ||
{ | ||
public string RootDirectory { get; set; } | ||
private static string _ConfigFile = ".\\ffmpeg.config.json"; | ||
private static string _DefaultRoot = ".\\FFMPEG\\bin"; | ||
|
||
public static FFMpegOptions Options { get; private set; } = new FFMpegOptions(); | ||
|
||
public static void Configure(FFMpegOptions options) | ||
{ | ||
Options = options; | ||
} | ||
|
||
static FFMpegOptions() | ||
{ | ||
if (File.Exists(_ConfigFile)) | ||
{ | ||
Options = JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(_ConfigFile)); | ||
} | ||
} | ||
|
||
public string RootDirectory { get; set; } = _DefaultRoot; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters