public void RemoveShouldRemoveItem() { SyncListTestObject serverList = new SyncListTestObject(); SyncListTestObject clientList = new SyncListTestObject(); SyncListTest.SerializeAllTo(serverList, clientList); // add some items TestObject item1 = new TestObject { id = 1, text = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nostrum ullam aliquid perferendis, aut nihil sunt quod ipsum corporis a. Cupiditate, alias. Commodi, molestiae distinctio repellendus dolor similique delectus inventore eum." }; serverList.Add(item1); TestObject item2 = new TestObject { id = 2, text = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nostrum ullam aliquid perferendis, aut nihil sunt quod ipsum corporis a. Cupiditate, alias. Commodi, molestiae distinctio repellendus dolor similique delectus inventore eum." }; serverList.Add(item2); // sync SyncListTest.SerializeDeltaTo(serverList, clientList); // clear all items serverList.Remove(item1); // sync SyncListTest.SerializeDeltaTo(serverList, clientList); Assert.IsFalse(clientList.Any(x => x.id == item1.id)); Assert.IsTrue(clientList.Any(x => x.id == item2.id)); }
public void ListIsDirtyWhenModifingAndSettingStruct() { SyncList <TestPlayer> serverList = new SyncList <TestPlayer>(); SyncList <TestPlayer> clientList = new SyncList <TestPlayer>(); // set up dirty callback int serverListDirtyCalled = 0; serverList.OnDirty = () => ++ serverListDirtyCalled; SyncListTest.SerializeAllTo(serverList, clientList); serverList.Add(new TestPlayer { item = new TestItem { price = 10 } }); Assert.That(serverListDirtyCalled, Is.EqualTo(1)); SyncListTest.SerializeDeltaTo(serverList, clientList); serverListDirtyCalled = 0; TestPlayer player = serverList[0]; player.item.price = 15; serverList[0] = player; Assert.That(serverListDirtyCalled, Is.EqualTo(1)); }
public void OldValueShouldNotBeNewValue() { SyncList <TestPlayer> serverList = new SyncList <TestPlayer>(); SyncList <TestPlayer> clientList = new SyncList <TestPlayer>(); SyncListTest.SerializeAllTo(serverList, clientList); serverList.Add(new TestPlayer { item = new TestItem { price = 10 } }); SyncListTest.SerializeDeltaTo(serverList, clientList); TestPlayer player = serverList[0]; player.item.price = 15; serverList[0] = player; bool callbackCalled = false; clientList.Callback += (SyncList <TestPlayer> .Operation op, int itemIndex, TestPlayer oldItem, TestPlayer newItem) => { Assert.That(op == SyncList <TestPlayer> .Operation.OP_SET, Is.True); Assert.That(itemIndex, Is.EqualTo(0)); Assert.That(oldItem.item.price, Is.EqualTo(10)); Assert.That(newItem.item.price, Is.EqualTo(15)); callbackCalled = true; }; SyncListTest.SerializeDeltaTo(serverList, clientList); Assert.IsTrue(callbackCalled); }
public void ListIsDirtyWhenModifingAndSettingStruct() { var serverList = new SyncListTestPlayer(); var clientList = new SyncListTestPlayer(); SyncListTest.SerializeAllTo(serverList, clientList); serverList.Add(new TestPlayer { item = new TestItem { price = 10 } }); SyncListTest.SerializeDeltaTo(serverList, clientList); Assert.That(serverList.IsDirty, Is.False); TestPlayer player = serverList[0]; player.item.price = 15; serverList[0] = player; Assert.That(serverList.IsDirty, Is.True); }
public void ListIsDirtyWhenModifingAndSettingStruct() { // let the weaver know to generate a reader and writer for TestPlayer _ = Writer <TestPlayer> .write; var serverList = new SyncList <TestPlayer>(); var clientList = new SyncList <TestPlayer>(); SyncListTest.SerializeAllTo(serverList, clientList); serverList.Add(new TestPlayer { item = new TestItem { price = 10 } }); SyncListTest.SerializeDeltaTo(serverList, clientList); Assert.That(serverList.IsDirty, Is.False); TestPlayer player = serverList[0]; player.item.price = 15; serverList[0] = player; Assert.That(serverList.IsDirty, Is.True); }