public void FakeWFTemplateImperative1() { // This is the semantically equivalent code to the markup example. // Any conditional logical in the construction of the activity // tree is not representable in xaml. // var iVar = new FakeVariable <int>() { Name = "i" }; var loop = new FakeForEach <int>() { LoopVariable = iVar, ItemsSource = new int[] { 1, 2, 3 }, Body = () => new FakeAppendIntToString() { Target = new FakeLookupVariable <string>("global"), Content = iVar } }; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); string globalFinalValue = global.GetValue(null); Assert.AreEqual("Hello World123", globalFinalValue); }
public void FakeWFTemplateImperative3() { // This is identical to #2, however using a factory method // to get better type infrencing. C# 3.0 doesn't do inferencing // based on the LHS, so you have to type all the expr variables. // var loop = new FakeForEach <int>() { LoopVariable = new FakeVariable <int>() { Name = "i" }, ItemsSource = new int[] { 1, 2, 3 }, Body = () => (FakeActivity) new FakeAppendIntToString() { Target = new FakeLookupVariable <string>("global"), Content = new FakeLookupVariable <int>("i") } }; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); string globalFinalValue = global.GetValue(null); Assert.AreEqual("Hello World123", globalFinalValue); }
public void FakeWFTemplateImperative2() { // This is the more natural C# developer intuition. // Notice that the string LoopVariableName is effectively // ignored. // var loop = new FakeForEach <int>() { LoopVariable = new FakeVariable <int>() { Name = "i" }, ItemsSource = new int[] { 1, 2, 3 }, Body = () => new FakeAppendIntToString() { Target = new FakeLookupVariable <string>("global"), Content = new FakeLookupVariable <int>("i") } }; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); string globalFinalValue = global.GetValue(null); Assert.AreEqual("Hello World123", globalFinalValue); }