Пример #1
0
        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();
        }
Пример #2
0
        public void MoveRootUserToAnotherFolderShouldCreateAProxyInTheTarget()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("Hans");
            m_treeManager.CreateNewUser("klaus");
            m_treeManager.CreateNewUser("mrX");

            PwEntry hans  = TestHelper.GetUserRootNodeByNameFor(m_database, "Hans");
            PwEntry klaus = TestHelper.GetUserRootNodeByNameFor(m_database, "klaus");
            PwEntry mrx   = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");

            Assert.IsNotNull(hans);
            Assert.IsNotNull(klaus);
            Assert.IsNotNull(mrx);

            // Simulate move by the user ->  RootNode changes location to destination folder
            Assert.IsTrue(mrx.ParentGroup.Entries.Remove(mrx));
            m_database.RootGroup.AddEntry(mrx, true);

            // Correction should move the RootNode back and create a ProxyNode instead
            m_treeManager.CorrectStructure();

            Assert.AreEqual(7, NumberOfEntriesIn(m_database)); // a root and a proxy node for each user + a new proxy
            IsUsersGroupSane(m_database, 3);
        }