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);
        }
Exemple #2
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);
        }