Ejemplo n.º 1
0
        public void TestRandomFile()
        {
            var tfc      = new TempFileCollection();
            var fileName = tfc.AddExtension("txt");

            var fileManager = new FileManager();
            var command     = new CreateRandomFileCommand(fileManager, fileName);

            var invoker = new Invoker();

            invoker.Execute(command);

            using (var reader = File.OpenText(fileName))
            {
                var content = reader.ReadToEnd();
                Assert.IsFalse(string.IsNullOrEmpty(content));
            }
        }
Ejemplo n.º 2
0
        public void TestInvokerThreads()
        {
            var tfc          = new TempFileCollection();
            var ftpFileName  = tfc.AddExtension("tmp1");
            var httpFileName = tfc.AddExtension("tmp2");
            var fileName     = tfc.AddExtension("txt");

            var fileManager     = new FileManager();
            var randFileCommand = new CreateRandomFileCommand(fileManager, fileName);

            var ftpClient   = new WebClient();
            var httpClient  = new WebClient();
            var ftpCommand  = new FtpGetFileCommand(ftpClient, FTP_URI, ftpFileName);
            var httpCommand = new HttpGetFileCommand(httpClient, HTTP_URI, httpFileName);

            var invoker = new Invoker(true);

            invoker.Execute(ftpCommand);
            invoker.Execute(randFileCommand);
            invoker.Execute(httpCommand);

            Thread.Sleep(1000);

            using (var reader = File.OpenText(ftpFileName))
            {
                var content = reader.ReadToEnd();
                Assert.IsFalse(string.IsNullOrEmpty(content));
            }
            using (var reader = File.OpenText(httpFileName))
            {
                var content = reader.ReadToEnd();
                Assert.IsFalse(string.IsNullOrEmpty(content));
            }
            using (var reader = File.OpenText(fileName))
            {
                var content = reader.ReadToEnd();
                Assert.IsFalse(string.IsNullOrEmpty(content));
            }
        }
Ejemplo n.º 3
0
        public void TestCopy()
        {
            var tfc          = new TempFileCollection();
            var srcFileName  = tfc.AddExtension("tmp1");
            var destFileName = tfc.AddExtension("tmp2");

            var fileManager   = new FileManager();
            var createCommand = new CreateRandomFileCommand(fileManager, srcFileName);
            var copyCommand   = new CopyFileCommand(fileManager, srcFileName, destFileName);

            var invoker = new Invoker();

            invoker.Execute(createCommand);
            invoker.Execute(copyCommand);

            using (StreamReader srcReader = File.OpenText(srcFileName),
                   destReader = File.OpenText(destFileName))
            {
                var srcContent  = srcReader.ReadToEnd();
                var destContent = destReader.ReadToEnd();
                Assert.AreEqual(srcContent, destContent);
            }
        }