Exemplo n.º 1
0
        public void ShouldFailWithDirectoryNotFoundExceptionWhenDestinationDirectoryDoesNotExistsBeforeBeginExecute()
        {
            String sourceFilePath = null;
            String destinationFilePath = null;
            ImageResizePlugin plugin;

            try
            {
                sourceFilePath = Path.GetTempFileName();
                destinationFilePath = Path.Combine(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()),
                                                   Path.GetRandomFileName());
                plugin = new ImageResizePlugin();
                plugin.ExecuteFailed +=
                    delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

                plugin.SourceFilePath = sourceFilePath;
                plugin.DestinationFilePath = destinationFilePath;

                plugin.BeginExecute();
            }
            finally
            {
                if (File.Exists(sourceFilePath))
                    File.Delete(sourceFilePath);
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
            }
        }
Exemplo n.º 2
0
        public void ShouldDeleteOverwrittenFileOnBeginComit()
        {
            String temporaryFilePath = null;
            ImageResizePlugin plugin;

            try
            {
                temporaryFilePath = Path.GetTempFileName();

                plugin = new ImageResizePlugin();
                plugin.CommitFailed +=
                    delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

                plugin.ShouldOwerwriteExistingFile = true;
                plugin.TemporaryFilePath = temporaryFilePath;

                plugin.BeginCommit();

                Assert.IsFalse(File.Exists(temporaryFilePath));
            }
            finally
            {
                if (File.Exists(temporaryFilePath))
                    File.Delete(temporaryFilePath);
            }
        }
Exemplo n.º 3
0
        public void ShouldFailWithFileAlreadyExistExceptionWhenDestinationFileAlreadyExistsBeforeBeginExecute()
        {
            String sourceFilePath = null;
            String destinationFilePath = null;
            ImageResizePlugin plugin;

            try
            {
                sourceFilePath = Path.GetTempFileName();
                destinationFilePath = Path.GetTempFileName();
                plugin = new ImageResizePlugin();
                plugin.ExecuteFailed +=
                    delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

                plugin.SourceFilePath = sourceFilePath;
                plugin.DestinationFilePath = destinationFilePath;

                plugin.BeginExecute();
            }
            finally
            {
                if (File.Exists(sourceFilePath))
                    File.Delete(sourceFilePath);
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
            }
        }
Exemplo n.º 4
0
        public void ShouldRestoreOverwrittenFileOnBeginRollback()
        {
            String destinationFilePath = null;
            String temporaryFilePath = null;
            ImageResizePlugin plugin;

            try
            {
                var fileContent = Guid.NewGuid().ToString();

                temporaryFilePath = FileOperations.GetNonExistentFilePath();
                File.WriteAllText(temporaryFilePath, fileContent);

                destinationFilePath = Path.GetTempFileName();
                plugin = new ImageResizePlugin();
                plugin.RollbackFailed +=
                    delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

                plugin.DestinationFilePath = destinationFilePath;
                plugin.ShouldOwerwriteExistingFile = true;
                plugin.TemporaryFilePath = temporaryFilePath;

                plugin.BeginRollback();

                Assert.That(File.Exists(destinationFilePath));
                Assert.AreEqual(fileContent, File.ReadAllText(destinationFilePath));
            }
            finally
            {
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
                if (File.Exists(temporaryFilePath))
                    File.Delete(temporaryFilePath);
            }
        }
Exemplo n.º 5
0
        public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenSourceFilePathNotSetBeforeBeginExecute()
        {
            var plugin = new ImageResizePlugin();
            plugin.ExecuteFailed +=
                delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

            plugin.DestinationFilePath = Path.GetRandomFileName();

            plugin.BeginExecute();
        }
Exemplo n.º 6
0
        public void ShouldResizeImage()
        {
            String sourceFilePath = null;
            String destinationFilePath = null;
            ImageResizePlugin plugin;

            try
            {
                sourceFilePath = CreateImage(500, 500);
                destinationFilePath = FileOperations.GetNonExistentFilePath("jpg");

                plugin = new ImageResizePlugin();
                plugin.ExecuteFailed +=
                    delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

                plugin.SourceFilePath = sourceFilePath;
                plugin.DestinationFilePath = destinationFilePath;
                plugin.Amount = 200;
                plugin.Type = ImageResizeType.WIDTH;
                plugin.Quality = 95;

                plugin.BeginExecute();

                using (var image = new Bitmap(destinationFilePath))
                {
                    Assert.AreEqual(200, image.Width);
                }
            }
            finally
            {
                if (File.Exists(sourceFilePath))
                    File.Delete(sourceFilePath);
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
            }
        }
Exemplo n.º 7
0
        public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenNoPropertiesSetBeforeBeginExecute()
        {
            var plugin = new ImageResizePlugin();
            plugin.ExecuteFailed +=
                delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

            plugin.BeginExecute();
        }
Exemplo n.º 8
0
        public void ShouldFailWithFileNotFoundExceptionWhenSourceFileDoesNotExistsBeforeBeginExecute()
        {
            String sourceFilePath;
            String destinationFilePath;

            var plugin = new ImageResizePlugin();
            plugin.ExecuteFailed +=
                delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

            sourceFilePath = FileOperations.GetNonExistentFilePath();
            destinationFilePath = FileOperations.GetNonExistentFilePath();

            plugin.SourceFilePath = sourceFilePath;
            plugin.DestinationFilePath = destinationFilePath;

            plugin.BeginExecute();
        }
Exemplo n.º 9
0
        public void ShouldFailWithFileNotFoundExceptionWhenOverwritedTemporaryFilePathDoesNotExistOnBeginRollback()
        {
            String destinationFilePath = null;
            String temporaryFilePath;
            ImageResizePlugin plugin;

            try
            {
                temporaryFilePath = FileOperations.GetNonExistentFilePath();

                destinationFilePath = Path.GetTempFileName();
                plugin = new ImageResizePlugin();
                plugin.RollbackFailed +=
                    delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

                plugin.DestinationFilePath = destinationFilePath;
                plugin.ShouldOwerwriteExistingFile = true;
                plugin.TemporaryFilePath = temporaryFilePath;

                plugin.BeginRollback();
            }
            finally
            {
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
            }
        }
Exemplo n.º 10
0
        public void ShouldFailWithFileNotFoundExceptionWhenOverwritedTemporaryFilePathDoesNotExistOnBeginComit()
        {
            var overwritedTemporaryFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var plugin = new ImageResizePlugin();

            plugin.ShouldOwerwriteExistingFile = true;
            plugin.TemporaryFilePath = overwritedTemporaryFilePath;

            plugin.CommitFailed +=
                delegate(object sender, PluginErrorEventArgs e) { throw e.Exception; };

            plugin.BeginCommit();
        }
Exemplo n.º 11
0
        public void ShouldResizeImage()
        {
            String sourceFilePath = null;
            String destinationFilePath = null;
            ImageResizePlugin plugin;

            try
            {
                sourceFilePath = CreateImage(500, 500);
                destinationFilePath = FileOperations.GetNonExistentFilePath("jpg");

                plugin = new ImageResizePlugin();
                plugin.ExecuteFailed +=
                    delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; };

                plugin.SourceFilePath = sourceFilePath;
                plugin.DestinationFilePath = destinationFilePath;
                plugin.Amount = 530;
                plugin.Type = ResizeType.width;
                plugin.Quality = 95;

                Console.WriteLine( XmlSerialize.ToXML( plugin ).OuterXml );

                plugin.BeginExecute();

                using (var image = new Bitmap(destinationFilePath))
                {
                    Assert.AreEqual(1000, image.Width);
                }
            }
            finally
            {
                if (File.Exists(sourceFilePath))
                    File.Delete(sourceFilePath);
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
            }
        }