Example #1
0
        public void ShouldNotSerializePropertyGivenIndexer()
        {
            var expected = new HasIndexer();

            expected["anything"] = "value";

            TestCompiler.CompileAndLoadAssets(expected, result =>
            {
                Assert.AreNotEqual(expected["anything"], result["anything"]);
            });
        }
Example #2
0
        public void ShouldSerializePropertyGivenNameOfItem()
        {
            var expected = new HasNoIndexer {
                Item = "lorem-ipsum"
            };

            TestCompiler.CompileAndLoadAssets(expected, result =>
            {
                Assert.AreEqual(expected.Item, result.Item);
            });
        }
Example #3
0
        public void RoundTrip1DArrayStruct()
        {
            var expected = Enumerable.Range(0, 10).Select(i => new TestDataStruct {
                A = i * 42, B = "index: " + i
            }).ToArray();

            TestCompiler.CompileAndLoadAssets(expected.ToArray(), result =>
            {
                Assert.IsInstanceOf <TestDataStruct[]>(result);
                Assert.AreEqual(1, result.Rank);
                Assert.AreEqual(expected.Length, result.Length);
                CollectionAssert.AreEquivalent(expected, result);
            });
        }
Example #4
0
        public void RoundTripJaggedArrayClass()
        {
            var expected = Enumerable.Range(0, 5).Select(a => Enumerable.Range(0, 3).Select(b => new TestDataClass {
                A = a * 42 << b, B = "index: " + a * 5 + b
            }).ToArray()).ToArray();

            TestCompiler.CompileAndLoadAssets(expected.ToArray(), result =>
            {
                Assert.IsNotNull(result);
                Assert.IsInstanceOf <TestDataClass[][]>(result);
                Assert.AreEqual(1, result.Rank);
                Assert.AreEqual(expected.Length, result.Length);
                for (int i = 0; i < expected.Length; i++)
                {
                    CollectionAssert.AreEquivalent(expected[i], result[i]);
                }
            });
        }
Example #5
0
        public void RoundTrip3DArrayClass()
        {
            var expected = new TestDataClass[3, 4, 2];

            for (int z = 0; z < expected.GetLength(2); z++)
            {
                for (int y = 0; y < expected.GetLength(1); y++)
                {
                    for (int x = 0; x < expected.GetLength(0); x++)
                    {
                        expected[x, y, z] = new TestDataClass {
                            A = x + y * 10 + z * 100, B = string.Format("X: {0} Y: {1} Z: {2}", x, y, z)
                        }
                    }
                }
            }
            ;

            TestCompiler.CompileAndLoadAssets((TestDataClass[, , ])expected.Clone(), result =>
            {
                Assert.IsNotNull(result);
                Assert.IsInstanceOf <TestDataClass[, , ]>(result);
                Assert.AreEqual(result.Rank, 3);

                for (int i = 0; i < result.Rank; i++)
                {
                    Assert.AreEqual(expected.GetLength(i), result.GetLength(i));
                }

                for (int z = 0; z < expected.GetLength(2); z++)
                {
                    for (int y = 0; y < expected.GetLength(1); y++)
                    {
                        for (int x = 0; x < expected.GetLength(0); x++)
                        {
                            Assert.AreEqual(expected[x, y, z], result[x, y, z]);
                        }
                    }
                }
            });
        }
Example #6
0
        public void RoundTripArrayContainer()
        {
            var expected = new TestDataContainer
            {
                Array2D = new Microsoft.Xna.Framework.Rectangle[3, 2],
                Array3D = new Microsoft.Xna.Framework.Rectangle[3, 4, 2]
            };

            for (int y = 0; y < expected.Array2D.GetLength(1); y++)
            {
                for (int x = 0; x < expected.Array2D.GetLength(0); x++)
                {
                    expected.Array2D[x, y] = new Microsoft.Xna.Framework.Rectangle(x, y, -x, -y);
                }
            }

            for (int z = 0; z < expected.Array3D.GetLength(2); z++)
            {
                for (int y = 0; y < expected.Array3D.GetLength(1); y++)
                {
                    for (int x = 0; x < expected.Array3D.GetLength(0); x++)
                    {
                        expected.Array3D[x, y, z] = new Microsoft.Xna.Framework.Rectangle(x, y, z, -z);
                    }
                }
            }

            TestCompiler.CompileAndLoadAssets(expected.DeepClone(), result =>
            {
                Assert.IsNotNull(result.Array3D);
                Assert.IsInstanceOf <Microsoft.Xna.Framework.Rectangle[, , ]>(result.Array3D);
                Assert.AreEqual(result.Array3D.Rank, 3);

                for (int i = 0; i < result.Array3D.Rank; i++)
                {
                    Assert.AreEqual(expected.Array3D.GetLength(i), result.Array3D.GetLength(i));
                }

                for (int z = 0; z < expected.Array3D.GetLength(2); z++)
                {
                    for (int y = 0; y < expected.Array3D.GetLength(1); y++)
                    {
                        for (int x = 0; x < expected.Array3D.GetLength(0); x++)
                        {
                            Assert.AreEqual(expected.Array3D[x, y, z], result.Array3D[x, y, z]);
                        }
                    }
                }

                Assert.IsNotNull(result.Array2D);
                Assert.IsInstanceOf <Microsoft.Xna.Framework.Rectangle[, ]>(result.Array2D);
                Assert.AreEqual(result.Array2D.Rank, 2);

                for (int i = 0; i < result.Array2D.Rank; i++)
                {
                    Assert.AreEqual(expected.Array2D.GetLength(i), result.Array2D.GetLength(i));
                }

                for (int y = 0; y < expected.Array2D.GetLength(1); y++)
                {
                    for (int x = 0; x < expected.Array2D.GetLength(0); x++)
                    {
                        Assert.AreEqual(expected.Array2D[x, y], result.Array2D[x, y]);
                    }
                }
            });
        }