diff --git a/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs b/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs index 3a1dff2..824a5d2 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs +++ b/OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs @@ -30,5 +30,21 @@ namespace OSCADSharp.UnitTests Assert.AreEqual("", output[1]); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void Settings_NullOpenSCADPathThrowsError() + { + Settings.OpenSCADPath = null; + + var cube = new Cube(); + + var mock = new Mock(); + mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny(), It.IsAny())) + .Callback((path, contents) => { }); + Dependencies.FileWriter = mock.Object; + + cube.ToFile("test").Open(); + } } } diff --git a/OSCADSharp/OSCADSharp/Files/DefaultFileInvoker.cs b/OSCADSharp/OSCADSharp/Files/DefaultFileInvoker.cs index 2980866..89b74f9 100644 --- a/OSCADSharp/OSCADSharp/Files/DefaultFileInvoker.cs +++ b/OSCADSharp/OSCADSharp/Files/DefaultFileInvoker.cs @@ -17,12 +17,26 @@ namespace OSCADSharp.Files public void CreateModel(string outputFile) { - Process.Start(Settings.OpenSCADPath, String.Format("-o {0} {1}", outputFile, this.filePath)); + try + { + Process.Start(Settings.OpenSCADPath, String.Format("-o {0} {1}", outputFile, this.filePath)); + } + catch (InvalidOperationException) + { + throw new InvalidOperationException("Cannot open because Settings.OpenSCADPath is not a valid file path. Please check that the path defined points to you OpenSCAD executable."); + } } public void Open() { - Process.Start(Settings.OpenSCADPath, String.Format("{0}", this.filePath)); + try + { + Process.Start(Settings.OpenSCADPath, String.Format("{0}", this.filePath)); + } + catch (InvalidOperationException) + { + throw new InvalidOperationException("Cannot open because Settings.OpenSCADPath is not a valid file path. Please check that the path defined points to you OpenSCAD executable."); + } } } }