[TestMethod] // control that the folder name's functions are correctly checked public void folderName() { Boolean result = true; // try to add an unexisting path result = _filenameManipulation.setFolder("Unexisting path"); Assert.AreEqual(false, result); Assert.AreEqual("", _filenameManipulation.getFolder()); // add an existing path result = _filenameManipulation.setFolder(_validFolder); Assert.AreEqual(true, result); Assert.AreEqual(_validFolder, _filenameManipulation.getFolder()); // change to a non-existing path. The previous path should have been kept result = _filenameManipulation.setFolder("unexisting folder"); Assert.AreEqual(false, result); Assert.AreEqual(_validFolder, _filenameManipulation.getFolder()); }
[TestMethod] // control the save and remove image methods (behaviour if existing) public void imageGoodPng() { Boolean result; String[] files; // take an image to save and delete Image img = Image.FromFile(_path + "\\a.jpg"); // save in good folder : return true and new image added result = _imageGoodPng.save(img); Assert.AreEqual(true, result); files = Directory.GetFiles(_goodFilenamePng.getFolder()); Assert.AreEqual(5, files.Length); // 5, because originally there are 3 pictures + 1 text file // remove an existing image : return true and old image deleted result = _imageGoodPng.remove(); Assert.AreEqual(true, result); files = Directory.GetFiles(_goodFilenamePng.getFolder()); Assert.AreEqual(4, files.Length); }
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); }
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); }