コード例 #1
0
        public void returns_all_existing_versions_of_the_same_chunk_in_descending_order_of_versions()
        {
            File.Create(GetFilePathFor("foo")).Close();
            File.Create(GetFilePathFor("bla")).Close();

            File.Create(GetFilePathFor("chunk-000001.000000")).Close();
            File.Create(GetFilePathFor("chunk-000002.000000")).Close();
            File.Create(GetFilePathFor("chunk-000003.000000")).Close();

            File.Create(GetFilePathFor("chunk-000005.000000")).Close();
            File.Create(GetFilePathFor("chunk-000005.000007")).Close();
            File.Create(GetFilePathFor("chunk-000005.000002")).Close();
            File.Create(GetFilePathFor("chunk-000005.000005")).Close();

            var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-");
            var versions = strategy.GetAllVersionsFor(5);
            Assert.AreEqual(4, versions.Length);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000007"), versions[0]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000005"), versions[1]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000002"), versions[2]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000000"), versions[3]);
        }
 public void when_getting_file_for_negative_version_throws_argumentoutofrangeexception()
 {
     var strategy = new VersionedPatternFileNamingStrategy("Path", "prefix");
     Assert.Throws<ArgumentOutOfRangeException>(() => strategy.GetFilenameFor(0, -1));
 }
 public void when_getting_file_for_nonnegative_index_and_version_appends_value_and_provided_version()
 {
     var strategy = new VersionedPatternFileNamingStrategy("path", "prefix-");
     Assert.AreEqual("path" + Path.DirectorySeparatorChar + "prefix-000001.000007", strategy.GetFilenameFor(1, 7));
 }
 public void when_getting_file_for_positive_index_and_no_version_appends_index_to_name_with_zero_version()
 {
     var strategy = new VersionedPatternFileNamingStrategy("path", "prefix-");
     Assert.AreEqual("path" + Path.DirectorySeparatorChar + "prefix-000001.000000", strategy.GetFilenameFor(1, 0));
 }
        public void returns_temp_filenames_detectable_by_getalltempfiles_method()
        {
            var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-");
            Assert.AreEqual(0, strategy.GetAllTempFiles().Length);

            var tmp1 = strategy.GetTempFilename();
            var tmp2 = strategy.GetTempFilename();
            File.Create(tmp1).Close();
            File.Create(tmp2).Close();
            var tmp = new[] { tmp1, tmp2 };
            Array.Sort(tmp);

            var tempFiles = strategy.GetAllTempFiles();
            Array.Sort(tempFiles);
            Assert.AreEqual(2, tempFiles.Length);
            Assert.AreEqual(tmp[0], tempFiles[0]);
            Assert.AreEqual(tmp[1], tempFiles[1]);
        }
        public void does_not_return_temp_file_that_is_named_as_chunk()
        {
            File.Create(GetFilePathFor("chunk-000000.000000.tmp")).Close();

            var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-");
            var tempFiles = strategy.GetAllVersionsFor(0);

            Assert.AreEqual(0, tempFiles.Length);
        }
        public void returns_all_temp_files_in_directory()
        {
            File.Create(GetFilePathFor("bla")).Close();
            File.Create(GetFilePathFor("bla.tmp")).Close();
            File.Create(GetFilePathFor("bla.temp")).Close();

            File.Create(GetFilePathFor("chunk-000005.000007.tmp")).Close();

            File.Create(GetFilePathFor("foo.tmp")).Close();

            var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-");
            var tempFiles = strategy.GetAllTempFiles();

            Assert.AreEqual(3, tempFiles.Length);
            Assert.AreEqual(GetFilePathFor("bla.tmp"), tempFiles[0]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000007.tmp"), tempFiles[1]);
            Assert.AreEqual(GetFilePathFor("foo.tmp"), tempFiles[2]);
        }
        public void returns_all_existing_not_temporary_files_with_correct_pattern()
        {
            File.Create(GetFilePathFor("foo")).Close();
            File.Create(GetFilePathFor("bla")).Close();
            File.Create(GetFilePathFor("chunk-000001.000000.tmp")).Close();
            File.Create(GetFilePathFor("chunk-001.000")).Close();

            File.Create(GetFilePathFor("chunk-000001.000000")).Close();
            File.Create(GetFilePathFor("chunk-000002.000000")).Close();
            File.Create(GetFilePathFor("chunk-000003.000000")).Close();

            File.Create(GetFilePathFor("chunk-000005.000000")).Close();
            File.Create(GetFilePathFor("chunk-000005.000007")).Close();
            File.Create(GetFilePathFor("chunk-000005.000002")).Close();
            File.Create(GetFilePathFor("chunk-000005.000005")).Close();

            var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-");
            var versions = strategy.GetAllPresentFiles();
            Array.Sort(versions, StringComparer.CurrentCultureIgnoreCase);
            Assert.AreEqual(7, versions.Length);
            Assert.AreEqual(GetFilePathFor("chunk-000001.000000"), versions[0]);
            Assert.AreEqual(GetFilePathFor("chunk-000002.000000"), versions[1]);
            Assert.AreEqual(GetFilePathFor("chunk-000003.000000"), versions[2]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000000"), versions[3]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000002"), versions[4]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000005"), versions[5]);
            Assert.AreEqual(GetFilePathFor("chunk-000005.000007"), versions[6]);
        }