public void OnDeserializeSafelyShouldDetectAndHandleDeSerializationMismatch()
        {
            // add components
            SerializeTest1NetworkBehaviour comp1 = gameObject.AddComponent <SerializeTest1NetworkBehaviour>();

            gameObject.AddComponent <SerializeMismatchNetworkBehaviour>();
            SerializeTest2NetworkBehaviour comp2 = gameObject.AddComponent <SerializeTest2NetworkBehaviour>();

            // set some unique values to serialize
            comp1.value = 12345;
            comp2.value = "67890";

            // serialize
            var ownerWriter     = new NetworkWriter();
            var observersWriter = new NetworkWriter();

            identity.OnSerializeAllSafely(true, ownerWriter, observersWriter);

            // reset component values
            comp1.value = 0;
            comp2.value = null;

            // deserialize all
            var reader = new NetworkReader(ownerWriter.ToArray());

            Assert.Throws <InvalidMessageException>(() =>
            {
                identity.OnDeserializeAllSafely(reader, true);
            });
        }
        public void OnSerializeAllSafely()
        {
            // create a networkidentity with our test components
            SerializeTest1NetworkBehaviour     comp1   = gameObject.AddComponent <SerializeTest1NetworkBehaviour>();
            SerializeExceptionNetworkBehaviour compExc = gameObject.AddComponent <SerializeExceptionNetworkBehaviour>();
            SerializeTest2NetworkBehaviour     comp2   = gameObject.AddComponent <SerializeTest2NetworkBehaviour>();

            // set some unique values to serialize
            comp1.value      = 12345;
            comp1.syncMode   = SyncMode.Observers;
            compExc.syncMode = SyncMode.Observers;
            comp2.value      = "67890";
            comp2.syncMode   = SyncMode.Owner;

            // serialize all
            var ownerWriter     = new NetworkWriter();
            var observersWriter = new NetworkWriter();

            // serialize should propagate exceptions
            Assert.Throws <Exception>(() =>
            {
                identity.OnSerializeAllSafely(true, ownerWriter, observersWriter);
            });
        }