FTPConnTestFileOperations.cs :  » Network-Clients » edtFTPnet » EnterpriseDT » Net » Ftp » Test » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » edtFTPnet 
edtFTPnet » EnterpriseDT » Net » Ftp » Test » FTPConnTestFileOperations.cs
// edtFTPnet
// 
// Copyright (C) 2004 Enterprise Distributed Technologies Ltd
// 
// www.enterprisedt.com
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Bug fixes, suggestions and comments should posted on 
// http://www.enterprisedt.com/forums/index.php
// 
// Change Log:
// 
// $Log: FTPConnTestFileOperations.cs,v $
// Revision 1.5  2008-06-17 06:13:50  bruceb
// net cf changes
//
// Revision 1.4  2008-04-30 07:35:35  hans
// Fixed faulty SetModTime test.
//
// Revision 1.3  2008-04-15 00:38:06  hans
// Added test for SetModTime
//
// Revision 1.2  2006/07/13 16:08:56  bruceb
// replace FTPException with FileTransferException
//
// Revision 1.1  2006/05/03 04:41:01  bruceb
// FTPConnection tests
//
//
//

using System;
using System.IO;
using FTPExceptionEnterpriseDT.Net.Ftp.FTPException;
using FTPTransferTypeEnterpriseDT.Net.Ftp.FTPTransferType;
using NUnit.Framework;

namespace EnterpriseDT.Net.Ftp.Test{  
  /// <summary>  Tests various file operations
  /// 
  /// </summary>
  /// <author>          Bruce Blackshaw
  /// </author>
  /// <version>         $Revision: 1.5 $
  /// </version>
  [TestFixture]
    [Category("edtFTPnet")]
  public class FTPConnTestFileOperations:FTPConnTestCase
  {
    /// <summary>  
    /// Get name of log file
    /// </summary>
    /// <returns> name of file to log to
    /// </returns>
    override internal string LogName
    {
      get
      {
        return "FTPConnTestFileOperations.log";
      }      
    }
        
    /// <summary>  Test remote deletion</summary>
    [Test]
    public virtual void Delete()
    {
      // test existent & non-existent file
      Connect();
      
      // move to test directory
      ftp.ChangeWorkingDirectory(testdir);
      
      try
      {
        // try to delete a non-existent file
        string file = GenerateRandomFilename();
        log.Debug("Deleting a non-existent file");
        ftp.DeleteFile(file);
      }
      catch (FileTransferException ex)
      {
        log.Debug("Expected exception: " + ex.Message);
      }
      
      // how to delete a file and make it repeatable?
      ftp.Close();
    }
    
    /// <summary>  Test renaming of a file</summary>
    [Test]
    public virtual void Rename()
    {
      // test existent & non-existent file
      Connect();
      
      // move to test directory
      ftp.ChangeWorkingDirectory(testdir);
      
      // rename file
            string ext = GenerateRandomFilename();
            string rename = remoteTextFile + "." + ext.Substring(0, 5);
      ftp.RenameFile(remoteTextFile, rename);
      
      // get its mod time
      DateTime modTime = ftp.GetLastWriteTime(rename);
      log.Debug(rename + ": " + modTime.ToString());
      
      // modtime on original file should fail
      try
      {
                ftp.GetLastWriteTime(remoteTextFile);
      }
      catch (FileTransferException ex)
      {
        log.Debug("Expected exception: " + ex.Message);
      }
      
      // and rename file back again
      ftp.RenameFile(rename, remoteTextFile);
      
      // and modtime should succeed 
      modTime = ftp.GetLastWriteTime(remoteTextFile);
      log.Debug(remoteTextFile + ": " + modTime.ToString());
      
      // GetLastWriteTime on renamed (first time) file should 
      // now fail (as we've just renamed it to original)
      try
      {
        ftp.GetLastWriteTime(rename);
      }
      catch (FileTransferException ex)
      {
        log.Debug("Expected exception: " + ex.Message);
      }
      
      ftp.Close();
    }
    
    
    /// <summary>  
        /// Test finding the modification time 
    /// of a file
    /// </summary>
    [Test]
    public virtual void Modtime()
    {      
      Connect();
      
      // move to test directory
      ftp.ChangeWorkingDirectory(testdir);
      
      // get modtime
      log.Debug("GetLastWriteTime on existing file: " + remoteTextFile);
      DateTime modTime = ftp.GetLastWriteTime(remoteTextFile);
      log.Debug(remoteTextFile + ": " + modTime.ToString());
      
      try
      {
        // get modtime on non-existent file
        string file = GenerateRandomFilename();
        log.Debug("GetLastWriteTime on non-existent file");
        modTime = ftp.GetLastWriteTime(file);
        log.Debug(remoteTextFile + ": " + modTime.ToString());
      }
      catch (FileTransferException ex)
      {
        log.Debug("Expected exception: " + ex.Message);
      }
      
      ftp.Close();
    }

        /// <summary>Test setting the modification time of a file</summary>
        [Test]
        public virtual void SetModtime()
        {
            log.Debug("SetModtime() test");

            Connect();

            // move to test directory
            ftp.ChangeWorkingDirectory(testdir);

            // get modtime
            log.Info("GetLastWriteTime on existing file: " + remoteTextFile);
            DateTime modTime = ftp.GetLastWriteTime(remoteTextFile);
            log.Info(remoteTextFile + ": " + modTime.ToString());

            // set modtime
            DateTime desiredModTime = modTime + new TimeSpan(1, 2, 3, 4);
            log.Debug("Setting mod-time to " + desiredModTime.ToString());
            ftp.SetLastWriteTime(remoteTextFile, desiredModTime);
            DateTime actualModTime = ftp.GetLastWriteTime(remoteTextFile);
            log.Debug(remoteTextFile + ": " + actualModTime.ToString());
            if (Math.Abs((actualModTime - desiredModTime).TotalMinutes) != 0)
            {
                string msg = "Desired mod-time(" + desiredModTime + ") != actual mod-time(" + actualModTime + ")";
                log.Error(msg);
                throw new System.Exception(msg);
            }

            ftp.Close();
        }

    /// <summary>Test the Size() method</summary>
    [Test]
    public virtual void Size()
    {      
      Connect();
      
      // move to test directory
      ftp.ChangeWorkingDirectory(testdir);
      ftp.TransferType = FTPTransferType.BINARY;
      
      // put to a random filename
      string filename = GenerateRandomFilename();
      ftp.UploadFile(localDataDir + localTextFile, filename);
      
      // find size of local file
      FileInfo local = new FileInfo(localDataDir + localTextFile);
      long sizeLocal = local.Length;
      
      // find size of remote
      long sizeRemote = ftp.GetSize(filename);
      
      // delete remote file
      ftp.DeleteFile(filename);
      
      if (sizeLocal != sizeRemote)
      {
        string msg = "Local size(" + sizeLocal + ") != remote size(" + sizeRemote + ")";
        log.Debug(msg);
        throw new System.Exception(msg);
      }
      
      ftp.Close();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.