Example #1
0
        public void ShouldExportImportedNodes()
        {
            var importDatabase = TestHelper.CreateDatabase();
            var importedEntry  = new PwEntry(true, true);

            importedEntry.SetTitle("ImportedEntry");
            var importedGroup = new PwGroup(true, true);

            importedGroup.Name = "ImportedGroup";
            importedGroup.AddEntry(importedEntry, true);
            importDatabase.RootGroup.AddGroup(importedGroup, true);

            var exportPath = GetTestPath();

            m_syncManager.AddExportPath(exportPath);
            var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");

            m_database.GetExportGroup().Groups.GetAt(0).AddEntry(userMrX.CreateProxyNode(), true);

            m_database.RootGroup.AddEntry(userMrX.CreateProxyNode(), true);
            var existingEntry = new PwEntry(true, true);

            existingEntry.SetTitle("ExistingEntry");
            m_database.RootGroup.AddEntry(existingEntry, true);
            m_treeManager.CorrectStructure();

            string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension;

            Assert.IsFalse(File.Exists(exportFile));

            Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
            Assert.AreEqual(0, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));

            m_syncManager.Export();

            Assert.IsTrue(File.Exists(exportFile));

            var importer = new SyncImporterAccessor();

            importer.MergeInAccessor(m_database, importDatabase);

            Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
            Assert.AreEqual(1, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));

            m_syncManager.Export();

            Assert.IsTrue(File.Exists(exportFile));

            var deltaDBUpdated = new PwDatabase();

            deltaDBUpdated.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
            Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));
            deltaDBUpdated.Close();
        }
        public void ShouldExportImportedNodes()
        {
            var importDatabase = TestHelper.CreateDatabase();
            var importedEntry = new PwEntry(true, true);
            importedEntry.SetTitle("ImportedEntry");
            var importedGroup = new PwGroup(true, true);
            importedGroup.Name = "ImportedGroup";
            importedGroup.AddEntry(importedEntry, true);
            importDatabase.RootGroup.AddGroup(importedGroup, true);

            var exportPath = GetTestPath();

            m_syncManager.AddExportPath(exportPath);
            var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");

            m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrX), true);

            m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true);
            var existingEntry = new PwEntry(true, true);
            existingEntry.SetTitle("ExistingEntry");
            m_database.RootGroup.AddEntry(existingEntry, true);
            m_treeManager.CorrectStructure();

            string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension;
            Assert.IsFalse(File.Exists(exportFile));

            Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
            Assert.AreEqual(0, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));

            m_syncManager.Export();

            Assert.IsTrue(File.Exists(exportFile));

            var importer = new SyncImporterAccessor();
            importer.MergeInAccessor(m_database, importDatabase);

            Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
            Assert.AreEqual(1, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));

            m_syncManager.Export();

            Assert.IsTrue(File.Exists(exportFile));

            var deltaDBUpdated = new PwDatabase();
            deltaDBUpdated.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
            Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));
            deltaDBUpdated.Close();
        }