mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +00:00
Shifted references to IFileInvoker to Dependencies.cs, added factory func to Dependencies.cs for providing IFileInvoker.
This commit is contained in:
parent
8b05e2af6a
commit
2976110f05
@ -148,7 +148,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; });
|
||||
Settings.FileWriter = mock.Object;
|
||||
Dependencies.FileWriter = mock.Object;
|
||||
|
||||
cube.ToFile("myFile");
|
||||
|
||||
@ -165,7 +165,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; });
|
||||
Settings.FileWriter = mock.Object;
|
||||
Dependencies.FileWriter = mock.Object;
|
||||
|
||||
cube.ToFile("myFile");
|
||||
|
||||
|
||||
@ -24,7 +24,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; });
|
||||
Settings.FileWriter = mock.Object;
|
||||
Dependencies.FileWriter = mock.Object;
|
||||
|
||||
cube.ToFile("myFile");
|
||||
|
||||
|
||||
25
OSCADSharp/OSCADSharp/Dependencies.cs
Normal file
25
OSCADSharp/OSCADSharp/Dependencies.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains definitions for external APIs used by OSCADSharp
|
||||
/// </summary>
|
||||
public static class Dependencies
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to write scripts to file
|
||||
/// </summary>
|
||||
public static IFileWriter FileWriter = new DefaultFileWriter();
|
||||
|
||||
/// <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); };
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,8 @@ namespace OSCADSharp.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// Invokes OpenSCAD actions on output files
|
||||
///
|
||||
/// If these methods don't work, double check that your Settings.OpenSCADPath value is correct
|
||||
/// </summary>
|
||||
public interface IFileInvoker
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Dependencies.cs" />
|
||||
<Compile Include="Files\DefaultFileInvoker.cs" />
|
||||
<Compile Include="Files\DefaultFileWriter.cs" />
|
||||
<Compile Include="Files\IFileInvoker.cs" />
|
||||
|
||||
@ -18,12 +18,7 @@ namespace OSCADSharp
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Used to write scripts to file
|
||||
/// </summary>
|
||||
public static IFileWriter FileWriter = new DefaultFileWriter();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Path to the OpenSCAD executable for file invocation
|
||||
/// (Default value is set the default install directory on Windows)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user