Esempio n. 1
0
        public void with_a_writer_checksum_of_zero_and_no_files_is_valid()
        {
            var validator = new TransactionFileDatabaseValidator(
                new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(0), new List <ICheckpoint>()));

            Assert.DoesNotThrow(validator.Validate);
        }
Esempio n. 2
0
        public void with_a_writer_checksum_of_nonzero_and_no_files_a_corrupted_database_exception_is_thrown()
        {
            var validator =
                new TransactionFileDatabaseValidator(
                    new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(500), new List <ICheckpoint>()));

            Assert.Throws <CorruptDatabaseException>(validator.Validate);
        }
Esempio n. 3
0
        public void with_not_enough_files_to_reach_checksum_throws()
        {
            var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(15000), new List <ICheckpoint>());

            File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(0)), new byte[10000]);
            var validator = new TransactionFileDatabaseValidator(config);

            Assert.Throws <CorruptDatabaseException>(validator.Validate);
        }
Esempio n. 4
0
        public void allows_with_exactly_enough_file_to_reach_checksum()
        {
            var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(10000),
                                                           new List <ICheckpoint>());

            File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(0)), new byte[10000]);
            var validator = new TransactionFileDatabaseValidator(config);

            Assert.DoesNotThrow(validator.Validate);
        }
Esempio n. 5
0
        public void with_file_of_wrong_size_higher_than_checksum_the_file_is_deleted()
        {
            var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(500), new List <ICheckpoint>());

            File.WriteAllText(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(0)), "this is just some test blahbydy blah");
            var validator = new TransactionFileDatabaseValidator(config);
            var ex        = Assert.Throws <CorruptDatabaseException>(validator.Validate);

            Assert.IsInstanceOf <BadChunkInDatabaseException>(ex.InnerException);
        }
Esempio n. 6
0
        public void with_wrong_size_file_less_than_checksum_throws()
        {
            var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(15000), new List <ICheckpoint>());

            File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(0)), new byte[10000]);
            File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(1)), new byte[9000]);
            var validator = new TransactionFileDatabaseValidator(config);
            var ex        = Assert.Throws <CorruptDatabaseException>(validator.Validate);

            Assert.IsInstanceOf <BadChunkInDatabaseException>(ex.InnerException);
        }
Esempio n. 7
0
        public void when_in_brand_new_extraneous_files_throws_corrupt_database_exception()
        {
            var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(0),
                                                           new List <ICheckpoint>());

            File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(4)), new byte[10000]);
            var validator = new TransactionFileDatabaseValidator(config);
            var ex        = Assert.Throws <CorruptDatabaseException>(validator.Validate);

            Assert.IsInstanceOf <ExtraneousFileFoundException>(ex.InnerException);
        }
Esempio n. 8
0
        public void when_a_reader_checksum_is_ahead_of_writer_checksum_throws_corrupt_database_exception()
        {
            var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, new InMemoryCheckpoint(0),
                                                           new List <ICheckpoint> {
                new InMemoryCheckpoint(11)
            });

            File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(0)), new byte[10000]);
            var validator = new TransactionFileDatabaseValidator(config);
            var ex        = Assert.Throws <CorruptDatabaseException>(validator.Validate);

            Assert.IsInstanceOf <ReaderCheckpointHigherThanWriterException>(ex.InnerException);
        }