public void AddingItems_AfterClear_ShouldSynchronizeItems()
        {
            var sourceGameWorld = new NotifyPropertyChangedTestGameWorld {
                RandomIntProperty = 5
            };

            var sourceSynchronizerRoot = new SourceSynchronizerRoot(sourceGameWorld);

            sourceGameWorld.Players.Clear();

            var targetSynchronizerRoot = new TargetSynchronizerRoot <NotifyPropertyChangedTestGameWorld>(sourceSynchronizerRoot.WriteFullAndDispose());

            sourceGameWorld.Players.Add("player1", new NotifyPropertyChangedTestPlayer {
                Name = "player1", Health = 100, Level = 30
            });
            sourceGameWorld.Players.Add("player2", new NotifyPropertyChangedTestPlayer {
                Name = "player2", Health = 44, Level = 1337
            });

            targetSynchronizerRoot.Read(sourceSynchronizerRoot.WriteChangesAndDispose().SetTick(TimeSpan.FromMilliseconds(10)));

            NotifyPropertyChangedTestGameWorld targetGameWorld = targetSynchronizerRoot.Reference;

            AssertExtension.AssertCloneEqual(sourceGameWorld, targetGameWorld);
        }
        public void AddingItems_AfterClear_ShouldSynchronizeItems()
        {
            var hashSetTestObject = new NotifyPropertyChangedHashSetTestObject {
                RandomIntProperty = 5
            };

            var SourceSynchronizerRoot = new SourceSynchronizerRoot(hashSetTestObject);

            hashSetTestObject.Players.Clear();

            var TargetSynchronizerRoot = new TargetSynchronizerRoot <NotifyPropertyChangedHashSetTestObject>(SourceSynchronizerRoot.WriteFullAndDispose());

            hashSetTestObject.Players.Add(new NotifyPropertyChangedTestPlayer {
                Name = "player1", Health = 100, Level = 30
            });
            hashSetTestObject.Players.Add(new NotifyPropertyChangedTestPlayer {
                Name = "player2", Health = 44, Level = 1337
            });

            TargetSynchronizerRoot.Read(SourceSynchronizerRoot.WriteChangesAndDispose().SetTick(TimeSpan.FromMilliseconds(10)));

            NotifyPropertyChangedHashSetTestObject targetGameWorld = TargetSynchronizerRoot.Reference;

            AssertExtension.AssertCloneEqual(hashSetTestObject, targetGameWorld);
        }
        public void SynchronizeChangesAddedItemTest()
        {
            var sourceGameWorld = new TestGameWorld();

            sourceGameWorld.RandomIntProperty = 5;

            var syncSourceRoot = new SyncSourceRoot(sourceGameWorld, _sourceSettings);

            var syncTargetRoot =
                new SyncTargetRoot <TestGameWorld>(syncSourceRoot.WriteFullAndDispose(), _targetSettings);

            sourceGameWorld.Players.Add("player1", new TestPlayer {
                Health = 100, Level = 30
            });
            sourceGameWorld.Players.Add("player2", new TestPlayer {
                Health = 44, Level = 1337
            });


            syncTargetRoot.Read(syncSourceRoot.WriteChangesAndDispose().SetTick(0));

            TestGameWorld targetGameWorld = syncTargetRoot.Root;

            AssertExtension.AssertCloneEqual(sourceGameWorld, targetGameWorld);
        }
Exemplo n.º 4
0
        public void SynchronizingString_ThatIsNotReferenceEqual_Test()
        {
            var sourceGameWorld = new NotifyPropertyChangedTestGameWorld {
                RandomIntProperty = 5
            };

            // Concatenating 1 to make sure the string is a new object
            sourceGameWorld.Players.Add("player1", new NotifyPropertyChangedTestPlayer {
                Name = "sameString" + 1, Health = 100, Level = 30
            });

            var SourceSynchronizerRoot = new SourceSynchronizerRoot(sourceGameWorld);

            var TargetSynchronizerRoot = new TargetSynchronizerRoot <NotifyPropertyChangedTestGameWorld>(SourceSynchronizerRoot.WriteFullAndDispose());

            sourceGameWorld.Players.Add("player2", new NotifyPropertyChangedTestPlayer {
                Name = "sameString" + 1, Health = 44, Level = 1337
            });
            SynchronizationPacket writeChangesAndDispose = SourceSynchronizerRoot.WriteChangesAndDispose();

            TargetSynchronizerRoot.Read(writeChangesAndDispose.SetTick(TimeSpan.Zero));

            NotifyPropertyChangedTestGameWorld targetGameWorld = TargetSynchronizerRoot.Reference;

            AssertExtension.AssertCloneEqual(sourceGameWorld, targetGameWorld);
        }
        public void SynchronizingFull_TargetObjectEqualsSource()
        {
            var sourceGameWorld = new NotifyPropertyChangedTestGameWorld {
                RandomIntProperty = 5
            };

            sourceGameWorld.Players.Add("player1", new NotifyPropertyChangedTestPlayer {
                Name = "player1", Health = 100, Level = 30
            });
            sourceGameWorld.Players.Add("player2", new NotifyPropertyChangedTestPlayer {
                Name = "player2", Health = 44, Level = 1337
            });

            var sourceSynchronizerRoot = new SourceSynchronizerRoot(sourceGameWorld);

            var targetSynchronizerRoot = new TargetSynchronizerRoot <NotifyPropertyChangedTestGameWorld>(sourceSynchronizerRoot.WriteFullAndDispose());
            NotifyPropertyChangedTestGameWorld targetGameWorld = targetSynchronizerRoot.Reference;

            AssertExtension.AssertCloneEqual(sourceGameWorld, targetGameWorld);
        }
        public void MoreThanEightSyncAttributesTest()
        {
            var sourceTestMock = new SynchronizeManySyncAttributesTest()
            {
                Test  = 0,
                Test2 = 2,
                Test3 = 34,
                Test4 = 43,
                Test5 = 122,
                Test6 = 99999999.32423,
                Test7 = 3434,
                Test8 = 23,
                Test9 = 2
            };

            var syncSourceRoot = new SyncSourceRoot(sourceTestMock, _sourceSettings);

            var target =
                new SyncTargetRoot <SynchronizeManySyncAttributesTest>(syncSourceRoot.WriteFullAndDispose(), _targetSettings);

            AssertExtension.AssertCloneEqual(sourceTestMock, target.Root);
        }