public void CreateFor(string expected) { _setting.TimeStampFormat = BackupSettings.DefaultTimeStampFormat; var backup = BackupFile.CreateFor(_file, _setting); StringAssert.IsMatch(expected, backup.FullName); }
public void RenameGeneric(bool hasBackup, bool hasSoft) { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); file.CreateFileOnDisk(); if (hasBackup && repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk(); } if (hasSoft) { file.SoftDeleteFile().CreateFileOnDisk(); } repository.Rename <DummySerializable>("NewName", false); AssertFile.Exists(false, file); AssertFile.Exists(true, file.WithNewName("NewName", repository.Settings)); if (hasBackup && repository.Settings.BackupSettings != null) { AssertFile.Exists(false, BackupFile.CreateFor(file, repository.Settings.BackupSettings)); AssertFile.Exists(true, BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings)); } if (hasSoft) { AssertFile.Exists(false, file.SoftDeleteFile()); AssertFile.Exists(true, file.WithNewName("NewName", repository.Settings).SoftDeleteFile()); } }
public void DeleteFileName(bool deleteBackups) { if (this.CreateRepository() is IDataRepository dataRepository) { var file = CreateTestFile(dataRepository.Settings); var softDelete = file.SoftDeleteFile(); file.CreateFileOnDisk(); softDelete.CreateFileOnDisk(); if (dataRepository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, dataRepository.Settings.BackupSettings).CreateFileOnDisk(); } AssertFile.Exists(true, file); AssertFile.Exists(true, softDelete); dataRepository.Delete(file.Name, deleteBackups); AssertFile.Exists(false, file); AssertFile.Exists(false, softDelete); if (dataRepository.Settings.BackupSettings != null) { AssertFile.Exists(!deleteBackups, BackupFile.CreateFor(file, dataRepository.Settings.BackupSettings)); } } }
public void CreateFor(string expected) { this.File.CreatePlaceHolder(); var backupSettings = new BackupSettings(this.Directory.FullName, BackupSettings.DefaultExtension, BackupSettings.DefaultTimeStampFormat, 1, 1); var backup = BackupFile.CreateFor(this.File, backupSettings); StringAssert.IsMatch(expected, backup.FullName); }
public void CreateForNoTimestamp(string expected) { this.File.CreatePlaceHolder(); var setting = new BackupSettings(this.File.DirectoryName, BackupSettings.DefaultExtension, null, 1, int.MaxValue); var backup = BackupFile.CreateFor(this.File, setting); Assert.AreEqual(expected, backup.FullName); }
public void CreateForNoTimestamp(string expected) { File.VoidCreate(); var setting = new BackupSettings(File.Directory, true, BackupSettings.DefaultExtension, null, false, 1, Int32.MaxValue); var backup = BackupFile.CreateFor(File, setting); Assert.AreEqual(expected, backup.FullName); }
public void CreateForNoTimestamp(string fileName, string expected) { var file = new FileInfo(fileName); var setting = new BackupSettings(true, file.Directory, ".bak", null, false, 1, Int32.MaxValue); var backup = BackupFile.CreateFor(file, setting); Assert.AreEqual(expected, backup.FullName); }
public static void CreateFor() { var file = CreateFile(); file.CreateFileOnDisk(); var backupSettings = new BackupSettings(Directory.FullName, BackupSettings.DefaultExtension, BackupSettings.DefaultTimeStampFormat, 1, 1); var backup = BackupFile.CreateFor(file, backupSettings); StringAssert.IsMatch(@"BackupFileTests\\CreateFor\.\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d\.bak", backup.FullName); }
public static void CreateForNoTimestamp() { var file = CreateFile(); file.CreateFileOnDisk(); var setting = new BackupSettings(file.DirectoryName, BackupSettings.DefaultExtension, null, 1, int.MaxValue); var backup = BackupFile.CreateFor(file, setting); StringAssert.IsMatch(@"BackupFileTests\\CreateForNoTimestamp\.bak", backup.FullName); }
public void CanRenameGeneric() { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); file.CreateFileOnDisk(); if (repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk(); } Assert.AreEqual(true, repository.CanRename <DummySerializable>("NewName")); }
public void CanRenameFullFileName() { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings); file.CreateFileOnDisk(); if (repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk(); } Assert.AreEqual(true, repository.CanRename(file.FullName, "NewName")); }
public void CanRenameGenericWhenIllegalName() { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); file.CreateFileOnDisk(); if (repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk(); } var exception = Assert.Throws <ArgumentException>(() => repository.CanRename <DummySerializable>("NewName<>")); Assert.AreEqual("Illegal characters in path.", exception !.Message); }
public void RenameGenericOverwrite(bool overWrite) { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); var softDelete = file.SoftDeleteFile(); file.CreateFileOnDisk("file"); softDelete.CreateFileOnDisk("file soft delete"); file.WithNewName("NewName", repository.Settings).CreateFileOnDisk("existing new name"); file.WithNewName("NewName", repository.Settings).SoftDeleteFile().CreateFileOnDisk("existing soft delete new name"); if (repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk("backup"); BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).CreateFileOnDisk("existing backup new name"); } if (overWrite) { repository.Rename <DummySerializable>("NewName", true); AssertFile.Exists(false, file); AssertFile.Exists(false, softDelete); Assert.AreEqual("file", file.WithNewName("NewName", repository.Settings).ReadAllText()); Assert.AreEqual("file soft delete", file.WithNewName("NewName", repository.Settings).SoftDeleteFile().ReadAllText()); if (repository.Settings.BackupSettings != null) { AssertFile.Exists(false, BackupFile.CreateFor(file, repository.Settings.BackupSettings)); Assert.AreEqual("backup", BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).ReadAllText()); } } else { _ = Assert.Throws <InvalidOperationException>(() => repository.Rename <DummySerializable>("NewName", false)); Assert.AreEqual("file", file.ReadAllText()); Assert.AreEqual("file soft delete", softDelete.ReadAllText()); Assert.AreEqual("existing new name", file.WithNewName("NewName", repository.Settings).ReadAllText()); Assert.AreEqual("existing soft delete new name", file.WithNewName("NewName", repository.Settings).SoftDeleteFile().ReadAllText()); if (repository.Settings.BackupSettings != null) { Assert.AreEqual("backup", BackupFile.CreateFor(file, repository.Settings.BackupSettings).ReadAllText()); Assert.AreEqual("existing backup new name", BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).ReadAllText()); } } }
public void CanRenameGenericWouldOverwrite(bool fileNewNameExists, bool backupNewNameExists) { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); file.CreateFileOnDisk(); if (fileNewNameExists) { file.WithNewName("NewName", repository.Settings).CreateFileOnDisk(); Assert.AreEqual(false, repository.CanRename <DummySerializable>("NewName")); } if (backupNewNameExists && repository.Settings.BackupSettings != null) { var backup = BackupFile.CreateFor(file, repository.Settings.BackupSettings); backup.CreateFileOnDisk(); BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).CreateFileOnDisk(); Assert.AreEqual(false, repository.CanRename <DummySerializable>("NewName")); } }
public Files(string name, RepositorySettings settings) { var fileName = string.Concat(name, settings.Extension); var settingsDirectory = new DirectoryInfo(settings.Directory); this.File = settingsDirectory.CreateFileInfoInDirectory(fileName); var tempfileName = string.Concat(name, settings.TempExtension); this.Temp = settingsDirectory.CreateFileInfoInDirectory(tempfileName); this.SoftDelete = this.File.GetSoftDeleteFileFor(); this.WithNewName = this.File.WithNewName(NewName, settings); this.SoftDeleteNewName = this.SoftDelete.WithNewName(NewName, settings); var backupSettings = settings.BackupSettings; if (backupSettings != null) { this.Backup = BackupFile.CreateFor(this.File, backupSettings); this.BackupSoftDelete = this.Backup.GetSoftDeleteFileFor(); this.BackupNewName = BackupFile.CreateFor(this.WithNewName, backupSettings); } }