public void Compile_MissingUsing_ShouldNotBeCompiled() { var processor = new MonoCSharpProcessor(); var script = processor.Compile(CreateNameValueCollectionScript); Assert.IsFalse(script.IsCompiled); Assert.IsFalse(String.IsNullOrEmpty(processor.MessageOutput.ToString())); processor.AddNamespace("System.Collections.Specialized"); script = processor.Compile(CreateNameValueCollectionScript); Assert.IsTrue(script.IsCompiled); Assert.IsTrue(String.IsNullOrEmpty(processor.MessageOutput.ToString())); }
public void CompileAndEvaluate_ModifyInputScript_ElementsOfInputListShouldBeSetToZero() { var processor = new MonoCSharpProcessor(); processor.AddReferenceAssembly(typeof(MyMath.MyMath).Assembly); var parameters = new Dictionary <string, object> { { "v1", new VectorD() } }; var script = processor.Compile(ModifyInputScript, parameters); Assert.IsTrue(script.IsCompiled); Assert.IsTrue(String.IsNullOrEmpty(processor.MessageOutput.ToString())); var v = new VectorD() { 1, 2, 3, 4, 5 };; parameters["v1"] = v; processor.Evaluate(script, parameters); Assert.IsTrue(v.All(e => e == 0)); v = new VectorD() { 1, 2, 3, 4, 5 }; parameters["v1"] = v; processor.Evaluate(parameters); Assert.IsTrue(v.All(e => e == 0)); }
public void Compile_TypoScript_ShouldNotBeCompiled() { var processor = new MonoCSharpProcessor(); var script = processor.Compile(TypoScript); Assert.IsFalse(script.IsCompiled); Assert.IsFalse(String.IsNullOrEmpty(processor.MessageOutput.ToString())); }
public void CompileAndEvaluate_CalculateDistanceScript_ResultShouldBeCorrect() { var processor = new MonoCSharpProcessor(); processor.AddReferenceAssembly(typeof(MyMath.MyMath).Assembly); var parameters = new Dictionary <string, object> { { "v1", new VectorD() }, { "v2", new VectorD() } }; var script = processor.Compile(CalculateDistanceScript, parameters); Assert.IsTrue(script.IsCompiled); Assert.IsTrue(String.IsNullOrEmpty(processor.MessageOutput.ToString())); parameters["v1"] = new VectorD() { 1, 2, 3, 4, 5 }; parameters["v2"] = new VectorD() { 1, 2, -3, 4, -5 }; var distance = processor.Evaluate <double>(script, parameters); Assert.AreEqual(2, distance); parameters["v1"] = new VectorD() { 1, 2, 3, 4, 5 }; parameters["v2"] = new VectorD() { -1, -2, -3, -4, -5 }; distance = processor.Evaluate <double>(script, parameters); Assert.AreEqual(5, distance); distance = processor.Evaluate <double>(parameters); Assert.AreEqual(5, distance); }