Added setters for Dependency file operation interfaces

This commit is contained in:
Michael L Smith 2016-03-12 14:15:18 -08:00
parent 308aa7f25c
commit 5425cad195
4 changed files with 27 additions and 7 deletions

View File

@ -145,7 +145,7 @@ namespace OSCADSharp.UnitTests
var mock = new Mock<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { output = contents; });
Dependencies.FileWriter = mock.Object;
Dependencies.SetFileWriter(mock.Object);
cube.ToFile("myFile");
@ -162,7 +162,7 @@ namespace OSCADSharp.UnitTests
var mock = new Mock<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { output = contents; });
Dependencies.FileWriter = mock.Object;
Dependencies.SetFileWriter(mock.Object);
cube.ToFile("myFile");

View File

@ -24,7 +24,7 @@ namespace OSCADSharp.UnitTests.Scripting
var compound = new Variable("x", 5) / 12;
string type = compound.GetType().ToString();
Assert.AreEqual("OSCADSharp.Scripting.CompoundVariable", type);
Assert.AreEqual("OSCADSharp.CompoundVariable", type);
}
}
}

View File

@ -21,7 +21,7 @@ namespace OSCADSharp.UnitTests
var mock = new Mock<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { output = contents; });
Dependencies.FileWriter = mock.Object;
Dependencies.SetFileWriter(mock.Object);
cube.ToFile("myFile");
@ -39,7 +39,7 @@ namespace OSCADSharp.UnitTests
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;
Dependencies.SetFileWriter(mock.Object);
cube.ToFile("test").Open();
}

View File

@ -14,11 +14,31 @@ namespace OSCADSharp
/// <summary>
/// Used to write scripts to file
/// </summary>
public static IFileWriter FileWriter = new DefaultFileWriter();
public static IFileWriter FileWriter { get; private set; } = new DefaultFileWriter();
/// <summary>
/// Sets the filewriter for OSCADSharp to use
/// </summary>
/// <param name="writer"></param>
public static void SetFileWriter(IFileWriter writer)
{
FileWriter = writer;
}
/// <summary>
/// Factory method to provide the class used to perform actions on output scripts
/// </summary>
public static Func<string, IFileInvoker> FileInvokerFactory = (path) => { return new DefaultFileInvoker(path); };
public static Func<string, IFileInvoker> FileInvokerFactory { get; private set; } = (path) => { return new DefaultFileInvoker(path); };
/// <summary>
/// Sets the factory method OSCADSharp will use to get
/// file invoker objects
/// </summary>
/// <param name="invokerFactoryMethod"></param>
public static void SetFileInvokerFactory(Func<string, IFileInvoker> invokerFactoryMethod)
{
FileInvokerFactory = invokerFactoryMethod;
}
}
}