[TestMethod]
public void DeletesAFileFromTheFTPServer()
{
FTPAccess access = new FTPAccess();
string fn = "//Process1/220111.csv";
_ = access.DeleteFile(fn);
Assert.IsTrue(access.FileExists(fn) == false);
}
I once assigned the value "DeletMe.txt" to the fileName. I had an empty text file I used as the file to delete. It workded fine so I moved on. When I ran the program the DeleteFile method failed.
public bool DeleteFile(string fileName)
{
try
{
FtpWebRequest req = (FtpWebRequest)WebRequest.Create(new Uri(FTPServer + fileName));
req.Method = WebRequestMethods.Ftp.DeleteFile;
//req.Credentials = new NetworkCredential(usr, pwd);
using (FtpWebResponse response = (FtpWebResponse)req.GetResponse())
{
return true;
}
}
catch (WebException wx)
{
FtpWebResponse resp = (FtpWebResponse)wx.Response;
if (resp.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
{
return false;
}
}
return false;
}
It failed because the file was unavailable. The file was unavailable because the fileName was = "//Process1/DeleteMe.txt." But in the test you can clearly see that the variable passed is supposed to be "//Process1/220111.csv." But it seems I cannot assign a value to a string variable. So fn, or fileName, or fName (I have tried all three) is not defined when the DeletFile method is called. When the test gets to the DeleteFile method the variable fileName = "//Process1/DeleteMe.txt."
I have searched for DeleteMe.txt in the Entire Solution and it was not found. I searched for fileName and it was found exactly where it is being used and that's it.
I was going to include screen shots from Debugging here, but, apparently I can't.

New Topic/Question
Reply



MultiQuote






|