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); 
 }
 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);
 }
 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);
 }
 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);
 }
 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);
 }
 public void when_in_multiple_extraneous_files_throws_corrupt_database_exception()
 {
     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[10000]);
     File.WriteAllBytes(Path.Combine(PathName, config.FileNamingStrategy.GetFilenameFor(2)), new byte[10000]);
     var validator = new TransactionFileDatabaseValidator(config); 
     var ex = Assert.Throws<CorruptDatabaseException>(validator.Validate);
     Assert.IsInstanceOf<ExtraneousFileFoundException>(ex.InnerException);
 }
 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);
 }
 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);
 }