public void ListenAddRemove() { var newData = GetRawData(); var players = (IndexedDictionary <string, object>)newData ["players"]; players.Remove("key1"); players.Add("key3", new { value = "new" }); var listenCalls = 0; container.Listen("players/:id", (DataChange change) => { listenCalls++; if (change.operation == "add") { Assert.AreEqual("key3", change.path["id"]); Assert.AreEqual(new { value = "new" }, change.value); } else if (change.operation == "remove") { Assert.AreEqual("key1", change.path["id"]); } }); container.Set(new IndexedDictionary <string, object>(newData)); Assert.AreEqual(2, listenCalls); }
public void ListenInitialState() { var container = new DeltaContainer(new IndexedDictionary <string, object>()); var listenCalls = 0; container.Listen("players/:id/position/:attribute", (DataChange change) => { listenCalls++; }); container.Listen("turn", (DataChange change) => { listenCalls++; }); container.Listen("game/turn", (DataChange change) => { listenCalls++; }); container.Listen("messages/:number", (DataChange change) => { listenCalls++; }); container.Set(GetRawData()); Assert.AreEqual(9, listenCalls); }
public void ListenAddString() { var newData = GetRawData(); newData ["some_string"] = "hello!"; var listenCalls = 0; container.Listen("some_string", (DataChange change) => { listenCalls++; Assert.AreEqual("add", change.operation); Assert.AreEqual("hello!", change.value); }); container.Set(newData); Assert.AreEqual(1, listenCalls); }