public void HandleNewBook_RenamedBook_AddsRenameMessage() { using (var collectionFolder = new TemporaryFolder("HandleNewBook_RenamedBook_AddsRenameMessage_Collection")) { using (var repoFolder = new TemporaryFolder("HandleNewBook_RenamedBook_AddsRenameMessage_Shared")) { var bookFolderName1 = "Renamed book"; var localBookFolderPath = SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, bookFolderName1, "Something"); var mockTcManager = new Mock <ITeamCollectionManager>(); var tcLog = new TeamCollectionMessageLog(TeamCollectionManager.GetTcLogPathFromLcPath(collectionFolder.FolderPath)); var tc = new TestFolderTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, repoFolder.FolderPath, tcLog); tc.PutBook(localBookFolderPath); SIL.IO.RobustIO.MoveDirectory(localBookFolderPath, Path.Combine(collectionFolder.FolderPath, "old name")); // We could rename the book file too, but it doesn't matter for the current SUT tc.HandleNewBook(new NewBookEventArgs() { BookFileName = "Renamed book.bloom" }); var msg = tcLog.Messages[0]; Assert.That(msg.RawEnglishMessageTemplate, Is.EqualTo("The book \"{0}\" has been renamed to \"{1}\" by a teammate.")); Assert.That(msg.Param0, Is.EqualTo("old name")); Assert.That(msg.Param1, Is.EqualTo("Renamed book")); } } }
public void Checkin_RenamedBook_DeletesOriginal_NoTombstone() { using (var collectionFolder = new TemporaryFolder("Checkin_RenamedBook_DeletesOriginal_Collection")) { using (var repoFolder = new TemporaryFolder("Checkin_RenamedBook_DeletesOriginal_Shared")) { var mockTcManager = new Mock <ITeamCollectionManager>(); TeamCollectionManager.ForceCurrentUserForTests("*****@*****.**"); var tc = new FolderTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, repoFolder.FolderPath); tc.CollectionId = Bloom.TeamCollection.TeamCollection.GenerateCollectionId(); var oldFolderPath = SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, "old name", "book content"); tc.PutBook(oldFolderPath); tc.AttemptLock("old name"); SyncAtStartupTests.SimulateRename(tc, "old name", "middle name"); SyncAtStartupTests.SimulateRename(tc, "middle name", "new name"); tc.PutBook(Path.Combine(collectionFolder.FolderPath, "new name"), true); Assert.That(File.Exists(tc.GetPathToBookFileInRepo("new name")), Is.True); Assert.That(File.Exists(tc.GetPathToBookFileInRepo("old name")), Is.False, "old name was not deleted"); var status = tc.GetLocalStatus("new name"); Assert.That(status.oldName ?? "", Is.Empty, "Should stop tracking previous name once we cleaned it up"); Assert.That(tc.KnownToHaveBeenDeleted("old name"), Is.False); TeamCollectionManager.ForceCurrentUserForTests(null); } } }
public void HandleNewBook_AddsMessage_IffReallyNew(bool reallyNew) { using (var collectionFolder = new TemporaryFolder("HandleNewBook_NewBook_AddsMessage_Collection")) { using (var repoFolder = new TemporaryFolder("HandleNewBook_NewBook_AddsMessage_Shared")) { var bookFolderName1 = "New book"; var localBookFolderPath = SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, bookFolderName1, "Something"); var mockTcManager = new Mock <ITeamCollectionManager>(); var tcLog = new TeamCollectionMessageLog(TeamCollectionManager.GetTcLogPathFromLcPath(collectionFolder.FolderPath)); var tc = new TestFolderTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, repoFolder.FolderPath, tcLog); tc.PutBook(localBookFolderPath); if (reallyNew) { SIL.IO.RobustIO.DeleteDirectory(localBookFolderPath, true); } tc.HandleNewBook(new NewBookEventArgs() { BookFileName = "New book.bloom" }); if (reallyNew) { var msg = tcLog.Messages[0]; Assert.That(msg.RawEnglishMessageTemplate, Is.EqualTo("A new book called '{0}' was added by a teammate.")); } else { Assert.That(tcLog.Messages.Count, Is.EqualTo(0)); } } } }
public void AnyBooksCheckedOutHereByCurrentUser_TrueOnlyForRealCheckouts() { using (var collectionFolder = new TemporaryFolder("AnyBooksCheckedOutHereByCurrentUser_TrueOnlyForRealCheckouts")) { using (var repoFolder = new TemporaryFolder("AnyBooksCheckedOutHereByCurrentUser_TrueOnlyForRealCheckouts")) { TeamCollectionManager.ForceCurrentUserForTests("*****@*****.**"); var bookFolderName1 = "A very nice book book"; var localBookFolderPath = SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, bookFolderName1, "Something"); var mockTcManager = new Mock <ITeamCollectionManager>(); var tcLog = new TeamCollectionMessageLog(TeamCollectionManager.GetTcLogPathFromLcPath(collectionFolder.FolderPath)); var tc = new TestFolderTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, repoFolder.FolderPath, tcLog); SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, "Another nice book", "Something"); Assert.That(tc.AnyBooksCheckedOutHereByCurrentUser, Is.False); // both currently local-only tc.PutBook(localBookFolderPath); Assert.That(tc.AnyBooksCheckedOutHereByCurrentUser, Is.False); // one local-only, one checked in tc.AttemptLock(bookFolderName1, TeamCollectionManager.CurrentUser); Assert.That(tc.AnyBooksCheckedOutHereByCurrentUser, Is.True); // one local-only, one checked out tc.PutBook(localBookFolderPath, checkin: true); tc.AttemptLock(bookFolderName1, "someoneElse.somewhere.org"); Assert.That(tc.AnyBooksCheckedOutHereByCurrentUser, Is.False); // one local-only, one checked out but to someone else. } } }
public void ConnectToTeamCollection_SetsUpRequiredFiles() { using (var collectionFolder = new TemporaryFolder("FolderTeamCollectionTests2_Collection")) { using (var sharedFolder = new TemporaryFolder("FolderTeamCollectionTests2_Shared")) { var bookFolderName1 = "Some book"; SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, bookFolderName1, "Something"); // BL-9573 tests cases where the book name isn't exactly the same as the folder name var bookFolderName2 = "Some other book"; SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, "Some other name altogether", "Strange book content", bookFolderName2); var settingsFileName = Path.ChangeExtension(Path.GetFileName(collectionFolder.FolderPath), "bloomCollection"); var settingsPath = Path.Combine(collectionFolder.FolderPath, settingsFileName); // As an aside, this is a convenient place to check that a TC manager created when TC settings does not exist // functions and does not have a current collection. var tcManager = new TeamCollectionManager(settingsPath, null, new BookRenamedEvent(), new BookStatusChangeEvent(), null, null); Assert.That(tcManager.CurrentCollection, Is.Null); RobustFile.WriteAllText(settingsPath, "This is a fake settings file"); FolderTeamCollection.CreateTeamCollectionLinkFile(collectionFolder.FolderPath, sharedFolder.FolderPath); var nonBookFolder = Path.Combine(collectionFolder.FolderPath, "Some other folder"); Directory.CreateDirectory(nonBookFolder); tcManager = new TeamCollectionManager(settingsPath, null, new BookRenamedEvent(), new BookStatusChangeEvent(), null, null); var collection = tcManager.CurrentCollection; // sut (collection as FolderTeamCollection)?.SetupTeamCollection(sharedFolder.FolderPath, new NullWebSocketProgress()); Assert.That(collection, Is.Not.Null); var joinCollectionPath = Path.Combine(sharedFolder.FolderPath, "Join this Team Collection.JoinBloomTC"); Assert.That(File.Exists(joinCollectionPath)); var teamCollectionLinkPath = Path.Combine(collectionFolder.FolderPath, TeamCollectionManager.TeamCollectionLinkFileName); Assert.That(File.Exists(teamCollectionLinkPath)); var collectionFileContent = RobustFile.ReadAllText(teamCollectionLinkPath); Assert.That(collectionFileContent, Is.EqualTo(sharedFolder.FolderPath)); var sharedSettingsPath = Path.Combine(collectionFolder.FolderPath, settingsFileName); Assert.That(RobustFile.ReadAllText(sharedSettingsPath), Is.EqualTo("This is a fake settings file")); var bookPath = Path.Combine(sharedFolder.FolderPath, "Books", bookFolderName1 + ".bloom"); Assert.That(File.Exists(bookPath)); var bookPath2 = Path.Combine(sharedFolder.FolderPath, "Books", bookFolderName2 + ".bloom"); Assert.That(File.Exists(bookPath2)); } } }
public void OkToCheckIn_GivesCorrectResults() { using (var collectionFolder = new TemporaryFolder("OkToCheckIn_GivesCorrectResults_Collection")) { using (var repoFolder = new TemporaryFolder("OkToCheckIn_GivesCorrectResults_Shared")) { var mockTcManager = new Mock <ITeamCollectionManager>(); TeamCollectionManager.ForceCurrentUserForTests(""); var tc = new FolderTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, repoFolder.FolderPath); tc.CollectionId = Bloom.TeamCollection.TeamCollection.GenerateCollectionId(); var bookFolderPath = SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, "some name", "book content"); Assert.That(tc.OkToCheckIn("some name"), Is.False, "can't check in new book when not registered"); TeamCollectionManager.ForceCurrentUserForTests("*****@*****.**"); Assert.That(tc.OkToCheckIn("some name"), Is.True, "can check in new book"); tc.PutBook(bookFolderPath, true); tc.AttemptLock("some name"); Assert.That(tc.OkToCheckIn("some name"), Is.True, "can check in unmodified book with normal checkout status"); TeamCollectionManager.ForceCurrentUserForTests(""); Assert.That(tc.OkToCheckIn("some name"), Is.False, "normally permitted checkin is forbidden with no registration"); TeamCollectionManager.ForceCurrentUserForTests("*****@*****.**"); var status = tc.GetStatus("some name"); var altStatus = status.WithChecksum("some random thing"); tc.WriteBookStatus("some name", altStatus); tc.WriteLocalStatus("some name", status); Assert.That(tc.OkToCheckIn("some name"), Is.False, "can't check in, mysteriously modified in repo"); altStatus = status.WithLockedBy(null); tc.WriteBookStatus("some name", altStatus); tc.WriteLocalStatus("some name", status); Assert.That(tc.OkToCheckIn("some name"), Is.True, "special case, repo has lost checkout status, but not locked or modified"); altStatus = status.WithLockedBy("*****@*****.**"); tc.WriteBookStatus("some name", altStatus); tc.WriteLocalStatus("some name", status); Assert.That(tc.OkToCheckIn("some name"), Is.False, "conflicting lock in repo"); TeamCollectionManager.ForceCurrentUserForTests("null"); } } }
public void GetStatus_NoLocalStatus_ReturnsNewBookStatus() { using (var collectionFolder = new TemporaryFolder("GetStatus_NoLocalStatus_ReturnsNewBookStatus")) { var mockTcManager = new Mock <ITeamCollectionManager>(); SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, "Local book", "This is only local"); var tc = new DisconnectedTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, "my collection"); var status = tc.GetStatus("Local book"); Assert.That(status.lockedBy, Is.EqualTo(Bloom.TeamCollection.TeamCollection.FakeUserIndicatingNewBook)); Assert.That(status.lockedWhere, Is.EqualTo(TeamCollectionManager.CurrentMachine)); Assert.That(tc.CannotDeleteBecauseDisconnected("Local book"), Is.False); } }
public void GetStatus_LocalStatus_ReturnsLocalStatus_WithoutOldName() { using (var collectionFolder = new TemporaryFolder("GetStatus_LocalStatus_ReturnsLocalStatus")) { var mockTcManager = new Mock <ITeamCollectionManager>(); SyncAtStartupTests.MakeFakeBook(collectionFolder.FolderPath, "Repo book", "This is simulating a book that's in repo"); var tc = new DisconnectedTeamCollection(mockTcManager.Object, collectionFolder.FolderPath, "my collection"); tc.WriteLocalStatus("Repo book", new BookStatus().WithChecksum("a checksum").WithLockedBy("*****@*****.**").WithOldName("Renamed from")); var status = tc.GetStatus("Repo book"); Assert.That(status.lockedBy, Is.EqualTo("*****@*****.**")); Assert.That(status.lockedWhere, Is.EqualTo(TeamCollectionManager.CurrentMachine)); Assert.That(status.checksum, Is.EqualTo("a checksum")); Assert.That(status.oldName, Is.Null); Assert.That(tc.CannotDeleteBecauseDisconnected("Repo book"), Is.True); } }