public void ShouldExportAfterChangedContent() { PwEntry mrX = TestHelper.GetUserRootNodeFor(m_database, 0); //the first autoExport only checks if there is a delta container allready and if not it will export one //in our case there should be no existing container so a new one will be created. string exportPath = GetTestPath(); PwGroup exportGroup = new PwGroup(true, true, exportPath, PwIcon.Apple); m_database.GetExportGroup().AddGroup(exportGroup, true); exportGroup.AddEntry(mrX.CreateProxyNode(), true); string exportFile = exportPath + SyncSource.FileNameFor(mrX) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); m_syncManager.RefeshSourcesList(); m_syncManager.Export(); mrX = TestHelper.GetUserRootNodeFor(m_database, 0); Assert.AreEqual("mrX", mrX.GetTitle()); Assert.IsTrue(File.Exists(exportFile)); //now we will change a password that is shared to mrX and then trigger the AutoExport method //like it will happen on any OnChangeEvent. After that again we validate the data in the export container. PwEntry entry1 = m_database.RootGroup.FindEntry(Uuid1, true); entry1.SetTitle("new title"); //due to the fact that the UnitTest is way faster than userIneraction we have to manipulate the lastModTimestamp //because if we don't do that the um.Update() method will maybe use another value to update all references and //then we will have the old title in the stringField TestHelper.SimulateTouch(entry1); //now we run the update methods that will be triggered on every UiChangeEvent m_treeManager.CorrectStructure(); m_syncManager.RefeshSourcesList(); //the autoexport method was triggered by in import or OnSaveEvent only so we have to trigger it manually here m_syncManager.Export(); PwDatabase deltaDB = new PwDatabase(); Assert.DoesNotThrow(delegate { deltaDB.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); }); //as before we want to have the same content except that entry1 should now have a new title! Assert.AreEqual(5, deltaDB.RootGroup.GetEntries(true).UCount); Assert.AreEqual(3, deltaDB.RootGroup.Entries.UCount); Assert.AreEqual("grp1", deltaDB.RootGroup.Groups.GetAt(0).Name); Assert.AreEqual(2, deltaDB.RootGroup.Groups.GetAt(0).Entries.UCount); //now we will test in detail if there are only the expected entries in the created delta container Assert.AreEqual(Uuid1, deltaDB.RootGroup.Entries.GetAt(0).Uuid); Assert.AreEqual(Uuid3, deltaDB.RootGroup.Entries.GetAt(2).Uuid); Assert.AreEqual(Uuid6, deltaDB.RootGroup.Entries.GetAt(1).Uuid); Assert.AreEqual(Uuid4, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(0).Uuid); Assert.AreEqual(Uuid5, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(1).Uuid); Assert.AreEqual("new title", deltaDB.RootGroup.Entries.GetAt(0).GetTitle()); deltaDB.Close(); }
/// <summary> /// The function checks if thelast made change has to be propageted to /// some referenced PwEntries /// </summary> /// <returns>True if the function has made changes to the database.</returns> private Changes CheckReferences() { PwEntry lastModifiedEntry = GetLastModifiedEntry(); //if there are no changes, then we have nothing to do if (lastModifiedEntry == null) { return(Changes.None); } //was it a proxy or not? Changes changeFlag = Changes.None; if (lastModifiedEntry.IsProxyNode()) { //lets update the root so we later can update all proxies PwEntry root = m_database.GetProxyTargetFor(lastModifiedEntry); //check if there are real changes! if not we are done here if (lastModifiedEntry.IsSimilarTo(root, true)) { return(Changes.None); } PwGroup parent = root.ParentGroup; root.CreateBackup(m_database); //rootNode_X should save all modifications in history parent.Entries.Remove(root); PwEntry updatedRoot = lastModifiedEntry.CloneDeep(); updatedRoot.Uuid = root.Uuid; updatedRoot.SetParent(parent); //special handling for userRootNodes because they have a homefolder if (root.IsUserRootNode()) { //maybe the oldUserName has changed to => the homefolder should have the new name also //we also want to have the same icons everywhere parent.Name = updatedRoot.GetTitle(); parent.IconId = updatedRoot.IconId; } else { updatedRoot.Strings.Remove(KeeShare.UuidLinkField); } changeFlag |= UpdateProxyInformation(updatedRoot); changeFlag |= Changes.GroupDeleted; } else { changeFlag |= UpdateProxyInformation(lastModifiedEntry); } pe_lastModedEntry = GetLastModifiedEntry(); return(changeFlag); }