コード例 #1
0
        public void DifferentRoot(bool shortNames)
        {
            var zipFilePath = IOSamples.GetTestPath("output/result.zip");

            var a = IOSamples.CreateFile("C:\\Temp\\T1\\a.txt");
            var b = Path.GetFullPath(IOSamples.CreateFile("output/temp/T1/b.txt")).Replace("\\", "/"); // D:
            var c = Path.GetFullPath(IOSamples.CreateFile("output/temp/T2/c.txt")).Replace("\\", "/"); // D:

            var sources = new[] { a, b, c };

            WorkflowTester.CompileAndRun(new Zip
            {
                ToCompress      = new InArgument <string[]>(_ => sources),
                ShortEntryNames = shortNames
            }, GetArgs(zipFilePath));

            File.Delete(a);

            using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Read))
            {
                if (shortNames)
                {
                    Assert.AreEqual("C\\a.txt", zip.Entries[0].FullName);
                    Assert.AreEqual("D\\T1\\b.txt", zip.Entries[1].FullName);
                    Assert.AreEqual("D\\T2\\c.txt", zip.Entries[2].FullName);
                }
                else
                {
                    Assert.AreEqual(Path.GetFullPath(a).Replace(":", ""), zip.Entries[0].FullName);
                    Assert.AreEqual(Path.GetFullPath(b).Replace(":", ""), zip.Entries[1].FullName);
                    Assert.AreEqual(Path.GetFullPath(c).Replace(":", ""), zip.Entries[2].FullName);
                }
            }
        }
コード例 #2
0
        public void Default()
        {
            var path   = IOSamples.CreateFile("output/sample.txt");
            var result = WorkflowTester.Run(new WaitFile(), GetArgs(path));
            var info   = result.Get(p => p.Result) as FileInfo;

            Assert.AreEqual("sample.txt", info.Name);
        }
コード例 #3
0
        public void LockedFile(int unlockAfterMs)
        {
            var path = IOSamples.CreateFile("output/sample.txt");
            var fs   = File.Open(path, FileMode.Append, FileAccess.Write);

            if (!IsLocked(path))
            {
                Assert.Fail("File is not locked");
            }

            Task.Delay(unlockAfterMs).ContinueWith(_ =>
            {
                fs.Dispose();

                if (IsLocked(path))
                {
                    Assert.Fail("File is not unlocked");
                }
            });

            WorkflowTester.Run(new WaitFile(), GetArgs(path));

            Assert.IsFalse(IsLocked(path));
        }
コード例 #4
0
        private static async Task <string> CreateFileAfter(int seconds, string extension = ".txt")
        {
            await Task.Delay(seconds * 1000).ConfigureAwait(false);

            return(IOSamples.CreateFile("output/" + Guid.NewGuid().ToString("n") + extension));
        }