Beispiel #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] // test the full path method
        public void fullPath()
        {
            String result;

            // no folder set
            result = _filenameManipulation.getFullPath();
            Assert.AreEqual(null, result);

            // existing folder set
            _filenameManipulation.setFolder(_validFolder);
            result = _filenameManipulation.getFullPath();
            Assert.AreEqual(_validFolder + "\\new file - no filter.jpg", result);
        }
        public UnitTest_ControlsManipulator()
        {
            _path = System.IO.Directory.GetCurrentDirectory() + "\\..\\..\\images";

            _imageGood = Substitute.For <IimageManipulation>();
            _imageGood.save(Arg.Any <Image>()).Returns(true);
            _imageGood.remove().Returns(true);

            _controlSubs = Substitute.For <IControlsManipulation>();
            _controlSubs.ApplyFilter(Arg.Any <string>(), Arg.Any <PictureBox>(), Arg.Any <TextBox>(), Arg.Any <Image>()).Returns(true);

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

            _imageExisting = new ImageManipulation(_existingFilename);
        }
Beispiel #4
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);
        }