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 void TestApplyState() { var now = new DateTime(); IObjectState state = new MutableObjectState { ClassName = "Corgi", ObjectId = "abcd", ServerData = new Dictionary<string, object>() { { "exist", 2 }, { "change", "teletubies" } } }; IObjectState appliedState = new MutableObjectState { ClassName = "AnotherCorgi", ObjectId = "1234", CreatedAt = now, ServerData = new Dictionary<string, object>() { { "exist", 9 }, { "missing", "marasy" } } }; state = state.MutatedClone(mutableClone => { mutableClone.Apply(appliedState); }); Assert.AreEqual("Corgi", state.ClassName); Assert.AreEqual("1234", state.ObjectId); Assert.IsNotNull(state.CreatedAt); Assert.IsNull(state.UpdatedAt); Assert.AreEqual(3, state.Count()); Assert.AreEqual(9, state["exist"]); Assert.AreEqual("teletubies", state["change"]); Assert.AreEqual("marasy", state["missing"]); }
public void TestApplyOperation() { IAVFieldOperation op1 = new AVIncrementOperation(7); IAVFieldOperation op2 = new AVSetOperation("legendia"); IAVFieldOperation op3 = new AVSetOperation("vesperia"); var operations = new Dictionary<string, IAVFieldOperation>() { { "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 void TestMutatedClone() { IObjectState state = new MutableObjectState { ClassName = "Corgi" }; Assert.AreEqual("Corgi", state.ClassName); IObjectState newState = state.MutatedClone((mutableClone) => { mutableClone.ClassName = "AnotherCorgi"; mutableClone.CreatedAt = new DateTime(); }); Assert.AreEqual("Corgi", state.ClassName); Assert.IsNull(state.CreatedAt); Assert.AreEqual("AnotherCorgi", newState.ClassName); Assert.IsNotNull(newState.CreatedAt); Assert.AreNotSame(state, newState); }
public void TestApplyState() { DateTime now = new DateTime(); IObjectState state = new MutableObjectState { ClassName = "Corgi", ObjectId = "abcd", ServerData = new Dictionary <string, object>() { { "exist", 2 }, { "change", "teletubies" } } }; IObjectState appliedState = new MutableObjectState { ClassName = "AnotherCorgi", ObjectId = "1234", CreatedAt = now, ServerData = new Dictionary <string, object>() { { "exist", 9 }, { "missing", "marasy" } } }; state = state.MutatedClone(mutableClone => { mutableClone.Apply(appliedState); }); Assert.AreEqual("Corgi", state.ClassName); Assert.AreEqual("1234", state.ObjectId); Assert.IsNotNull(state.CreatedAt); Assert.IsNull(state.UpdatedAt); Assert.AreEqual(3, state.Count()); Assert.AreEqual(9, state["exist"]); Assert.AreEqual("teletubies", state["change"]); Assert.AreEqual("marasy", state["missing"]); }