예제 #1
0
        // save an image on the disc
        public Boolean save(Image img)
        {
            // get the path if exists
            String path = _filename.getFullPath();

            if (path == null)
            {
                return(false);
            }

            // choose the right format
            ImageFormat format = null;

            if (_filename.getFormat() == ".png")
            {
                format = ImageFormat.Png;
            }
            else
            {
                format = ImageFormat.Jpeg;
            }

            // save the image in the right place, at the right format
            try
            {
                System.Diagnostics.Trace.WriteLine(path);
                img.Save(path, format);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        [TestMethod] // control the file format's methods
        public void fileFormat()
        {
            Boolean result      = true;
            String  validFormat = ".jpeg";

            // try to set an invalid format
            result = _filenameManipulation.setFormat(".docx");
            Assert.AreEqual(false, result);
            Assert.AreEqual(".jpg", _filenameManipulation.getFormat());

            // set a valid format
            result = _filenameManipulation.setFormat(validFormat);
            Assert.AreEqual(true, result);
            Assert.AreEqual(validFormat, _filenameManipulation.getFormat());

            // set invalid format, previous format should stay
            result = _filenameManipulation.setFormat(".xlsx");
            Assert.AreEqual(false, result);
            Assert.AreEqual(validFormat, _filenameManipulation.getFormat());
        }
예제 #3
0
        public UnitTest_imageManipulation()
        {
            _path = System.IO.Directory.GetCurrentDirectory() + "\\..\\..\\images";

            // instanciation for successfull usage jpeg
            _goodFilename = Substitute.For <IFilenameManipulation>();
            _goodFilename.getFolder().Returns(_path);
            _goodFilename.getFullPath().Returns(_path + "\\new image - no filter.jpg");
            _goodFilename.getFormat().Returns(".jpg");

            // instanciation for successfull usage png
            _goodFilenamePng = Substitute.For <IFilenameManipulation>();
            _goodFilenamePng.getFolder().Returns(_path);
            _goodFilenamePng.getFullPath().Returns(_path + "\\new image - no filter.jpg");
            _goodFilenamePng.getFormat().Returns(".png");

            // instanciation for unsuccessful usage
            _badFilename = Substitute.For <IFilenameManipulation>();
            _badFilename.getFolder().Returns("unexisting path");
            _badFilename.getFullPath().Returns <Object>(null);

            // instanciation for existing image
            _existingFilename = Substitute.For <IFilenameManipulation>();
            _existingFilename.getFolder().Returns(_path);
            _existingFilename.getFullPath().Returns(_path + "\\a.jpg");

            // instanciation for existing but corrupted image
            _existingBadFilename = Substitute.For <IFilenameManipulation>();
            _existingBadFilename.getFolder().Returns(_path);
            _existingBadFilename.getFullPath().Returns(_path + "\\hi.txt");


            _imageGood        = new ImageManipulation(_goodFilename);
            _imageGoodPng     = new ImageManipulation(_goodFilenamePng);
            _imageBad         = new ImageManipulation(_badFilename);
            _imageExisting    = new ImageManipulation(_existingFilename);
            _imageBadExisting = new ImageManipulation(_existingBadFilename);
        }