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 TestProperties() { var now = new DateTime(); IObjectState state = new MutableObjectState { ClassName = "Corgi", UpdatedAt = now, CreatedAt = now, ServerData = new Dictionary<string, object>() { { "1", "Choucho" }, { "2", "Miku" }, { "3", "Halyosy" } } }; Assert.AreEqual("Corgi", state.ClassName); Assert.AreEqual(now, state.UpdatedAt); Assert.AreEqual(now, state.CreatedAt); Assert.AreEqual(3, state.Count()); Assert.AreEqual("Choucho", state["1"]); Assert.AreEqual("Miku", state["2"]); Assert.AreEqual("Halyosy", state["3"]); }
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"]); }
public void TestProperties() { var now = new DateTime(); IObjectState state = new MutableObjectState { ClassName = "Corgi", UpdatedAt = now, CreatedAt = now, ServerData = new Dictionary <string, object>() { { "1", "Choucho" }, { "2", "Miku" }, { "3", "Halyosy" } } }; Assert.AreEqual("Corgi", state.ClassName); Assert.AreEqual(now, state.UpdatedAt); Assert.AreEqual(now, state.CreatedAt); Assert.AreEqual(3, state.Count()); Assert.AreEqual("Choucho", state["1"]); Assert.AreEqual("Miku", state["2"]); Assert.AreEqual("Halyosy", state["3"]); }