private void ChangeNameAndCheck(TemporaryFolder newFolder, BookStorage storage) { var newBookName = Path.GetFileName(newFolder.Path); storage.SetBookName(newBookName); var newPath = newFolder.Combine(newBookName + ".htm"); Assert.IsTrue(Directory.Exists(newFolder.Path), "Expected folder:" + newFolder.Path); Assert.IsTrue(File.Exists(newPath), "Expected file:" + newPath); }
public void SetBookName_FolderWithNameAlreadyExists_AddsANumberToName() { using (var original = new TemporaryFolder(_folder, "original")) using (var x = new TemporaryFolder(_folder, "foo")) using (var y = new TemporaryFolder(_folder, "foo1")) using (var z = new TemporaryFolder(_folder, "foo2")) { File.WriteAllText(Path.Combine(original.Path, "original.htm"), "<html><head> href='file://blahblah\\editMode.css' type='text/css' /></head><body><div class='bloom-page'></div></body></html>"); var storage = new BookStorage(original.Path, _fileLocator, new BookRenamedEvent(), new CollectionSettings()); storage.Save(); Directory.Delete(z.Path); //so, we ask for "foo", but should get "foo2", because there is already a foo and foo1 var newBookName = Path.GetFileName(x.Path); storage.SetBookName(newBookName); var newPath = z.Combine("foo2.htm"); Assert.IsTrue(Directory.Exists(z.Path), "Expected folder:" + z.Path); Assert.IsTrue(File.Exists(newPath), "Expected file:" + newPath); } }