public void should_call_on_change_delegate() { SimCapiPointArray simCapiPointArray = new SimCapiPointArray(); simCapiPointArray.getPointList().Add(new Vector2(1, 2)); simCapiPointArray.getPointList().Add(new Vector2(3, 4)); simCapiPointArray.getPointList().Add(new Vector2(5, 6)); string exposedName = "exposeName"; simCapiPointArray.expose(exposedName, true, true); bool changeDelegateCalled = false; bool correctValue = false; simCapiPointArray.setChangeDelegate( delegate(Vector2[] value, ChangedBy changedBy) { changeDelegateCalled = true; if (value.Length == 3 && value[0] == new Vector2(6, 5) && value[1] == new Vector2(4, 3) && value[2] == new Vector2(2, 1)) { correctValue = true; } }); // Create the VALUE_CHANGE message SimCapiValue simCapiValue = new SimCapiValue(exposedName, SimCapiValueType.ARRAY, false, false, false, new ArrayData(new[] { "(6;5)", "(4;3)", "(2;1)" })); Dictionary <string, SimCapiValue> valueDictionary = new Dictionary <string, SimCapiValue>(); valueDictionary.Add(exposedName, simCapiValue); string valueChangedJson = SimCapiJsonMaker.create_VALUE_CHANGE_force_arrays(_transporter.getHandshake(), valueDictionary); _transporter.reciveJsonMessage(valueChangedJson); Assert.AreEqual(true, changeDelegateCalled); Assert.AreEqual(true, correctValue); }
public void should_call_on_change_delegate() { SimCapiStringArray simCapiStringArray = new SimCapiStringArray(); simCapiStringArray.getList().Add("One"); simCapiStringArray.getList().Add("Two"); simCapiStringArray.getList().Add("Three"); string exposedName = "exposeName"; simCapiStringArray.expose(exposedName, true, true); bool changeDelegateCalled = false; bool correctValue = false; simCapiStringArray.setChangeDelegate( delegate(string[] stringArray, ChangedBy changedBy) { changeDelegateCalled = true; if (stringArray.Length == 3 && stringArray[0] == "a" && stringArray[1] == "b" && stringArray[2] == "c") { correctValue = true; } }); // Create the VALUE_CHANGE message SimCapiValue simCapiValue = new SimCapiValue(exposedName, SimCapiValueType.STRING, false, false, false, new ArrayData(new[] { "a", "b", "c" })); Dictionary <string, SimCapiValue> valueDictionary = new Dictionary <string, SimCapiValue>(); valueDictionary.Add(exposedName, simCapiValue); string valueChangedJson = SimCapiJsonMaker.create_VALUE_CHANGE(_transporter.getHandshake(), valueDictionary); _transporter.reciveJsonMessage(valueChangedJson); Assert.AreEqual(true, changeDelegateCalled); Assert.AreEqual(true, correctValue); }
public void should_call_on_change_delegate() { SimCapiMathExpression simCapiMathExpression = new SimCapiMathExpression("InitialValue"); string exposedName = "exposeName"; simCapiMathExpression.expose(exposedName, true, true); bool changeDelegateCalled = false; bool correctValue = false; string newValue = "newValue"; simCapiMathExpression.setChangeDelegate( delegate(string value, ChangedBy changedBy) { changeDelegateCalled = true; if (value == newValue) { correctValue = true; } }); // Create the VALUE_CHANGE message SimCapiValue simCapiValue = new SimCapiValue(exposedName, SimCapiValueType.STRING, false, false, false, new StringData(newValue)); Dictionary <string, SimCapiValue> valueDictionary = new Dictionary <string, SimCapiValue>(); valueDictionary.Add(exposedName, simCapiValue); string valueChangedJson = SimCapiJsonMaker.create_VALUE_CHANGE(_transporter.getHandshake(), valueDictionary); _transporter.reciveJsonMessage(valueChangedJson); Assert.AreEqual(true, changeDelegateCalled); Assert.AreEqual(true, correctValue); }
public void should_call_on_change_delegate() { SimCapiEnum <EnumForTest> simCapiEnum = new SimCapiEnum <EnumForTest>(EnumForTest.INITIAL); string exposedName = "exposeName"; simCapiEnum.expose(exposedName, true, true); bool changeDelegateCalled = false; bool correctValue = false; simCapiEnum.setChangeDelegate( delegate(EnumForTest value, ChangedBy changedBy) { changeDelegateCalled = true; if (value == EnumForTest.CHANGED) { correctValue = true; } }); // Create the VALUE_CHANGE message SimCapiValue simCapiValue = new SimCapiValue(exposedName, SimCapiValueType.STRING, false, false, false, new StringData("CHANGED")); Dictionary <string, SimCapiValue> valueDictionary = new Dictionary <string, SimCapiValue>(); valueDictionary.Add(exposedName, simCapiValue); string valueChangedJson = SimCapiJsonMaker.create_VALUE_CHANGE(_transporter.getHandshake(), valueDictionary); _transporter.reciveJsonMessage(valueChangedJson); Assert.AreEqual(true, changeDelegateCalled); Assert.AreEqual(true, correctValue); }