public bool ConfigureFileManager(string path) { //get the filename string filename = path.Split(new char[] { '\\' }).Last(); string extension = path.Split(new char[] { '.' }).Last(); string name = filename.Replace("." + extension, ""); //get the foldername to populate the listbox string foldername = path.Replace(filename, ""); fm.setFolder(foldername); fm.setFileName(name); fm.setFileFilter(string.Empty); fm.setFileToken(string.Empty); fm.setFormat("." + extension); return(true); }
[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()); }