public void should_expose_value() { SimCapiStringArray simCapiStringArray = new SimCapiStringArray(); simCapiStringArray.getList().Add("One"); simCapiStringArray.getList().Add("Two"); simCapiStringArray.getList().Add("Three"); string exposedName = "exposeName"; simCapiStringArray.expose(exposedName, true, true); Dictionary <string, SimCapiValue> _outGoingMap = TestHelpers.getReferenceField <Dictionary <string, SimCapiValue> >(_transporter, "_outGoingMap"); Assert.AreNotEqual(null, _outGoingMap); Assert.AreEqual(true, _outGoingMap.ContainsKey(exposedName)); }
public void should_error_when_try_to_expose_twice() { SimCapiStringArray simCapiStringArray = new SimCapiStringArray(); simCapiStringArray.getList().Add("One"); simCapiStringArray.getList().Add("Two"); simCapiStringArray.getList().Add("Three"); string exposedName = "exposeName"; simCapiStringArray.expose(exposedName, true, true); Assert.Catch( delegate() { simCapiStringArray.expose(exposedName, true, true); }); }
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 Init() { Debugger.AddProcessor(ProcessCmd); // Adds Seperate insert Body Permission var capiInsertBody = new SimCapiBoolean(false); capiInsertBody.expose("Permission.InsertBody", false, false); capiInsertBody.setChangeDelegate(delegate(bool value, ChangedBy by) { // Add Permisison on true. if (value && !capiPerms.getList().Contains("InsertBody")) { capiPerms.getList().Add("InsertBody"); capiPerms.updateValue(); } // Remove Permission on false. else if (!value && capiPerms.getList().Contains("InsertBody")) { capiPerms.getList().Remove("InsertBody"); capiPerms.updateValue(); } }); capiPerms = new SimCapiStringArray(); capiPerms.expose("Permission.List", false, false); }