Esempio n. 1
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }