예제 #1
0
        public void SynchronisedClassCanChangeAuthority()
        {
            this.AssertNoActiveConnections();

            var network = this.SetupNetwork();

            try
            {
                // Create object and synchronise it on node A.
                var testA = new SynchronisedTest();
                testA.X = 3;
                testA.Y = 4;
                testA.Z = 5;
                network.NodeA.Synchronise(testA, "test", true);
                Assert.Equal(3, testA.X);
                Assert.Equal(4, testA.Y);
                Assert.Equal(5, testA.Z);

                // Create object and synchronise it on node B.
                var testB = new SynchronisedTest();
                Assert.Equal(0, testB.X);
                Assert.Equal(0, testB.Y);
                Assert.Equal(0, testB.Z);
                network.NodeB.Synchronise(testB, "test", false);
                Assert.Equal(3, testB.X);
                Assert.Equal(4, testB.Y);
                Assert.Equal(5, testB.Z);

                // Now set the values on B.
                testB.X = 6;
                testB.Y = 7;
                testB.Z = 8;
                Assert.Equal(3, testA.X);
                Assert.Equal(4, testA.Y);
                Assert.Equal(5, testA.Z);

                // Synchronise B authoritively.
                network.NodeB.Synchronise(testB, "test", true);
                Assert.Equal(3, testA.X);
                Assert.Equal(4, testA.Y);
                Assert.Equal(5, testA.Z);

                // Synchronise A non-authoritively.
                network.NodeA.Synchronise(testA, "test", false);
                Assert.Equal(6, testA.X);
                Assert.Equal(7, testA.Y);
                Assert.Equal(8, testA.Z);
            }
            finally
            {
                network.NodeA.Close();
                network.NodeB.Close();
            }

            this.AssertNoActiveConnections();
        }
예제 #2
0
        public void SynchronisedClassDoesNotUpdateUntilSynchronised()
        {
            this.AssertNoActiveConnections();

            var network = this.SetupNetwork();

            try
            {
                // Create object and synchronise it on node A.
                var testA = new SynchronisedTest();
                testA.X = 3;
                testA.Y = 4;
                testA.Z = 5;
                network.NodeA.Synchronise(testA, "test", true);
                Assert.Equal(3, testA.X);
                Assert.Equal(4, testA.Y);
                Assert.Equal(5, testA.Z);

                // Create object and synchronise it on node B.
                var testB = new SynchronisedTest();
                Assert.Equal(0, testB.X);
                Assert.Equal(0, testB.Y);
                Assert.Equal(0, testB.Z);
                network.NodeB.Synchronise(testB, "test", false);

                // Now update A, we should not see the changes reflected in B yet.
                testA.X = 6;
                testA.Y = 7;
                testA.Z = 8;
                Assert.Equal(3, testB.X);
                Assert.Equal(4, testB.Y);
                Assert.Equal(5, testB.Z);

                // Now synchronise A, we should still not see the changes reflected in B yet.
                network.NodeA.Synchronise(testA, "test", true);
                Assert.Equal(3, testB.X);
                Assert.Equal(4, testB.Y);
                Assert.Equal(5, testB.Z);

                // Now synchronise B and we should see the changes.
                network.NodeB.Synchronise(testB, "test", false);
                Assert.Equal(6, testB.X);
                Assert.Equal(7, testB.Y);
                Assert.Equal(8, testB.Z);
            }
            finally
            {
                network.NodeA.Close();
                network.NodeB.Close();
            }

            this.AssertNoActiveConnections();
        }
예제 #3
0
        public void SynchronisedClassBehavesCorrectly()
        {
            this.AssertNoActiveConnections();

            var network = this.SetupNetwork();

            try
            {
                // Create object and synchronise it on node A.
                var testA = new SynchronisedTest();
                testA.X = 3;
                testA.Y = 4;
                testA.Z = 5;
                network.NodeA.Synchronise(testA, "test", true);
                Assert.Equal(3, testA.X);
                Assert.Equal(4, testA.Y);
                Assert.Equal(5, testA.Z);

                // Create object and synchronise it on node B.
                var testB = new SynchronisedTest();
                Assert.Equal(0, testB.X);
                Assert.Equal(0, testB.Y);
                Assert.Equal(0, testB.Z);
                network.NodeB.Synchronise(testB, "test", false);
                Assert.Equal(3, testB.X);
                Assert.Equal(4, testB.Y);
                Assert.Equal(5, testB.Z);
            }
            finally
            {
                network.NodeA.Close();
                network.NodeB.Close();
            }

            this.AssertNoActiveConnections();
        }