public void AttemptToDownloadBadDS()
        {
            // Seen in wild: try to download a bad dataset, and it creates a directory
            // anyway. Ops!

            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("AttemptToDownloadBadDS");
            if (d.Exists)
            {
                d.Delete(true);
            }

            var ld = new LinuxMirrorDownloaderPretend(d, "forkitover");
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");

            try {
                var r = gf.GetDS(dsinfo);
            } catch (ArgumentException)
            {
                // Expecting it to throw here - no dataset should exist by that name!
            }

            // Did a local directory get created?
            d.Refresh();
            Assert.IsFalse(d.Exists);
        }
        public void DownloadAllFilesSecondTime()
        {
            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("DownloadAllFilesSecondTime");
            if (d.Exists)
            {
                d.Delete(true);
            }

            var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo, fileFilter: flist => flist.OrderBy(f => f).Take(1).ToArray());
            Assert.AreEqual(1, r.Length);

            r = gf.GetDS(dsinfo);
            Assert.AreEqual(5, r.Length);

            Assert.AreEqual(5, d.EnumerateFiles("*.root.*", SearchOption.AllDirectories).Where(f => !f.FullName.EndsWith(".part")).Count());
        }
        public void MakeSureContentsFileIsUpdated()
        {
            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("MakeSureContentsFileIsUpdated");
            if (d.Exists)
            {
                d.Delete(true);
            }
            d.Create();
            var f = new FileInfo(Path.Combine(d.FullName, "contents.txt"));
            using (var wr = f.CreateText())
            {
                wr.WriteLine("otherdataset.data.set gwatts");
            }

            var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo);

            Assert.IsTrue(f.Exists);
            Assert.AreEqual("otherdataset.data.set gwatts", f.ReadLine(1));
            Assert.IsTrue(f.ReadLine(2).StartsWith(dsinfo.Name));
        }
        public void MakeSureContentsFileIsCreated()
        {
            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("MakeSureContentsFileIsCreated");
            if (d.Exists)
            {
                d.Delete(true);
            }

            var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo);

            var f = new FileInfo(Path.Combine(d.FullName, "contents.txt"));
            Assert.IsTrue(f.Exists);
            Assert.IsTrue(f.ReadLine().StartsWith(dsinfo.Name));
        }
        public void DownloadToLinuxDirectoryThatIsAWindowsDirectoryWithScoppedDS()
        {
            var dsinfo = MakeDSInfo("user.norm:ds1.1.1");
            var d = new DirectoryInfo("DownloadToLinuxDirectoryThatIsAWindowsDirectory");
            if (d.Exists)
            {
                d.Delete(true);
            }

            var ld = new LinuxMirrorDownloaderPretend(d, "ds1.1.1");
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo);
            Assert.IsNotNull(r);
            Assert.AreEqual(5, r.Length);
            Assert.AreEqual("/bogus/files/store/ds1.1.1", ld.LinuxDest);
        }
        public void DownloadToLinuxDirectoryThatIsAWindowsDirectoryAndAreadyCreated()
        {
            // Seen in the wild. A crash (or other interruption) means the dataset directory has
            // been created, but is empty (for whatever reason). In that particular case, we should
            // treat it as not there.

            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("DownloadToLinuxDirectoryThatIsAWindowsDirectory");
            if (d.Exists)
            {
                d.Delete(true);
            }
            d.Create();
            var dsdir = d.SubDir(dsinfo.Name);
            dsdir.Create();

            var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo);
            Assert.IsNotNull(r);
            Assert.AreEqual(5, r.Length);
            Assert.AreEqual("/bogus/files/store/ds1.1.1", ld.LinuxDest);
        }