FTPTestCase.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 » FTPTestCase.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: FTPTestCase.cs,v $
// Revision 1.13  2008-06-20 00:22:18  bruceb
// CF changes
//
// Revision 1.12  2008-06-17 06:12:13  bruceb
// net cf changes
//
// Revision 1.11  2006/06/22 12:40:00  bruceb
// use casts as Login not in IFileTransfer
//
// Revision 1.10  2006/06/16 12:13:19  bruceb
// added serverWakeupInterval
//
// Revision 1.9  2006/05/03 04:41:02  bruceb
// FTPConnection tests
//
// Revision 1.8  2006/05/01 02:31:26  bruceb
// factor stuff out to AbstractTestCase
//
// Revision 1.7  2005/08/13 08:25:13  bruceb
// added new Print()
//
// Revision 1.6  2005/08/05 13:46:22  bruceb
// active mode port/ip address setting
//
// Revision 1.5  2005/08/04 21:55:46  bruceb
// changes for re-jigged test subdirs
//
// Revision 1.4  2005/06/03 11:39:57  bruceb
// vms changes
//
// Revision 1.3  2004/12/22 22:52:03  bruceb
// bulk test param
//
// Revision 1.2  2004/11/20 22:37:16  bruceb
// tweaked setup/teardown so its for each test
//
// Revision 1.1  2004/11/13 19:15:01  bruceb
// first cut of tests
//

using System;
using System.IO;
using System.Configuration;
using FTPClientEnterpriseDT.Net.Ftp.FTPClient;
using FTPConnectModeEnterpriseDT.Net.Ftp.FTPConnectMode;
using FTPControlSocketEnterpriseDT.Net.Ftp.FTPControlSocket;
using FileAppenderEnterpriseDT.Util.Debug.FileAppender;
using LevelEnterpriseDT.Util.Debug.Level;
using LoggerEnterpriseDT.Util.Debug.Logger;
using NUnit.Framework;


namespace EnterpriseDT.Net.Ftp.Test{    
    /// <summary>  
    /// Generic NUnit test superclass for FTP testing
    /// </summary>
    /// <remarks>This class provides some
    /// useful methods for subclasses that implement the actual
    /// test cases
    /// </remarks>
    /// <author>          
    /// Bruce Blackshaw
    /// </author>
    /// <version>         
    /// $Revision: 1.13 $
    /// </version>
    abstract public class FTPTestCase:AbstractTestCase
    {
        
        /// <summary> 
        /// Logs start of transfer
        /// </summary>
      internal void LogTransferStarted(object obj, TransferEventArgs args) 
      {
          log.Debug("TransferStarted[file=" + args.RemoteFilename + ",direction=" + 
                       args.Direction + ",type=" + args.TransferType + "]");
      }
        
        /// <summary> 
        /// Logs start of transfer
        /// </summary>
      internal void LogTransferComplete(object obj, TransferEventArgs args) 
      {
          log.Debug("TransferComplete[file=" + args.RemoteFilename + ",direction=" + 
                       args.Direction + ",type=" + args.TransferType + "]");
      }
        
    /// <summary> 
        /// Logs count of bytes transferred via event
        /// </summary>
      internal void BytesTransferred(object obj, BytesTransferredEventArgs args) 
      {
          log.Debug("Transferred: " + Convert.ToString(args.ByteCount));
      }
                
        /// <summary>  Reference to the FTP client</summary>
        internal IFileTransferClient ftp;
                
        /// <summary> Deallocate resources at close of fixture</summary>
        [TestFixtureTearDown]
        internal virtual void FixtureTearDown()
        {
            Logger.Shutdown();
            ftp = null;
        }

        
        /// <summary> Deallocate resources at close of each test</summary>
        [TearDown]
        internal virtual void TestTearDown()
        {
            ftp = null;
        }        
        
        /// <summary>  Connect to the server </summary>
        internal override void Connect(int timeout)
        {
            // connect
            ftp = new FTPClient();
            ftp.RemoteHost = host;
            ftp.ControlPort = FTPControlSocket.CONTROL_PORT;
            ftp.Timeout = timeout;
            log.Debug("Using timeout= " + timeout + " ms");
            ((FTPClient)ftp).ServerWakeupInterval = serverWakeupInterval;
            log.Debug("Using server wakeup interval= " + serverWakeupInterval + " sec");
            ((FTPClient)ftp).ConnectMode = connectMode;
            ftp.TransferStartedEx += new TransferHandler(LogTransferStarted);
            ftp.TransferCompleteEx += new TransferHandler(LogTransferComplete);
            ftp.BytesTransferred += new BytesTransferredHandler(BytesTransferred);
            if (!strictReplies)
            {
                log.Warn("Strict replies not enabled");
                ((FTPClient)ftp).StrictReturnCodes = false;
            }
            log.Debug("Connecting to " + host);
            ftp.Connect();
            log.Debug("Connected to " + host);
        }
        
        /// <summary>  Login to the server</summary>
        internal virtual void Login()
        {
            ((FTPClient)ftp).Login(user, password);
        }
               
        /// <summary>Transfer back and forth multiple times</summary>
        internal override void BulkTransfer(string localFile) 
        {
      // put to a random filename muliple times
            string filename = GenerateRandomFilename();
            log.Debug("Bulk transfer count=" + bulkCount);
            for (int i = 0; i < bulkCount; i++) 
            {
          ftp.Put(localDataDir + localFile, filename);
          
          // get it back        
          ftp.Get(localDataDir + filename, filename);
                        
            }
        // delete remote file
      ftp.Delete(filename);
      
      // check equality of local files
      AssertIdentical(localDataDir + localFile, localDataDir + filename);
      
      // and delete local file
      FileInfo local = new FileInfo(localDataDir + filename);
            local.Delete();
        }
        
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.