예제 #1
0
        /// <summary>
        /// Validate the Image DeSerialize  for different test cases.
        /// </summary>
        /// <param name="nodeName">Differrent node name for different test cases.</param>
        /// <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>
        /// <param name="format">Image format.</param>
        public void ValidateDeserializeImageFilesForDifferentLevel(string nodeName, string expectedFileName, int level, int tileXValue, int tileYValue, ImageFormat format)
        {
            // Get Values from XML File
            string filePath = utilityObj.XmlUtil.GetTextValue(nodeName, Constants.InputFilePath);

            var imageTileSerializer = new ImageTileSerializer(expectedFileName, ImageFormat.Png);

            using (Bitmap bitmap = new Bitmap(filePath))
            {
                // Serialize the file.
                imageTileSerializer.Serialize(bitmap, level, tileXValue, tileYValue);

                string path = Path.Combine(Environment.CurrentDirectory, imageTileSerializer.GetFileName(level, tileXValue, tileYValue));
                Assert.IsTrue(File.Exists(path));

                using (Bitmap newBitmap = imageTileSerializer.Deserialize(level, tileXValue, tileYValue) as Bitmap)
                {
                    Assert.IsNotNull(newBitmap);
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        for (int y = 0; y < bitmap.Height; y++)
                        {
                            Assert.AreEqual(bitmap.GetPixel(x, y), newBitmap.GetPixel(x, y));
                        }
                    }
                }

                // Delete the file.
                File.Delete(path);
            }
        }
        public void ValidImageDeserializeTest()
        {
            try
            {
                string imageFileNameTemplate = @"Pyramid\{0}\{1}\L{0}X{1}Y{2}.{3}";
                var imageTileSerializer = new ImageTileSerializer(Path.Combine(Environment.CurrentDirectory, imageFileNameTemplate), ImageFormat.Png);
                using (Bitmap bitmap = new Bitmap(Path.Combine(TestDataPath, @"Image.png")))
                {
                    // Serialize the file.
                    imageTileSerializer.Serialize(bitmap, 0, 0, 0);

                    // Assert that the file exists.
                    string path = Path.Combine(Environment.CurrentDirectory, imageTileSerializer.GetFileName(0, 0, 0));
                    Assert.IsTrue(File.Exists(path));

                    using (Bitmap newBitmap = imageTileSerializer.Deserialize(0, 0, 0) as Bitmap)
                    {
                        // Assert that the deserialized bitmap is not null.
                        Assert.IsNotNull(newBitmap);
                        for (int i = 0; i < bitmap.Width; i++)
                        {
                            for (int j = 0; j < bitmap.Height; j++)
                            {
                                Assert.AreEqual(bitmap.GetPixel(i, j), newBitmap.GetPixel(i, j));
                            }
                        }
                    }

                    // Delete the file.
                    File.Delete(path);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
예제 #3
0
        public void ValidImageDeserializeTest()
        {
            try
            {
                string imageFileNameTemplate = @"Pyramid\{0}\{1}\L{0}X{1}Y{2}.{3}";
                var    imageTileSerializer   = new ImageTileSerializer(Path.Combine(Environment.CurrentDirectory, imageFileNameTemplate), ImageFormat.Png);
                using (Bitmap bitmap = new Bitmap(Path.Combine(TestDataPath, @"Image.png")))
                {
                    // Serialize the file.
                    imageTileSerializer.Serialize(bitmap, 0, 0, 0);

                    // Assert that the file exists.
                    string path = Path.Combine(Environment.CurrentDirectory, imageTileSerializer.GetFileName(0, 0, 0));
                    Assert.IsTrue(File.Exists(path));

                    using (Bitmap newBitmap = imageTileSerializer.Deserialize(0, 0, 0) as Bitmap)
                    {
                        // Assert that the deserialized bitmap is not null.
                        Assert.IsNotNull(newBitmap);
                        for (int i = 0; i < bitmap.Width; i++)
                        {
                            for (int j = 0; j < bitmap.Height; j++)
                            {
                                Assert.AreEqual(bitmap.GetPixel(i, j), newBitmap.GetPixel(i, j));
                            }
                        }
                    }

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