public void Serialize_TestTableWithUnion_And_TestTable2_CanBeReadByOracle()
        {
            const string stringProp = "Hello, FlatBuffers!";

            var table2 = new TestTable2()
            {
                StringProp = stringProp
            };

            var obj = new TestTableWithUnion()
            {
                IntProp   = 512,
                UnionProp = table2
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnion(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual(typeof(TestTable2), oracleResult.UnionProp.GetType());

            var oracleResult2 = oracleResult.UnionProp as TestTable2;

            Assert.IsNotNull(oracleResult2);
            Assert.AreEqual(stringProp, oracleResult2.StringProp);
        }
        public void Serialize_TestTableWithNestedTestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var nested = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithNestedTestTable1()
            {
                IntProp = 2048,
                Nested  = nested
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithNestedTable1(buffer);

            Assert.AreEqual(2048, oracleResult.IntProp);

            var oracleResult1 = oracleResult.Nested as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }
        public void Serialize_TestTableWithUnion_And_TestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var table1 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithUnion()
            {
                IntProp   = 512,
                UnionProp = table1
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnion(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual(typeof(TestTable1), oracleResult.UnionProp.GetType());

            var oracleResult1 = oracleResult.UnionProp as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }
        public void Serialize_TestTable1_And_TestTableWithOriginalOrdering_EmitDifferentBuffers()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var obj = new TestTableWithOriginalOrdering()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var obj2 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var buffer2 = FlatBuffersConvert.SerializeObject(obj2);

            // Buffers will be different as they've been written in different orders
            Assert.IsFalse(buffer.SequenceEqual(buffer2));
        }
        public void Vec3_CanonicalBuffer_Matches_SerializedResult()
        {
            // Declare a Vec3 in .NET
            var vec3 = new Vec3()
            {
                X     = 1.0f,
                Y     = 2.0f,
                Z     = 3.0f,
                Test1 = 4.0,
                Test2 = Color.Green,
                Test3 = new Test()
                {
                    A = 5, B = 6
                }
            };

            // Create a buffer using the generated API
            var fbb        = new FlatBufferBuilder(32);
            var vec3Offset = MyGame.Example.Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 4.0, MyGame.Example.Color.Green, 5, 6);

            // Serialize Vec3 using FlatBuffers-net
            var buffer = FlatBuffersConvert.SerializeObject(vec3);

            // Verify buffers are identical
            Assert.IsTrue(buffer.SequenceEqual(fbb.DataBuffer.Data));
        }
        public void Serialize_TestTableWithIdentifier_CanBeReadByOracle()
        {
            const int intProp = 123456;

            var obj = new TestTableWithIdentifier()
            {
                IntProp = intProp,
            };

            var buffer       = FlatBuffersConvert.SerializeObject(obj);
            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithIdentifier(buffer);

            Assert.AreEqual(intProp, oracleResult.IntProp);
        }
        public void Serialize_TestTableWithUnionAndMoreFields_And_TestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var table1 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithUnionAndMoreFields()
            {
                IntProp    = 512,
                StringProp = "Hello, world!",
                FloatProp  = 3.125f,
                DoubleProp = 3.14,
                UnionProp  = table1
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnionAndMoreFields(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual("Hello, world!", oracleResult.StringProp);
            Assert.AreEqual(3.125f, oracleResult.FloatProp);
            Assert.AreEqual(3.14, oracleResult.DoubleProp);
            Assert.IsInstanceOf <TestTable1>(oracleResult.UnionProp);

            var oracleResult1 = oracleResult.UnionProp as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }