static void Main() { TheClass testClass = new TheClass(); //reference type TheStruct testStruct = new TheStruct(); //value type string testString; //value type int testInteger; //value type testClass.willIChange = "Initial"; testStruct.willIChange = "Initial"; testString = "Initial"; testInteger = 0; Console.WriteLine($"Class field before method: {testClass.willIChange}"); Console.WriteLine($"Struct field before method: {testStruct.willIChange}"); Console.WriteLine($"String before method: {testString}"); Console.WriteLine($"Integer before method: {testInteger}"); Console.WriteLine(); ClassTaker(testClass); StructTaker(testStruct); StringTaker(testString); // we need to use 'ref' here too! intTaker(ref testInteger); Console.WriteLine(); Console.WriteLine($"Class field after method: {testClass.willIChange}"); Console.WriteLine($"Struct field after method: {testStruct.willIChange}"); Console.WriteLine($"String after method: {testString}"); Console.WriteLine($"Integer after method: {testInteger}"); Console.WriteLine(); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public static void Main() { TheStruct a = new TheStruct(); a.x = 1; structtaker(a); Console.WriteLine("a.x = {0}", a.x); }
public static void Main() { TheStruct a = new TheStruct(); TheClass b = new TheClass(); a.x = 1; b.x = 1; structtaker(a); classtaker(b); Console.WriteLine("a.x = {0}", a.x); Console.WriteLine("b.x = {0}", b.x); }
public void AccessPublicPropertyOnAStruct() { TheStruct myStruct = new TheStruct { PublicProperty = 22 }; TestPropertyValue <TheStruct, int> propValue = new TestPropertyValue <TheStruct, int> { Operand = myStruct, PropertyName = "PublicProperty" }; TestSequence seq = TestExpressionTracer.GetTraceablePropertyValue <TheStruct, int>(propValue, myStruct.PublicProperty.ToString()); TestRuntime.RunAndValidateWorkflow(seq); }
public void SetValueOfAnItemInMultiDimensionalIndexer() { // // Test case description: // Set value of an item in multi dimensional indexer. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; Variable <int> varIndex2 = new Variable <int>() { Default = 2, Name = "varIndex2" }; Variable <int> varIndex3 = new Variable <int>() { Default = 3, Name = "varIndex3" }; TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { OperandLocationVariable = var }; valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, 1)); valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, varIndex2)); valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, varIndex3)); int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var, varIndex2, varIndex3 }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx)[1, 2, 3].ToString()), HintMessage = value.ToString() } } }; TestRuntime.RunAndValidateWorkflow(seq); }
public void SetUninitializedIndices() { // // Test case description: // Try executing ValueTypeIndexerReference activity without initializing indices. Validation exception // expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx)[1].ToString()),HintMessage = value.ToString() } } }; string error = string.Format(ErrorStrings.IndicesAreNeeded, valueTypeIndexerReference.ProductActivity.GetType().Name, valueTypeIndexerReference.DisplayName); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypeIndexerReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void TrySetItemNullOperand() { // // Test case description: // Try executing ValueTypeIndexerReference activity without initializing indices. Validation exception // expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { Indices = { new TestArgument <int>(Direction.In, null, 2) } }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, } }; string error = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "OperandLocation", valueTypeIndexerReference.ProductActivity.GetType().Name, valueTypeIndexerReference.DisplayName); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypeIndexerReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void TrySettingReadOnlyField() { // // Test case description: // Try setting a read only field. Exception expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeFieldReference <TheStruct, int> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, int>() { FieldName = "readonlyField", OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeFieldReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx).readonlyField.ToString()),HintMessage = value.ToString() } } }; string error = string.Format(ErrorStrings.MemberIsReadOnly, "readonlyField", typeof(TheStruct).Name); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypeFieldReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void TrySettingNullFieldName() { // // Test case description: // Try setting a null OperandLocation. Validation exception expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeFieldReference <TheStruct, int> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, int>() { OperandLocationVariable = var }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeFieldReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx).publicField.ToString()),HintMessage = value.ToString() } } }; string error = string.Format(ErrorStrings.ActivityPropertyMustBeSet, "FieldName", valueTypeFieldReference.DisplayName); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypeFieldReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void TrySettingPropertyWithoutSetter() { // // Test case description: // Try setting a property which does not have a setter. Exception expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>() { PropertyName = "PropertyWithoutSetter", OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypePropertyReference, Value = value, ExpectedOutcome = Outcome.UncaughtException(typeof(InvalidOperationException)), }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, } }; string error = string.Format(ErrorStrings.MemberIsReadOnly, "PropertyWithoutSetter", typeof(TheStruct)); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypePropertyReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void TrySettingFieldOfNonExistentField() { // // Test case description: // Try setting value of a field in a type which does not exist. Validation exception expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeFieldReference <TheStruct, int> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, int>() { FieldName = "NonExistField", OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeFieldReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, } }; string error = string.Format(ErrorStrings.MemberNotFound, "NonExistField", typeof(TheStruct).Name); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypeFieldReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void TrySettingValueOfFieldNameNull() { // // Test case description: // Try executing ValueTypeFieldReference activity by setting FieldName to null. Validation exception // expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeFieldReference <TheStruct, int> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, int>() { FieldName = null, OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeFieldReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, } }; string error = string.Format(ErrorStrings.ActivityPropertyMustBeSet, "FieldName", valueTypeFieldReference.DisplayName); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypeFieldReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
private static int Main(string[] args) { try { TestClass newobj = new TestClass(); TheStruct s = new TheStruct(); StructTaker_Inline(s); return(100); } catch (Exception e) { Console.WriteLine(e.Message); return(666); } }
static void Main() { TheClass testClass = new TheClass(); TheStruct testStruct = new TheStruct(); testClass.willIChange = "Not Changed"; testStruct.willIChange = "Not Changed"; ClassTaker(testClass); StructTaker(testStruct); Console.WriteLine("Class field = {0}", testClass.willIChange); Console.WriteLine("Struct field = {0}", testStruct.willIChange); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
private static int Main(string[] args) { try { TestClass newobj = new TestClass(); TheStruct s = new TheStruct(); StructTaker_Inline(s); return 100; } catch (Exception e) { Console.WriteLine(e.Message); return 666; } }
public void TrySettingNullOperand() { // // Test case description: // Try setting a null OperandLocation. Validation exception expected. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>() { PropertyName = "PublicProperty", }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypePropertyReference, Value = value, }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, } }; string error = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "OperandLocation"); List <TestConstraintViolation> constraints = new List <TestConstraintViolation> { new TestConstraintViolation( error, valueTypePropertyReference.ProductActivity) }; TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void ThrowFromIndexer() { // // Test case description: // Throw from ‘this’ property TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { OperandLocationVariable = var, }; valueTypeIndexerReference.Indices.Add(new TestArgument <float>(Direction.In, null, 2)); int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value, ExpectedOutcome = Outcome.UncaughtException(typeof(Exception)), }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx)[2].ToString()),HintMessage = value.ToString() } } }; TestRuntime.RunAndValidateAbortedException(seq, typeof(Exception), null); }
public void SetPublicPropertyOnValueType() { // // Test case description: // Set a public property on value type. TheStruct valueType = new TheStruct { PublicProperty = 123 }; Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>() { PropertyName = "PublicProperty", OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypePropertyReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx).PublicProperty.ToString()),HintMessage = value.ToString() } } }; TestRuntime.RunAndValidateWorkflow(seq); }
public void SetPublicEnumFieldOnValueType() { // // Test case description: // Set a public enum field on value type. TheStruct valueType = new TheStruct { enumField = FileAccess.Write }; Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeFieldReference <TheStruct, FileAccess> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, FileAccess>() { FieldName = "enumField", OperandLocationVariable = var, }; System.IO.FileAccess value = System.IO.FileAccess.ReadWrite; TestAssign <System.IO.FileAccess> testAssign = new TestAssign <FileAccess>() { ToLocation = valueTypeFieldReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx).enumField.ToString()),HintMessage = value.ToString() } } }; TestRuntime.RunAndValidateWorkflow(seq); }
public void SetPublicPropertyOnAStruct() { TheStruct myStruct = new TheStruct { PublicProperty = 23 }; Variable <TheStruct> customType = new Variable <TheStruct>() { Name = "Custom", Default = myStruct }; TestPropertyReference <TheStruct, int> propReference = new TestPropertyReference <TheStruct, int> { OperandVariable = customType, PropertyName = "PublicProperty" }; TestSequence seq = new TestSequence { Variables = { customType }, Activities = { new TestAssign <int> { ToLocation = propReference, Value = 27 }, new TestWriteLine { MessageExpression = e => customType.Get(e).publicField.ToString(), HintMessage = "0" } } }; string error = string.Format(ErrorStrings.TargetTypeIsValueType, typeof(PropertyReference <TheStruct, int>).Name, propReference.DisplayName); List <TestConstraintViolation> constraints = new List <TestConstraintViolation>(); constraints.Add(new TestConstraintViolation( error, propReference.ProductActivity)); TestRuntime.ValidateWorkflowErrors(seq, constraints, error); }
public void SetIndexWithCompatibleType() { // // Test case description: // Try setting short indexed on integer indexer. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { OperandLocationVariable = var, }; valueTypeIndexerReference.Indices.Add(new TestArgument <short>(Direction.In, null, 2)); int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx)[2].ToString()),HintMessage = value.ToString() } } }; TestRuntime.RunAndValidateWorkflow(seq); }
public void ThrowExceptionFromSetterOfCustomTypeProperty() { // // Test case description: // Try setting a property which throws from setter. TheStruct valueType = new TheStruct(); Variable <TheStruct> var = new Variable <TheStruct>() { Default = valueType, Name = "var" }; TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>() { PropertyName = "ThrowInSetterProperty", OperandLocationVariable = var, }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypePropertyReference, Value = value, ExpectedOutcome = Outcome.UncaughtException(typeof(System.Reflection.TargetInvocationException)), }; TestSequence seq = new TestSequence() { Variables = { var }, Activities = { testAssign, } }; TestRuntime.RunAndValidateAbortedException(seq, typeof(System.Reflection.TargetInvocationException), null); }
public static void structtaker(TheStruct s) { s.x = 5; }
public void SetDelegateArgument() { // for using delegate argument TheStruct valueType = new TheStruct(); int indiceValue = 2; DelegateInArgument <int> indice = new DelegateInArgument <int>(); Variable <TheStruct> var = VariableHelper.CreateInitialized <TheStruct>("var", valueType); TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { OperandLocationVariable = var, }; valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, (env) => indice.Get(env))); int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value }; TestSequence seq = new TestSequence() { Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx)[indiceValue].ToString()) } } }; CoreWf.Statements.Sequence outerSeq = new CoreWf.Statements.Sequence() { Variables = { var }, Activities = { new InvokeAction <int>() { Argument = indiceValue, Action = new ActivityAction <int>() { Argument = indice, Handler = seq.ProductActivity } } } }; TestCustomActivity testActivity = TestCustomActivity <CoreWf.Statements.Sequence> .CreateFromProduct(outerSeq); UnorderedTraces traces = new UnorderedTraces() { Steps = { new UserTrace(value.ToString()) } }; testActivity.ActivitySpecificTraces.Add(traces); ExpectedTrace expectedTrace = testActivity.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(ActivityTrace)); TestRuntime.RunAndValidateWorkflow(testActivity, expectedTrace); }
static void StructTaker(TheStruct s) { s.willIChange = "Changed"; }
private static void StructTaker_Inline(TheStruct Struct) { Struct.fieldinStruct = "xyz"; }
static void StructTaker(TheStruct s) { s.willIChange = "Changed"; Console.WriteLine($"Struct field inside method: {s.willIChange}"); }