mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-22 10:48:27 +00:00
Added a test / changes to ensure null globals and/or null variable names do not affect outputs.
This commit is contained in:
parent
052760ecf1
commit
8678c3293d
@ -158,8 +158,8 @@ namespace OSCADSharp.UnitTests
|
|||||||
public void OSCADObject_ToFileIncludesGlobalVariablesDefinedInSettings()
|
public void OSCADObject_ToFileIncludesGlobalVariablesDefinedInSettings()
|
||||||
{
|
{
|
||||||
var cube = new Cube();
|
var cube = new Cube();
|
||||||
string[] output = null;
|
|
||||||
Settings.Globals["$fn"] = 100;
|
Settings.Globals["$fn"] = 100;
|
||||||
|
string[] output = null;
|
||||||
|
|
||||||
var mock = new Mock<IFileWriter>();
|
var mock = new Mock<IFileWriter>();
|
||||||
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
|
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
|
||||||
@ -167,8 +167,8 @@ namespace OSCADSharp.UnitTests
|
|||||||
Settings.FileWriter = mock.Object;
|
Settings.FileWriter = mock.Object;
|
||||||
|
|
||||||
cube.ToFile("myFile");
|
cube.ToFile("myFile");
|
||||||
|
bool outputMatches = "$fn = 100;\r\n" == output[1];
|
||||||
Assert.AreEqual("$fn = 100;\r\n", output[1]);
|
Assert.IsTrue(outputMatches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,7 @@
|
|||||||
</Otherwise>
|
</Otherwise>
|
||||||
</Choose>
|
</Choose>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="SettingsTests.cs" />
|
||||||
<Compile Include="Solids\CubeTests.cs" />
|
<Compile Include="Solids\CubeTests.cs" />
|
||||||
<Compile Include="Solids\CylinderTests.cs" />
|
<Compile Include="Solids\CylinderTests.cs" />
|
||||||
<Compile Include="Transforms\HullTests.cs" />
|
<Compile Include="Transforms\HullTests.cs" />
|
||||||
|
|||||||
33
OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs
Normal file
33
OSCADSharp/OSCADSharp.UnitTests/SettingsTests.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Moq;
|
||||||
|
using OSCADSharp.Scripting;
|
||||||
|
using OSCADSharp.Solids;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.UnitTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class SettingsTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void Settings_NullVariablesDoNothing()
|
||||||
|
{
|
||||||
|
var cube = new Cube();
|
||||||
|
Settings.Globals["thing"] = null;
|
||||||
|
string[] output = null;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
cube.ToFile("myFile");
|
||||||
|
|
||||||
|
Assert.AreEqual("", output[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -54,6 +54,11 @@ namespace OSCADSharp.Scripting
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
foreach (var kvp in this.variables)
|
foreach (var kvp in this.variables)
|
||||||
{
|
{
|
||||||
|
if(kvp.Value == null || String.IsNullOrEmpty(kvp.Value.ToString()) || String.IsNullOrEmpty(kvp.Key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
sb.Append(kvp.Key);
|
sb.Append(kvp.Key);
|
||||||
sb.Append(" = ");
|
sb.Append(" = ");
|
||||||
sb.Append(kvp.Value);
|
sb.Append(kvp.Value);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user