Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:54:10+00:00 2026-05-25T00:54:10+00:00

I code a FTP client Application, testing my functions by nunit tool. I try

  • 0

I code a FTP client Application, testing my functions by nunit tool. I try to mock FTP data stream. GetAllCsvFilesFromFTP method call FtpConnect() method, but while testing I want to get a Stream data without connecting FTP server.

    public List<string> GetAllCsvFilesFromFTP()
    {
        var files = new List<string>();
        var responseStream = _ftpConnection.FtpConnect(WebRequestMethods.Ftp.ListDirectory);
        if (responseStream != null)
        {
            var reader = new StreamReader(responseStream);
            ReadResponseStream(files, reader);
            reader.Close();
            responseStream.Close();
        }
        return files.OrderByDescending(p => p).ToList();
    }
    public Stream FtpConnect(string connectionType, string fileName = "")
    {
        try
        {
            var request = (FtpWebRequest)WebRequest.Create(_readConfigXml.FtpUrl + fileName);
            request.Credentials = new NetworkCredential(_readConfigXml.UserName, _readConfigXml.PassWord);
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = true;
            request.Method = connectionType;
            var response = (FtpWebResponse) request.GetResponse();
            var stream = response.GetResponseStream();
            return stream;
        }
        catch (Exception ex)
        {
            _logWriter.WriteLog(_readConfigXml.LogPath, ex.Message);
            return null;
        }
    }

I try to mock test’s Setup method in below:
_ftpConnection.Setup(m => m.FtpConnect(It.IsAny(), It.IsAny())).Returns(?);

Could you help me about how can i simulate Returns data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:54:11+00:00Added an answer on May 25, 2026 at 12:54 am
    string csvdata = "1,2,3,4,5":
    var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvdata));
    ms.Position = 0;
    _ftpConnection.Setup(m => m.FtpConnect(It.IsAny(), It.IsAny())).Returns(ms);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am developing a webbased ftp client application i want to get client
I am planning pin making an ftp client, however how in my code in
I need to write code that picks up PGP-encrypted files from an FTP location
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
I need to implement an FTP service inside my .NET application (running as a
I'm currently working on an FTP client written in C, and it's working pretty
I wrote small FTP Client Applet which uploads files to FTP Server using Commons
I'm looking for a web based FTP client, with a good PHP, javascript, html,
I want to create an FTP client in C# and Visual Studio 2010. Can
I am trying to create a ftp client with uploading a file capability. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.