Test for .Open() if file path is invalid.

This commit is contained in:
Michael Smith 2016-02-26 18:11:56 -08:00
parent d5ec961cb1
commit 6b628d9bca
2 changed files with 32 additions and 2 deletions

View File

@ -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<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { });
Dependencies.FileWriter = mock.Object;
cube.ToFile("test").Open();
}
}
}

View File

@ -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.");
}
}
}
}