public void TestApplyOperation() { IParseFieldOperation op1 = new ParseIncrementOperation(7); IParseFieldOperation op2 = new ParseSetOperation("legendia"); IParseFieldOperation op3 = new ParseSetOperation("vesperia"); Dictionary <string, IParseFieldOperation> operations = new Dictionary <string, IParseFieldOperation>() { { "exist", op1 }, { "missing", op2 }, { "change", op3 } }; IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "exist", 2 }, { "change", "teletubies" } } }; Assert.AreEqual(2, state["exist"]); Assert.AreEqual("teletubies", state["change"]); state = state.MutatedClone(mutableClone => mutableClone.Apply(operations)); Assert.AreEqual(3, state.Count()); Assert.AreEqual(9, state["exist"]); Assert.AreEqual("legendia", state["missing"]); Assert.AreEqual("vesperia", state["change"]); }
public object this[string key] { get { if (estimatedData.TryGetValue(key, out object value)) { if (value is ParseRelation <ParseObject> relation) { relation.Key = key; relation.Parent = this; } return(value); } return(null); } set { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); } if (key.StartsWith("_")) { throw new ArgumentException("key should not start with '_'"); } if (key == "objectId" || key == "createdAt" || key == "updatedAt") { throw new ArgumentException($"{key} is reserved by LeanCloud"); } ParseSetOperation setOp = new ParseSetOperation(value); ApplyOperation(key, setOp); } }