[Test] public void ExecuteMakeUsesSymbolInClassName() { processor.Get<Symbols>().Save("symbol", "NUnit"); var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("fitSharp.Test.$symbol.Slim.SampleClass"); ExecuteOperation(executeMake, input, 2); Assert.IsTrue(processor.Get<SavedInstances>().GetValue("variable") is SampleClass); }
public void ExecuteMakeBadClassReturnsException() { var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("garbage"); ExecuteOperation(executeMake, input, 2); CheckForException("message:<<NO_CLASS garbage>>"); }
[Test] public void ExecuteCallBadMethodReturnsException() { processor.Get<SavedInstances>().Save("variable", new SampleClass()); var executeCall = new ExecuteCall { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("variable").AddBranchValue("garbage"); ExecuteOperation(executeCall, input, 2); CheckForException("message:<<NO_METHOD_IN_CLASS garbage fitSharp.Test.NUnit.Slim.SampleClass>>"); }
public void ExecuteImportAddsNamespace() { var executeImport = new ExecuteImport { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("import").AddBranchValue("fitSharp.Test.NUnit.Slim"); ExecuteOperation(executeImport, input, 2); Assert.IsTrue(processor.Create("SampleClass", new SlimTree()).Value is SampleClass); }
public void ExecuteDefaultReturnsException() { var executeDefault = new ExecuteDefault { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("garbage"); ExecuteOperation(executeDefault, input, 2); CheckForException("message:<<MALFORMED_INSTRUCTION step,garbage>>"); }
public void ExecuteCallUsesDomainAdapter() { processor.Store(new SavedInstance("variable", new SampleClass())); var executeCall = new ExecuteCall { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("variable").AddBranchValue("DomainMethod"); ExecuteOperation(executeCall, input, 2); Assert.AreEqual("domainstuff", result.Branches[1].Value); }
[Test] public void ExecuteMakeUsesSymbolAsObject() { var newClass = new SampleClass(); processor.Get<Symbols>().Save("symbol", newClass); var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("$symbol"); ExecuteOperation(executeMake, input, 2); Assert.AreEqual(newClass, processor.Get<SavedInstances>().GetValue("variable")); }
private void MakeSampleClass(string sampleData) { var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("scriptTableActor").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass").AddBranchValue(sampleData); ExecuteOperation(executeMake, input, 2); }
private void CallActorMethod(string methodName) { var executeCall = new ExecuteCall { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("scriptTableActor").AddBranchValue(methodName); ExecuteOperation(executeCall, input, 2); }
private Tree<string> ExecuteInstructions(Tree<string> instructions) { var results = new SlimTree(); foreach (Tree<string> statement in instructions.Branches) { var result = processor.Invoke(new SlimInstruction(), new MemberName(string.Empty), statement).GetValue<Tree<string>>(); results.AddBranchValue(result); if (ComposeException.WasAborted(result.ValueAt(1))) break; } return results; }
[Test] public void ExecuteCallAndAssignSavesSymbol() { processor.Get<SavedInstances>().Save("variable", new SampleClass()); var executeCallAndAssign = new ExecuteCallAndAssign { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("callAndAssign").AddBranchValue("symbol").AddBranchValue( "variable").AddBranchValue("sampleMethod"); ExecuteOperation(executeCallAndAssign, input, 2); Assert.AreEqual("testresult", result.ValueAt(1)); Assert.AreEqual("testresult", processor.Get<Symbols>().GetValue("symbol")); }
[Test] public void ExecuteMakeLibraryIsStacked() { var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass"); ExecuteOperation(executeMake, input, 2); foreach (TypedValue libraryInstance in processor.LibraryInstances) { Assert.IsTrue(libraryInstance.Value is SampleClass); return; } Assert.Fail(); }
protected static Tree <string> ParameterTree(Tree <string> input, int startingIndex) { var result = new SlimTree(); for (int i = startingIndex; i < input.Branches.Count; i++) { result.AddBranch(input.Branches[i]); } return(result); }
[Test] public void ExecuteDefaultReturnsException() { var executeDefault = new ExecuteDefault { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("garbage"); ExecuteOperation(executeDefault, input, 2); CheckForException("message:<<MALFORMED_INSTRUCTION step,garbage>>"); }
[Test] public void OperatorIsAddedFromConfiguration() { var configuration = new Configuration(); configuration.LoadXml("<config><fitSharp.Slim.Service.Service><addOperator>fitSharp.Test.NUnit.Slim.SampleOperator</addOperator></fitSharp.Slim.Service.Service></config>"); var statement = new SlimTree().AddBranchValue("step").AddBranchValue("sampleCommand"); var result = new Service(configuration).Execute(TypedValue.Void, statement).GetValue <Tree <string> >(); Assert.AreEqual("sampleResult", result.Branches[1].Value); }
[Test] public void ExecuteMakeBadClassReturnsException() { var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("garbage"); ExecuteOperation(executeMake, input, 2); CheckForException("message:<<NO_CLASS garbage>>"); }
[Test] public void ExecuteMakeUsesSymbolAsFullClassName() { processor.Get <Symbols>().Save("symbol", "fitSharp.Test.NUnit.Slim.SampleClass"); var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("$symbol"); ExecuteOperation(executeMake, input, 2); Assert.IsTrue(processor.Get <SavedInstances>().GetValue("variable") is SampleClass); }
[Test] public void ExecuteCallUsesDomainAdapter() { processor.Store(new SavedInstance("variable", new SampleClass())); var executeCall = new ExecuteCall { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("variable").AddBranchValue("DomainMethod"); ExecuteOperation(executeCall, input, 2); Assert.AreEqual("domainstuff", result.Branches[1].Value); }
public Tree <string> Compose(TypedValue instance) { var list = instance.Value as IList ?? new List <object>(); var tree = new SlimTree(); foreach (object value in list) { tree.AddBranch(Processor.Compose(value)); } return(tree); }
public void ExecuteCallOnMissingInstanceUsesLibrary() { var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass"); ExecuteOperation(executeMake, input, 2); var executeCall = new ExecuteCall { Processor = processor }; input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("garbage").AddBranchValue("SampleMethod"); SampleClass.MethodCount = 0; ExecuteOperation(executeCall, input, 2); Assert.AreEqual(1, SampleClass.MethodCount); }
[Test] public void ExecuteMakeUsesSymbolInClassName() { processor.Store(new Symbol("symbol", "NUnit")); var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("fitSharp.Test.$symbol.Slim.SampleClass"); ExecuteOperation(executeMake, input, 2); Assert.IsTrue(processor.Load(new SavedInstance("variable")).Instance is SampleClass); }
public void ExecuteCallAndAssignSavesSymbol() { processor.Store(new SavedInstance("variable", new SampleClass())); var executeCallAndAssign = new ExecuteCallAndAssign { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("callAndAssign").AddBranchValue("symbol").AddBranchValue( "variable").AddBranchValue("sampleMethod"); ExecuteOperation(executeCallAndAssign, input, 2); Assert.AreEqual("testresult", result.Branches[1].Value); Assert.AreEqual("testresult", processor.Load(new Symbol("symbol")).Instance); }
static SlimTree ReadList(DelimitedString input) { var count = int.Parse(input.ReadTo(":")); var result = new SlimTree(); for (var i = 0; i < count; i++) { var itemLength = int.Parse(input.ReadTo(":")); result.AddBranch(Read(input.Read(itemLength, 1))); } return(result); }
[Test] public void ExecuteMakeUsesSymbolAsObject() { var newClass = new SampleClass(); processor.Store(new Symbol("symbol", newClass)); var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("variable").AddBranchValue("$symbol"); ExecuteOperation(executeMake, input, 2); Assert.AreEqual(newClass, processor.Load(new SavedInstance("variable")).Instance); }
[Test] public void ExecuteCallAndAssignSavesSymbol() { processor.Store(new SavedInstance("variable", new SampleClass())); var executeCallAndAssign = new ExecuteCallAndAssign { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("callAndAssign").AddBranchValue("symbol").AddBranchValue( "variable").AddBranchValue("sampleMethod"); ExecuteOperation(executeCallAndAssign, input, 2); Assert.AreEqual("testresult", result.Branches[1].Value); Assert.AreEqual("testresult", processor.Load(new Symbol("symbol")).Instance); }
public void ExecuteAssignSavesSymol() { processor.Get <SavedInstances>().Save("variable", new SampleClass()); var executeAssign = new ExecuteAssign { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("assign").AddBranchValue("symbol").AddBranchValue( "value"); ExecuteOperation(executeAssign, input, 2); Assert.AreEqual("OK", result.ValueAt(1)); Assert.AreEqual("value", processor.Get <Symbols>().GetValue("symbol")); }
private Tree <string> ExecuteInstructions(Tree <string> instructions) { var results = new SlimTree(); foreach (Tree <string> statement in instructions.Branches) { var result = processor.Execute(statement).GetValue <Tree <string> >(); results.AddBranchValue(result); if (ComposeException.WasAborted(result.Branches[1].Value)) { break; } } return(results); }
[Test] public void ExecuteCallOnMissingInstanceUsesLibrary() { var executeMake = new ExecuteMake { Processor = processor }; var input = new SlimTree().AddBranchValue("step").AddBranchValue("make").AddBranchValue("librarystuff").AddBranchValue("fitSharp.Test.NUnit.Slim.SampleClass"); ExecuteOperation(executeMake, input, 2); var executeCall = new ExecuteCall { Processor = processor }; input = new SlimTree().AddBranchValue("step").AddBranchValue("call").AddBranchValue("garbage").AddBranchValue("SampleMethod"); SampleClass.MethodCount = 0; ExecuteOperation(executeCall, input, 2); Assert.AreEqual(1, SampleClass.MethodCount); }
public TypedValue Parse(Type type, TypedValue instance, Tree <string> parameters) { var values = parameters.IsLeaf ? SlimTree.Parse(parameters.Value) : parameters; if (type.IsArray) { var array = Array.CreateInstance(type.GetElementType(), values.Branches.Count); int i = 0; foreach (var branch in values.Branches) { array.SetValue(Processor.ParseTree(type.GetElementType(), branch).Value, i); i++; } return(new TypedValue(array)); } return(new TypedValue( values.Branches.Aggregate( (IList)Activator.CreateInstance(type), (list, branch) => { list.Add(Processor.ParseTree(type.GetGenericArguments()[0], branch).Value); return list; }))); }
private Tree<string> ExecuteInstructions(Tree<string> instructions) { var results = new SlimTree(); foreach (Tree<string> statement in instructions.Branches) { var result = processor.Execute(statement).GetValue<Tree<string>>(); results.AddBranchValue(result); if (ComposeException.WasAborted(result.Branches[1].Value)) break; } return results; }