public void SecureSslConnectionWorks()
        {
            string           fileName     = "notexistingdummy.dat";
            IFtpFakeResponse fakeResponse = null;

            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponseMock.
                Setup(m => m.GetFakeServerResponseString(It.Is <string>(r => r == AuthorizationUrl))).
                Returns(".\r\n..\r\nunittest.dat\r\n");
                fakeResponse = fakeResponseMock.Object;
            }

            var credentials = GetCredentials();

            credentials.Secure = true;
            Assert.DoesNotThrowAsync(() => FileExistsWorksAsync(fileName, credentials, fakeResponse));
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FtpCloudStorageClient"/> class.
 /// </summary>
 /// <param name="fakeResponse">If this parameter is not null, the storage client is put
 /// into a test mode and no real calls to the Ftp server are made. Instead a Mock can
 /// define fake responses.</param>
 public FtpCloudStorageClient(IFtpFakeResponse fakeResponse)
 {
     _fakeResponse = fakeResponse;
 }
        public void FileLifecycleWorks()
        {
            string fileName = "unittest.dat";

            byte[] fileContent = new byte[16];
            new Random().NextBytes(fileContent);

            // 1) Test upload
            IFtpFakeResponse fakeResponse = null;

            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponse = fakeResponseMock.Object;
            }
            Assert.DoesNotThrowAsync(() => UploadFileWorksAsync(fileName, fileContent, fakeResponse));

            // 2) Test listing
            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponseMock.
                Setup(m => m.GetFakeServerResponseString(It.Is <string>(r => r == AuthorizationUrl))).
                Returns(".\r\n..\r\nXyz\r\nunittest.dat\r\nb.txt\r\nc.txt\r\n");
                fakeResponse = fakeResponseMock.Object;
            }
            List <string> res = Task.Run(async() => await ListFileNamesWorksAsync(GetCredentials(), fakeResponse)).Result;

            Assert.IsTrue(res.Count >= 1);
            Assert.IsTrue(res.Contains("unittest.dat"));

            // 3) Test exists
            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponseMock.
                Setup(m => m.GetFakeServerResponseString(It.Is <string>(r => r == AuthorizationUrl))).
                Returns(".\r\n..\r\nXyz\r\nunittest.dat\r\nb.txt\r\nc.txt\r\n");
                fakeResponse = fakeResponseMock.Object;
            }
            bool exists = Task.Run(async() => await FileExistsWorksAsync(fileName, GetCredentials(), fakeResponse)).Result;

            Assert.IsTrue(exists);

            // 4) Test download
            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponseMock
                .Setup(m => m.GetFakeServerResponseBytes(It.IsAny <string>()))
                .Returns(fileContent);
                fakeResponse = fakeResponseMock.Object;
            }
            Byte[] downloadedContent = Task.Run(async() => await DownloadFileWorksAsync(fileName, GetCredentials(), fakeResponse)).Result;
            Assert.AreEqual(fileContent, downloadedContent);

            // 5) Test delete
            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponse = fakeResponseMock.Object;
            }
            Assert.DoesNotThrowAsync(() => DeleteFileWorksAsync(fileName, GetCredentials(), fakeResponse));

            // 6) Was really deleted?
            if (!DoRealWebRequests)
            {
                Mock <IFtpFakeResponse> fakeResponseMock = new Mock <IFtpFakeResponse>();
                fakeResponseMock.
                Setup(m => m.GetFakeServerResponseString(It.Is <string>(r => r == AuthorizationUrl))).
                Returns(".\r\n..\r\nXyz\r\nb.txt\r\nc.txt\r\n");
                fakeResponse = fakeResponseMock.Object;
            }
            exists = Task.Run(async() => await FileExistsWorksAsync(fileName, GetCredentials(), fakeResponse)).Result;
            Assert.IsFalse(exists);
        }
 private async Task DeleteFileWorksAsync(string fileName, CloudStorageCredentials credentials, IFtpFakeResponse fakeResponse)
 {
     ICloudStorageClient client = new FtpCloudStorageClient(fakeResponse);
     await client.DeleteFileAsync(fileName, credentials);
 }
        private async Task <byte[]> DownloadFileWorksAsync(string fileName, CloudStorageCredentials credentials, IFtpFakeResponse fakeResponse)
        {
            ICloudStorageClient client = new FtpCloudStorageClient(fakeResponse);

            byte[] result = await client.DownloadFileAsync(fileName, credentials);

            return(result);
        }
        private async Task <bool> FileExistsWorksAsync(string fileName, CloudStorageCredentials credentials, IFtpFakeResponse fakeResponse)
        {
            ICloudStorageClient client = new FtpCloudStorageClient(fakeResponse);
            bool result = await client.ExistsFileAsync(fileName, credentials);

            return(result);
        }
        private async Task <List <string> > ListFileNamesWorksAsync(CloudStorageCredentials credentials, IFtpFakeResponse fakeResponse)
        {
            ICloudStorageClient client = new FtpCloudStorageClient(fakeResponse);
            List <string>       result = await client.ListFileNamesAsync(credentials);

            return(result);
        }
 private async Task UploadFileWorksAsync(string fileName, byte[] fileContent, IFtpFakeResponse fakeResponse)
 {
     ICloudStorageClient     client      = new FtpCloudStorageClient(fakeResponse);
     CloudStorageCredentials credentials = GetCredentials();
     await client.UploadFileAsync(fileName, fileContent, credentials);
 }