Esempio n. 1
0
        /// <summary>
        /// Validate the DEM files name for different test cases.
        /// </summary>
        /// <param name="expectedFileName">Expected file name.</param>
        /// <param name="level">Levels in the folder structure.</param>
        /// <param name="tileXValue">Tile X value.</param>
        /// <param name="tileYValue">Tile Y value.</param>
        public void ValidateDeserializeDEMDifferentLevel(string expectedFileName, int level, int tileXValue, int tileYValue)
        {
            string destinationPath   = Path.Combine(Environment.CurrentDirectory, fileTemplate);
            var    demTileSerializer = new DemTileSerializer(destinationPath);

            short[] values = new short[1089];
            Random  random = new Random();

            for (int index = 0; index < 1089; index++)
            {
                values[index] = Convert.ToInt16(random.Next(100));
            }

            demTileSerializer.Serialize(values, level, tileXValue, tileYValue);

            // Validate the file structure created and the files
            string actualPath = demTileSerializer.GetFileName(level, tileXValue, tileYValue);

            Assert.AreEqual(actualPath, Path.Combine(Environment.CurrentDirectory, expectedFileName));
            Assert.IsTrue(File.Exists(actualPath));

            var newBytes = demTileSerializer.Deserialize(level, tileXValue, tileYValue);

            // Assert that the deserialized bitmap is not null and holds original values.
            Assert.IsNotNull(newBytes);
            for (int i = 0; i < values.Length; i++)
            {
                Assert.AreEqual(values[i], newBytes[i]);
            }

            // Delete the file.
            File.Delete(actualPath);
        }
Esempio n. 2
0
        public void ValidDemDeserializeTest()
        {
            try
            {
                string fileNameTemplate  = @"Pyramid\{0}\{1}\DL{0}X{1}Y{2}.dem";
                string destination       = Path.Combine(Environment.CurrentDirectory, fileNameTemplate);
                var    demTileSerializer = new DemTileSerializer(destination);

                // Serialize the file.
                short[] values = new short[1089];
                Random  random = new Random();
                for (int index = 0; index < 1089; index++)
                {
                    values[index] = Convert.ToInt16(random.Next(100));
                }

                int level = 3;
                int tileX = 2;
                int tileY = 1;
                demTileSerializer.Serialize(values, level, tileX, tileY);

                // Assert that the file exists.
                string path = Path.Combine(Environment.CurrentDirectory, demTileSerializer.GetFileName(level, tileX, tileY));
                Assert.AreEqual(path, Path.Combine(Environment.CurrentDirectory, @"Pyramid\3\2\DL3X2Y1.dem"));
                Assert.IsTrue(File.Exists(path));

                var newBytes = demTileSerializer.Deserialize(level, tileX, tileY);

                // Assert that the deserialized bitmap is not null and holds original values.
                Assert.IsNotNull(newBytes);
                for (int i = 0; i < values.Length; i++)
                {
                    Assert.AreEqual(values[i], newBytes[i]);
                }

                // Delete the file.
                File.Delete(path);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void ValidDemDeserializeTest()
        {
            try
            {
                string fileNameTemplate = @"Pyramid\{0}\{1}\DL{0}X{1}Y{2}.dem";
                string destination = Path.Combine(Environment.CurrentDirectory, fileNameTemplate);
                var demTileSerializer = new DemTileSerializer(destination);

                // Serialize the file.
                short[] values = new short[1089];
                Random random = new Random();
                for (int index = 0; index < 1089; index++)
                {
                    values[index] = Convert.ToInt16(random.Next(100));
                }

                int level = 3;
                int tileX = 2;
                int tileY = 1;
                demTileSerializer.Serialize(values, level, tileX, tileY);

                // Assert that the file exists.
                string path = Path.Combine(Environment.CurrentDirectory, demTileSerializer.GetFileName(level, tileX, tileY));
                Assert.AreEqual(path, Path.Combine(Environment.CurrentDirectory, @"Pyramid\3\2\DL3X2Y1.dem"));
                Assert.IsTrue(File.Exists(path));

                var newBytes = demTileSerializer.Deserialize(level, tileX, tileY);

                // Assert that the deserialized bitmap is not null and holds original values.
                Assert.IsNotNull(newBytes);
                for (int i = 0; i < values.Length; i++)
                {
                    Assert.AreEqual(values[i], newBytes[i]);
                }

                // Delete the file.
                File.Delete(path);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }