From 2976110f055c5b82eec0a97b7b7c4ae03676a8ac Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 24 Feb 2016 23:17:35 -0800 Subject: [PATCH] Shifted references to IFileInvoker to Dependencies.cs, added factory func to Dependencies.cs for providing IFileInvoker. --- .../OSCADSharp.UnitTests/OSCADObjectTests.cs | 4 +-- .../OSCADSharp.UnitTests/SettingsTests.cs | 2 +- OSCADSharp/OSCADSharp/Dependencies.cs | 25 +++++++++++++++++++ OSCADSharp/OSCADSharp/Files/IFileInvoker.cs | 2 ++ OSCADSharp/OSCADSharp/OSCADObject.cs | 4 +-- OSCADSharp/OSCADSharp/OSCADSharp.csproj | 1 + OSCADSharp/OSCADSharp/Settings.cs | 7 +----- 7 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 OSCADSharp/OSCADSharp/Dependencies.cs diff --git a/OSCADSharp/OSCADSharp.UnitTests/OSCADObjectTests.cs b/OSCADSharp/OSCADSharp.UnitTests/OSCADObjectTests.cs index 62af2ab..ad140b0 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/OSCADObjectTests.cs +++ b/OSCADSharp/OSCADSharp.UnitTests/OSCADObjectTests.cs @@ -148,7 +148,7 @@ namespace OSCADSharp.UnitTests var mock = new Mock(); mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny(), It.IsAny())) .Callback((path, contents) => { output = contents; }); - Settings.FileWriter = mock.Object; + Dependencies.FileWriter = mock.Object; cube.ToFile("myFile"); @@ -165,7 +165,7 @@ namespace OSCADSharp.UnitTests var mock = new Mock(); mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny(), It.IsAny())) .Callback((path, contents) => { output = contents; }); - Settings.FileWriter = mock.Object; + Dependencies.FileWriter = mock.Object; cube.ToFile("myFile"); diff --git a/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs b/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs index 29926db..3a1dff2 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs +++ b/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs @@ -24,7 +24,7 @@ namespace OSCADSharp.UnitTests var mock = new Mock(); mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny(), It.IsAny())) .Callback((path, contents) => { output = contents; }); - Settings.FileWriter = mock.Object; + Dependencies.FileWriter = mock.Object; cube.ToFile("myFile"); diff --git a/OSCADSharp/OSCADSharp/Dependencies.cs b/OSCADSharp/OSCADSharp/Dependencies.cs new file mode 100644 index 0000000..7a954eb --- /dev/null +++ b/OSCADSharp/OSCADSharp/Dependencies.cs @@ -0,0 +1,25 @@ +using OSCADSharp.Files; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp +{ + /// + /// Contains definitions for external APIs used by OSCADSharp + /// + public static class Dependencies + { + /// + /// Used to write scripts to file + /// + public static IFileWriter FileWriter = new DefaultFileWriter(); + + /// + /// Factory method to provide the class used to perform actions on output scripts + /// + public static Func FileInvokerFactory = (path) => { return new DefaultFileInvoker(path); }; + } +} diff --git a/OSCADSharp/OSCADSharp/Files/IFileInvoker.cs b/OSCADSharp/OSCADSharp/Files/IFileInvoker.cs index 0847311..9cf7f51 100644 --- a/OSCADSharp/OSCADSharp/Files/IFileInvoker.cs +++ b/OSCADSharp/OSCADSharp/Files/IFileInvoker.cs @@ -8,6 +8,8 @@ namespace OSCADSharp.Files { /// /// Invokes OpenSCAD actions on output files + /// + /// If these methods don't work, double check that your Settings.OpenSCADPath value is correct /// public interface IFileInvoker { diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs index 4e41c3c..6a62825 100644 --- a/OSCADSharp/OSCADSharp/OSCADObject.cs +++ b/OSCADSharp/OSCADSharp/OSCADObject.cs @@ -331,14 +331,14 @@ namespace OSCADSharp path += ".scad"; } - Settings.FileWriter.WriteAllLines(path, new string[] + Dependencies.FileWriter.WriteAllLines(path, new string[] { Settings.OSCADSharpHeader, Variables.Global.ToString(), this.ToString() }); - return new DefaultFileInvoker(filePath); + return Dependencies.FileInvokerFactory(filePath); } #endregion diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index 434d3fb..3be8f51 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -42,6 +42,7 @@ + diff --git a/OSCADSharp/OSCADSharp/Settings.cs b/OSCADSharp/OSCADSharp/Settings.cs index ba57744..0d87776 100644 --- a/OSCADSharp/OSCADSharp/Settings.cs +++ b/OSCADSharp/OSCADSharp/Settings.cs @@ -18,12 +18,7 @@ namespace OSCADSharp /// public static readonly string OSCADSharpHeader = String.Format("/*Code Generated using OSCADSharp on {0}. {1}{2}For more information, please visit https://github.com/Exolun/OSCADSharp */{3}", DateTime.Now.ToString(), Environment.NewLine, Environment.NewLine, Environment.NewLine); - - /// - /// Used to write scripts to file - /// - public static IFileWriter FileWriter = new DefaultFileWriter(); - + /// /// Path to the OpenSCAD executable for file invocation /// (Default value is set the default install directory on Windows)